-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby): allow deduplicating head elements on
id
(#36138)
* feat: deduplicate head elements on id attrbibute in browser * feat: deduplicate head elements on id attrbibute in html gen * page with head deduplication * add test * update comments to match current code * Update e2e-tests/development-runtime/cypress/integration/head-function-export/deduplication.js Co-authored-by: Jude Agboola <[email protected]> * Update e2e-tests/development-runtime/cypress/integration/head-function-export/deduplication.js * add test case to e2e-production * add test case to head integration tests Co-authored-by: Jude Agboola <[email protected]>
- Loading branch information
1 parent
997db76
commit b08ef18
Showing
12 changed files
with
193 additions
and
3 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
e2e-tests/development-runtime/cypress/integration/head-function-export/deduplication.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import headFunctionExportSharedData from "../../../shared-data/head-function-export.js" | ||
|
||
it(`Deduplicates multiple tags with same id`, () => { | ||
cy.visit(headFunctionExportSharedData.page.deduplication).waitForRouteChange() | ||
|
||
// deduplication link has id and should be deduplicated | ||
cy.get(`link[rel=deduplication]`).should("have.length", 1) | ||
// last deduplication link should win | ||
cy.get(`link[rel=deduplication]`).should("have.attr", "href", "/bar") | ||
// we should preserve id | ||
cy.get(`link[rel=deduplication]`).should( | ||
"have.attr", | ||
"id", | ||
"deduplication-test" | ||
) | ||
|
||
// alternate links are not using id, so should have multiple instances | ||
cy.get(`link[rel=alternate]`).should("have.length", 2) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
e2e-tests/development-runtime/src/pages/head-function-export/deduplication.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as React from "react" | ||
|
||
export default function HeadFunctionDeduplication() { | ||
return ( | ||
<> | ||
<h1> | ||
I deduplicated Head elements by their <code>id</code> | ||
</h1> | ||
</> | ||
) | ||
} | ||
|
||
function SEO({ children }) { | ||
return ( | ||
<> | ||
<link rel="deduplication" id="deduplication-test" href="/foo" /> | ||
<link | ||
rel="alternate" | ||
type="application/atom+xml" | ||
title="RSS Feed" | ||
href="/blog/news/atom" | ||
/> | ||
{children} | ||
</> | ||
) | ||
} | ||
|
||
export function Head() { | ||
return ( | ||
<SEO> | ||
<link rel="deduplication" id="deduplication-test" href="/bar" /> | ||
<link rel="alternate" hrefLang="de-DE" href="/de/" /> | ||
</SEO> | ||
) | ||
} |
19 changes: 19 additions & 0 deletions
19
e2e-tests/production-runtime/cypress/integration/head-function-export/deduplication.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import headFunctionExportSharedData from "../../../shared-data/head-function-export.js" | ||
|
||
it(`Deduplicates multiple tags with same id`, () => { | ||
cy.visit(headFunctionExportSharedData.page.deduplication).waitForRouteChange() | ||
|
||
// deduplication link has id and should be deduplicated | ||
cy.get(`link[rel=deduplication]`).should("have.length", 1) | ||
// last deduplication link should win | ||
cy.get(`link[rel=deduplication]`).should("have.attr", "href", "/bar") | ||
// we should preserve id | ||
cy.get(`link[rel=deduplication]`).should( | ||
"have.attr", | ||
"id", | ||
"deduplication-test" | ||
) | ||
|
||
// alternate links are not using id, so should have multiple instances | ||
cy.get(`link[rel=alternate]`).should("have.length", 2) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
e2e-tests/production-runtime/src/pages/head-function-export/deduplication.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as React from "react" | ||
|
||
export default function HeadFunctionDeduplication() { | ||
return ( | ||
<> | ||
<h1> | ||
I deduplicated Head elements by their <code>id</code> | ||
</h1> | ||
</> | ||
) | ||
} | ||
|
||
function SEO({ children }) { | ||
return ( | ||
<> | ||
<link rel="deduplication" id="deduplication-test" href="/foo" /> | ||
<link | ||
rel="alternate" | ||
type="application/atom+xml" | ||
title="RSS Feed" | ||
href="/blog/news/atom" | ||
/> | ||
{children} | ||
</> | ||
) | ||
} | ||
|
||
export function Head() { | ||
return ( | ||
<SEO> | ||
<link rel="deduplication" id="deduplication-test" href="/bar" /> | ||
<link rel="alternate" hrefLang="de-DE" href="/de/" /> | ||
</SEO> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
integration-tests/head-function-export/src/pages/head-function-export/deduplication.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as React from "react" | ||
|
||
export default function HeadFunctionDeduplication() { | ||
return ( | ||
<> | ||
<h1> | ||
I deduplicated Head elements by their <code>id</code> | ||
</h1> | ||
</> | ||
) | ||
} | ||
|
||
function SEO({ children }) { | ||
return ( | ||
<> | ||
<link rel="deduplication" id="deduplication-test" href="/foo" /> | ||
<link | ||
rel="alternate" | ||
type="application/atom+xml" | ||
title="RSS Feed" | ||
href="/blog/news/atom" | ||
/> | ||
{children} | ||
</> | ||
) | ||
} | ||
|
||
export function Head() { | ||
return ( | ||
<SEO> | ||
<link rel="deduplication" id="deduplication-test" href="/bar" /> | ||
<link rel="alternate" hrefLang="de-DE" href="/de/" /> | ||
</SEO> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters