-
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
<html>
and <body>
attributes to be updated fr…
…om `Head` (#37449) * allow usage of html and body tags in head * add integration test for html and body attrs * get rid of debug logs * setBody/HtmlAttributes doesn't have second arg * drop another console.log * add test to e2e/dev * add test to e2e/prod * sigh ... silence invalid nesting of html and body elements * add comment about order of onRenderBody vs Head * consistent return * dev ssr tests * offline ... * offline ... vol2 * fix tracking body attributes * fix deduplication Co-authored-by: pieh <misiek.piechowiak@gmail.com>
- Loading branch information
1 parent
e4f841f
commit fe65c29
Showing
17 changed files
with
431 additions
and
75 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
.../development-runtime/cypress/integration/head-function-export/html-and-body-attributes.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,50 @@ | ||
import headFunctionExportSharedData from "../../../shared-data/head-function-export.js" | ||
|
||
describe(`Html and body attributes`, () => { | ||
it(`Page has body and html attributes on direct visit`, () => { | ||
cy.visit( | ||
headFunctionExportSharedData.page.htmlAndBodyAttributes | ||
).waitForRouteChange() | ||
|
||
cy.get(`body`).should(`have.attr`, `data-foo`, `baz`) | ||
cy.get(`body`).should(`have.attr`, `class`, `foo`) | ||
cy.get(`html`).should(`have.attr`, `data-foo`, `bar`) | ||
cy.get(`html`).should(`have.attr`, `lang`, `fr`) | ||
}) | ||
|
||
it(`Page has body and html attributes on client-side navigation`, () => { | ||
cy.visit(headFunctionExportSharedData.page.basic).waitForRouteChange() | ||
|
||
cy.get(`body`).should(`not.have.attr`, `data-foo`, `baz`) | ||
cy.get(`body`).should(`not.have.attr`, `class`, `foo`) | ||
cy.get(`html`).should(`not.have.attr`, `data-foo`, `bar`) | ||
cy.get(`html`).should(`not.have.attr`, `lang`, `fr`) | ||
|
||
cy.visit( | ||
headFunctionExportSharedData.page.htmlAndBodyAttributes | ||
).waitForRouteChange() | ||
|
||
cy.get(`body`).should(`have.attr`, `data-foo`, `baz`) | ||
cy.get(`body`).should(`have.attr`, `class`, `foo`) | ||
cy.get(`html`).should(`have.attr`, `data-foo`, `bar`) | ||
cy.get(`html`).should(`have.attr`, `lang`, `fr`) | ||
}) | ||
|
||
it(`Body and html attributes are removed on client-side navigation when new page doesn't set them`, () => { | ||
cy.visit( | ||
headFunctionExportSharedData.page.htmlAndBodyAttributes | ||
).waitForRouteChange() | ||
|
||
cy.get(`body`).should(`have.attr`, `data-foo`, `baz`) | ||
cy.get(`body`).should(`have.attr`, `class`, `foo`) | ||
cy.get(`html`).should(`have.attr`, `data-foo`, `bar`) | ||
cy.get(`html`).should(`have.attr`, `lang`, `fr`) | ||
|
||
cy.visit(headFunctionExportSharedData.page.basic).waitForRouteChange() | ||
|
||
cy.get(`body`).should(`not.have.attr`, `data-foo`, `baz`) | ||
cy.get(`body`).should(`not.have.attr`, `class`, `foo`) | ||
cy.get(`html`).should(`not.have.attr`, `data-foo`, `bar`) | ||
cy.get(`html`).should(`not.have.attr`, `lang`, `fr`) | ||
}) | ||
}) |
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
28 changes: 28 additions & 0 deletions
28
e2e-tests/development-runtime/src/pages/head-function-export/html-and-body-attributes.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,28 @@ | ||
import * as React from "react" | ||
|
||
export default function HeadFunctionHtmlAndBodyAttributes() { | ||
return ( | ||
<> | ||
<h1>I have html and body attributes</h1> | ||
</> | ||
) | ||
} | ||
|
||
function Indirection({ children }) { | ||
return ( | ||
<> | ||
<html lang="fr" /> | ||
<body className="foo" /> | ||
{children} | ||
</> | ||
) | ||
} | ||
|
||
export function Head() { | ||
return ( | ||
<Indirection> | ||
<html data-foo="bar" /> | ||
<body data-foo="baz" /> | ||
</Indirection> | ||
) | ||
} |
61 changes: 61 additions & 0 deletions
61
...s/production-runtime/cypress/integration/head-function-export/html-and-body-attributes.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,61 @@ | ||
import headFunctionExportSharedData from "../../../shared-data/head-function-export.js" | ||
|
||
Cypress.on("uncaught:exception", err => { | ||
if ( | ||
(err.message.includes("Minified React error #418") || | ||
err.message.includes("Minified React error #423") || | ||
err.message.includes("Minified React error #425")) && | ||
Cypress.env(`TEST_PLUGIN_OFFLINE`) | ||
) { | ||
return false | ||
} | ||
}) | ||
|
||
describe(`Html and body attributes`, () => { | ||
it(`Page has body and html attributes on direct visit`, () => { | ||
cy.visit( | ||
headFunctionExportSharedData.page.htmlAndBodyAttributes | ||
).waitForRouteChange() | ||
|
||
cy.get(`body`).should(`have.attr`, `data-foo`, `baz`) | ||
cy.get(`body`).should(`have.attr`, `class`, `foo`) | ||
cy.get(`html`).should(`have.attr`, `data-foo`, `bar`) | ||
cy.get(`html`).should(`have.attr`, `lang`, `fr`) | ||
}) | ||
|
||
it(`Page has body and html attributes on client-side navigation`, () => { | ||
cy.visit(headFunctionExportSharedData.page.basic).waitForRouteChange() | ||
|
||
cy.get(`body`).should(`not.have.attr`, `data-foo`, `baz`) | ||
cy.get(`body`).should(`not.have.attr`, `class`, `foo`) | ||
cy.get(`html`).should(`not.have.attr`, `data-foo`, `bar`) | ||
cy.get(`html`).should(`not.have.attr`, `lang`, `fr`) | ||
|
||
cy.visit( | ||
headFunctionExportSharedData.page.htmlAndBodyAttributes | ||
).waitForRouteChange() | ||
|
||
cy.get(`body`).should(`have.attr`, `data-foo`, `baz`) | ||
cy.get(`body`).should(`have.attr`, `class`, `foo`) | ||
cy.get(`html`).should(`have.attr`, `data-foo`, `bar`) | ||
cy.get(`html`).should(`have.attr`, `lang`, `fr`) | ||
}) | ||
|
||
it(`Body and html attributes are removed on client-side navigation when new page doesn't set them`, () => { | ||
cy.visit( | ||
headFunctionExportSharedData.page.htmlAndBodyAttributes | ||
).waitForRouteChange() | ||
|
||
cy.get(`body`).should(`have.attr`, `data-foo`, `baz`) | ||
cy.get(`body`).should(`have.attr`, `class`, `foo`) | ||
cy.get(`html`).should(`have.attr`, `data-foo`, `bar`) | ||
cy.get(`html`).should(`have.attr`, `lang`, `fr`) | ||
|
||
cy.visit(headFunctionExportSharedData.page.basic).waitForRouteChange() | ||
|
||
cy.get(`body`).should(`not.have.attr`, `data-foo`, `baz`) | ||
cy.get(`body`).should(`not.have.attr`, `class`, `foo`) | ||
cy.get(`html`).should(`not.have.attr`, `data-foo`, `bar`) | ||
cy.get(`html`).should(`not.have.attr`, `lang`, `fr`) | ||
}) | ||
}) |
11 changes: 11 additions & 0 deletions
11
e2e-tests/production-runtime/cypress/integration/head-function-export/html-insertion.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
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
28 changes: 28 additions & 0 deletions
28
e2e-tests/production-runtime/src/pages/head-function-export/html-and-body-attributes.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,28 @@ | ||
import * as React from "react" | ||
|
||
export default function HeadFunctionHtmlAndBodyAttributes() { | ||
return ( | ||
<> | ||
<h1>I have html and body attributes</h1> | ||
</> | ||
) | ||
} | ||
|
||
function Indirection({ children }) { | ||
return ( | ||
<> | ||
<html lang="fr" /> | ||
<body className="foo" /> | ||
{children} | ||
</> | ||
) | ||
} | ||
|
||
export function Head() { | ||
return ( | ||
<Indirection> | ||
<html data-foo="bar" /> | ||
<body data-foo="baz" /> | ||
</Indirection> | ||
) | ||
} |
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
28 changes: 28 additions & 0 deletions
28
...ion-tests/head-function-export/src/pages/head-function-export/html-and-body-attributes.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,28 @@ | ||
import * as React from "react" | ||
|
||
export default function HeadFunctionHtmlAndBodyAttributes() { | ||
return ( | ||
<> | ||
<h1>I have html and body attributes</h1> | ||
</> | ||
) | ||
} | ||
|
||
function Indirection({ children }) { | ||
return ( | ||
<> | ||
<html lang="fr" /> | ||
<body className="foo" /> | ||
{children} | ||
</> | ||
) | ||
} | ||
|
||
export function Head() { | ||
return ( | ||
<Indirection> | ||
<html data-foo="bar" /> | ||
<body data-foo="baz" /> | ||
</Indirection> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,6 @@ export const VALID_NODE_NAMES = [ | |
`base`, | ||
`noscript`, | ||
`script`, | ||
`html`, | ||
`body`, | ||
] |
Oops, something went wrong.