diff --git a/e2e-tests/development-runtime/cypress/integration/head-function-export/html-insertion.js b/e2e-tests/development-runtime/cypress/integration/head-function-export/html-insertion.js index d1783554c22a2..97bdfc71fd078 100644 --- a/e2e-tests/development-runtime/cypress/integration/head-function-export/html-insertion.js +++ b/e2e-tests/development-runtime/cypress/integration/head-function-export/html-insertion.js @@ -15,6 +15,7 @@ describe(`Head function export html insertion`, () => { cy.getTestElement(`link`) .invoke(`attr`, `href`) .should(`equal`, data.static.link) + cy.getTestElement(`jsonLD`).should(`have.text`, data.static.jsonLD) }) it(`should work with data from a page query`, () => { @@ -47,6 +48,7 @@ describe(`Head function export html insertion`, () => { cy.getTestElement(`link`) .invoke(`attr`, `href`) .should(`equal`, data.static.link) + cy.getTestElement(`jsonLD`).should(`have.text`, data.static.jsonLD) }) it(`should work when an imported Head component with queried data is used`, () => { diff --git a/e2e-tests/development-runtime/cypress/integration/head-function-export/navigation.js b/e2e-tests/development-runtime/cypress/integration/head-function-export/navigation.js index dc855eb015808..663ca2ca4677c 100644 --- a/e2e-tests/development-runtime/cypress/integration/head-function-export/navigation.js +++ b/e2e-tests/development-runtime/cypress/integration/head-function-export/navigation.js @@ -42,6 +42,7 @@ describe(`Head function export behavior during CSR navigation (Gatsby Link)`, () cy.getTestElement(`link`) .invoke(`attr`, `href`) .should(`equal`, data.static.link) + cy.getTestElement(`jsonLD`).should(`have.text`, data.static.jsonLD) cy.getTestElement(`navigate-to-page-without-head-export`) .click() @@ -53,6 +54,7 @@ describe(`Head function export behavior during CSR navigation (Gatsby Link)`, () cy.getTestElement(`noscript`).should(`not.exist`) cy.getTestElement(`style`).should(`not.exist`) cy.getTestElement(`link`).should(`not.exist`) + cy.getTestElement(`jsonLD`).should(`not.exist`) }) /** diff --git a/e2e-tests/development-runtime/cypress/integration/head-function-export/warnings.js b/e2e-tests/development-runtime/cypress/integration/head-function-export/warnings.js index a06a256dcb07c..f2f3a83ebb52c 100644 --- a/e2e-tests/development-runtime/cypress/integration/head-function-export/warnings.js +++ b/e2e-tests/development-runtime/cypress/integration/head-function-export/warnings.js @@ -18,11 +18,4 @@ describe(`Head function export should warn`, () => { )}` ) }) - - it(`for scripts that could use the script component`, () => { - cy.get(`@consoleWarn`).should( - `be.calledWith`, - `Do not add scripts here. Please use the ) } diff --git a/e2e-tests/development-runtime/src/pages/head-function-export/basic.js b/e2e-tests/development-runtime/src/pages/head-function-export/basic.js index 2f1b7a137b0f6..af5204c87420a 100644 --- a/e2e-tests/development-runtime/src/pages/head-function-export/basic.js +++ b/e2e-tests/development-runtime/src/pages/head-function-export/basic.js @@ -28,6 +28,7 @@ export function Head() { style, link, extraMeta, + jsonLD } = data.static return ( @@ -50,6 +51,9 @@ export function Head() { name="extra-meta-for-hot-reloading" content="%SOME_EXTRA_META%" /> + ) } diff --git a/e2e-tests/development-runtime/src/pages/head-function-export/warnings.js b/e2e-tests/development-runtime/src/pages/head-function-export/warnings.js index be6a624007010..fba419a066190 100644 --- a/e2e-tests/development-runtime/src/pages/head-function-export/warnings.js +++ b/e2e-tests/development-runtime/src/pages/head-function-export/warnings.js @@ -14,7 +14,6 @@ export function Head() { return ( <>

hello

- ) } diff --git a/e2e-tests/production-runtime/cypress/integration/head-function-export/html-insertion.js b/e2e-tests/production-runtime/cypress/integration/head-function-export/html-insertion.js index f518afe0c3572..0c34c9d59502c 100644 --- a/e2e-tests/production-runtime/cypress/integration/head-function-export/html-insertion.js +++ b/e2e-tests/production-runtime/cypress/integration/head-function-export/html-insertion.js @@ -15,6 +15,7 @@ describe(`Head function export html insertion`, () => { cy.getTestElement(`link`) .invoke(`attr`, `href`) .should(`equal`, data.static.link) + cy.getTestElement(`jsonLD`).should(`have.text`, data.static.jsonLD) }) it(`should work with data from a page query`, () => { @@ -47,6 +48,7 @@ describe(`Head function export html insertion`, () => { cy.getTestElement(`link`) .invoke(`attr`, `href`) .should(`equal`, data.static.link) + cy.getTestElement(`jsonLD`).should(`have.text`, data.static.jsonLD) }) it(`should work when an imported Head component with queried data is used`, () => { diff --git a/e2e-tests/production-runtime/cypress/integration/head-function-export/navigation.js b/e2e-tests/production-runtime/cypress/integration/head-function-export/navigation.js index a25e7519a3926..6ce9f7379c34c 100644 --- a/e2e-tests/production-runtime/cypress/integration/head-function-export/navigation.js +++ b/e2e-tests/production-runtime/cypress/integration/head-function-export/navigation.js @@ -42,6 +42,7 @@ describe(`Head function export behavior during CSR navigation (Gatsby Link)`, () cy.getTestElement(`link`) .invoke(`attr`, `href`) .should(`equal`, data.static.link) + cy.getTestElement(`jsonLD`).should(`have.text`, data.static.jsonLD) cy.getTestElement(`navigate-to-page-without-head-export`) .click() @@ -53,6 +54,7 @@ describe(`Head function export behavior during CSR navigation (Gatsby Link)`, () cy.getTestElement(`noscript`).should(`not.exist`) cy.getTestElement(`style`).should(`not.exist`) cy.getTestElement(`link`).should(`not.exist`) + cy.getTestElement(`jsonLD`).should(`not.exist`) }) /** diff --git a/e2e-tests/production-runtime/shared-data/head-function-export.js b/e2e-tests/production-runtime/shared-data/head-function-export.js index c20460ae662ff..523fbc1b62ed7 100644 --- a/e2e-tests/production-runtime/shared-data/head-function-export.js +++ b/e2e-tests/production-runtime/shared-data/head-function-export.js @@ -22,6 +22,7 @@ const data = { style: `rebeccapurple`, link: `/used-by-head-function-export-basic.css`, extraMeta: `Extra meta tag that should be removed during navigation`, + jsonLD: `{"@context":"https://schema.org","@type":"Organization","url":"https://www.spookytech.com","name":"Spookytechnologies","contactPoint":{"@type":"ContactPoint","telephone":"+5-601-785-8543","contactType":"CustomerSupport"}}` }, queried: { base: `http://localhost:9000`, diff --git a/e2e-tests/production-runtime/src/components/head-function-export.js b/e2e-tests/production-runtime/src/components/head-function-export.js index c261601b6c99f..1f60426fa9c97 100644 --- a/e2e-tests/production-runtime/src/components/head-function-export.js +++ b/e2e-tests/production-runtime/src/components/head-function-export.js @@ -43,7 +43,7 @@ function HeadComponent({ children }) { } function Head() { - const { base, title, meta, noscript, style, link } = data.static + const { base, title, meta, noscript, style, link, jsonLD } = data.static return ( <> @@ -59,6 +59,9 @@ function Head() { `} + ) } diff --git a/e2e-tests/production-runtime/src/pages/head-function-export/basic.js b/e2e-tests/production-runtime/src/pages/head-function-export/basic.js index 6845115bef687..1132b579f8cda 100644 --- a/e2e-tests/production-runtime/src/pages/head-function-export/basic.js +++ b/e2e-tests/production-runtime/src/pages/head-function-export/basic.js @@ -18,7 +18,7 @@ export default function HeadFunctionExportBasic() { } export function Head() { - const { base, title, meta, noscript, style, link, extraMeta } = data.static + const { base, title, meta, noscript, style, link, extraMeta, jsonLD } = data.static return ( <> @@ -34,8 +34,10 @@ export function Head() { `} - + ) } diff --git a/integration-tests/head-function-export/__tests__/ssr-html-output.js b/integration-tests/head-function-export/__tests__/ssr-html-output.js index f60c7cd47a1ad..1354d6a62b2d5 100644 --- a/integration-tests/head-function-export/__tests__/ssr-html-output.js +++ b/integration-tests/head-function-export/__tests__/ssr-html-output.js @@ -18,14 +18,15 @@ function getNodes(dom) { const noscript = dom.querySelector(`[data-testid=noscript]`) const style = dom.querySelector(`[data-testid=style]`) const link = dom.querySelector(`[data-testid=link]`) - return { base, title, meta, noscript, style, link } + const jsonLD = dom.querySelector(`[data-testid=jsonLD]`) + return { base, title, meta, noscript, style, link, jsonLD } } describe(`Head function export SSR'ed HTML output`, () => { it(`should work with static data`, () => { const html = readFileSync(`${publicDir}${page.basic}/index.html`) const dom = parse(html) - const { base, title, meta, noscript, style, link } = getNodes(dom) + const { base, title, meta, noscript, style, link, jsonLD } = getNodes(dom) expect(base.attributes.href).toEqual(data.static.base) expect(title.text).toEqual(data.static.title) @@ -33,6 +34,7 @@ describe(`Head function export SSR'ed HTML output`, () => { expect(noscript.text).toEqual(data.static.noscript) expect(style.text).toContain(data.static.style) expect(link.attributes.href).toEqual(data.static.link) + expect(jsonLD.text).toEqual(data.static.jsonLD) }) it(`should work with data from a page query`, () => { @@ -51,7 +53,7 @@ describe(`Head function export SSR'ed HTML output`, () => { it(`should work when a Head function with static data is re-exported from the page`, () => { const html = readFileSync(`${publicDir}${page.reExport}/index.html`) const dom = parse(html) - const { base, title, meta, noscript, style, link } = getNodes(dom) + const { base, title, meta, noscript, style, link, jsonLD } = getNodes(dom) expect(base.attributes.href).toEqual(data.static.base) expect(title.text).toEqual(data.static.title) @@ -59,6 +61,7 @@ describe(`Head function export SSR'ed HTML output`, () => { expect(noscript.text).toEqual(data.static.noscript) expect(style.text).toContain(data.static.style) expect(link.attributes.href).toEqual(data.static.link) + expect(jsonLD.text).toEqual(data.static.jsonLD) }) it(`should work when an imported Head component with queried data is used`, () => { diff --git a/integration-tests/head-function-export/shared-data/head-function-export.js b/integration-tests/head-function-export/shared-data/head-function-export.js index 056f993b590c3..a6bfc266ead36 100644 --- a/integration-tests/head-function-export/shared-data/head-function-export.js +++ b/integration-tests/head-function-export/shared-data/head-function-export.js @@ -17,6 +17,7 @@ const data = { noscript: `You take romance - I will take Jell-O!`, style: `rebeccapurple`, link: `/used-by-head-function-export-basic.css`, + jsonLD: `{"@context":"https://schema.org","@type":"Organization","url":"https://www.spookytech.com","name":"Spookytechnologies","contactPoint":{"@type":"ContactPoint","telephone":"+5-601-785-8543","contactType":"CustomerSupport"}}` }, queried: { base: `http://localhost:8000`, diff --git a/integration-tests/head-function-export/src/components/head-function-export.js b/integration-tests/head-function-export/src/components/head-function-export.js index c261601b6c99f..1f60426fa9c97 100644 --- a/integration-tests/head-function-export/src/components/head-function-export.js +++ b/integration-tests/head-function-export/src/components/head-function-export.js @@ -43,7 +43,7 @@ function HeadComponent({ children }) { } function Head() { - const { base, title, meta, noscript, style, link } = data.static + const { base, title, meta, noscript, style, link, jsonLD } = data.static return ( <> @@ -59,6 +59,9 @@ function Head() { `} + ) } diff --git a/integration-tests/head-function-export/src/pages/head-function-export/basic.js b/integration-tests/head-function-export/src/pages/head-function-export/basic.js index 10f71983b1ad3..0d8a46d7f72c1 100644 --- a/integration-tests/head-function-export/src/pages/head-function-export/basic.js +++ b/integration-tests/head-function-export/src/pages/head-function-export/basic.js @@ -15,7 +15,7 @@ export default function HeadFunctionExportBasic() { } export function Head() { - const { base, title, meta, noscript, style, link } = data.static + const { base, title, meta, noscript, style, link, jsonLD } = data.static return ( <> @@ -31,6 +31,9 @@ export function Head() { `} + ) } diff --git a/packages/gatsby/cache-dir/head/constants.js b/packages/gatsby/cache-dir/head/constants.js index 05ccf7fdd5c7b..a0d86cfc26d73 100644 --- a/packages/gatsby/cache-dir/head/constants.js +++ b/packages/gatsby/cache-dir/head/constants.js @@ -5,4 +5,5 @@ export const VALID_NODE_NAMES = [ `title`, `base`, `noscript`, + `script`, ] diff --git a/packages/gatsby/cache-dir/head/utils.js b/packages/gatsby/cache-dir/head/utils.js index 4551446c0a793..833226a37f90b 100644 --- a/packages/gatsby/cache-dir/head/utils.js +++ b/packages/gatsby/cache-dir/head/utils.js @@ -39,20 +39,15 @@ if (process.env.NODE_ENV !== `production`) { } } -export { warnOnce } - /** * Warn for invalid tags in head. * @param {string} tagName */ export function warnForInvalidTags(tagName) { if (process.env.NODE_ENV !== `production`) { - const warning = - tagName !== `script` - ? `<${tagName}> is not a valid head element. Please use one of the following: ${VALID_NODE_NAMES.join( - `, ` - )}` - : `Do not add scripts here. Please use the