Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby): allow deduplicating head elements on id #36138

Merged
merged 9 commits into from
Jul 18, 2022
Prev Previous commit
Next Next commit
add test
pieh committed Jul 15, 2022
commit 2963da8c52d34bac6d27d3941641a421a45de364
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import headFunctionExportSharedData from "../../../shared-data/head-function-export.js"

it(`Head function export receive correct props`, () => {
cy.visit(headFunctionExportSharedData.page.deduplication).waitForRouteChange()

// icon has id and should be deduplicated
cy.get(`link[rel=deduplication]`).should("have.length", 1)
// last icon 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)
})
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ const page = {
ssr: `${path}/ssr/`,
invalidElements: `${path}/invalid-elements/`,
fsRouteApi: `${path}/fs-route-api/`,
deduplication: `${path}/deduplication/`,
}

const data = {
Original file line number Diff line number Diff line change
@@ -13,11 +13,7 @@ export default function HeadFunctionExportBasic() {
function SEO({ children }) {
return (
<>
<link
id="icon"
rel="icon"
href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='0.9em' font-size='90'>👤</text></svg>"
/>
<link rel="deduplication" id="deduplication-test" href="/foo" />
<link
rel="alternate"
type="application/atom+xml"
@@ -32,11 +28,7 @@ function SEO({ children }) {
export function Head() {
return (
<SEO>
<link
id="icon"
rel="icon"
href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='0.9em' font-size='90'>🔥</text></svg>"
/>
<link rel="deduplication" id="deduplication-test" href="/bar" />
<link rel="alternate" hrefLang="de-DE" href="/de/" />
</SEO>
)