Skip to content

Commit d83a5a2

Browse files
jonathonluiGatsbyJS Bot
authored and
GatsbyJS Bot
committed
fix(gatsby-plugin-netlify): don't add /undefined in generated _headers file (#18925)
* fix(gatsby-plugin-netlify): /undefined in generated _headers file * Explicitly check that /undefined is not in output of buildHeadersProgram * Fix matcher
1 parent 1272063 commit d83a5a2

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed

packages/gatsby-plugin-netlify/src/__tests__/__snapshots__/build-headers-program.js.snap

+74
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,77 @@ exports[`build-headers-program without caching headers 1`] = `
284284
Link: </component---src-pages-404-js-53e6c51a5a7e73090f50.js>; rel=preload; as=script
285285
"
286286
`;
287+
288+
exports[`build-headers-program without manifest['pages-manifest'] 1`] = `
289+
"## Created with gatsby-plugin-netlify
290+
291+
/*
292+
X-Frame-Options: DENY
293+
X-XSS-Protection: 1; mode=block
294+
X-Content-Type-Options: nosniff
295+
Referrer-Policy: same-origin
296+
/component---node-modules-gatsby-plugin-offline-app-shell-js-78f9e4dea04737fa062d.js
297+
Cache-Control: public, max-age=31536000, immutable
298+
/0-0180cd94ef2497ac7db8.js
299+
Cache-Control: public, max-age=31536000, immutable
300+
/component---src-templates-blog-post-js-517987eae96e75cddbe7.js
301+
Cache-Control: public, max-age=31536000, immutable
302+
/component---src-pages-404-js-53e6c51a5a7e73090f50.js
303+
Cache-Control: public, max-age=31536000, immutable
304+
/component---src-pages-index-js-0bdd01c77ee09ef0224c.js
305+
Cache-Control: public, max-age=31536000, immutable
306+
/webpack-runtime-acaa8994f1f704475e21.js
307+
Cache-Control: public, max-age=31536000, immutable
308+
/styles.1025963f4f2ec7abbad4.css
309+
Cache-Control: public, max-age=31536000, immutable
310+
/styles-565f081c8374bbda155f.js
311+
Cache-Control: public, max-age=31536000, immutable
312+
/app-f33c13590352da20930f.js
313+
Cache-Control: public, max-age=31536000, immutable
314+
/static/*
315+
Cache-Control: public, max-age=31536000, immutable
316+
/sw.js
317+
Cache-Control: no-cache
318+
/offline-plugin-app-shell-fallback/
319+
Link: </webpack-runtime-acaa8994f1f704475e21.js>; rel=preload; as=script
320+
Link: </styles-565f081c8374bbda155f.js>; rel=preload; as=script
321+
Link: </app-f33c13590352da20930f.js>; rel=preload; as=script
322+
Link: </component---node-modules-gatsby-plugin-offline-app-shell-js-78f9e4dea04737fa062d.js>; rel=preload; as=script
323+
/hi-folks/
324+
Link: </webpack-runtime-acaa8994f1f704475e21.js>; rel=preload; as=script
325+
Link: </styles-565f081c8374bbda155f.js>; rel=preload; as=script
326+
Link: </app-f33c13590352da20930f.js>; rel=preload; as=script
327+
Link: </0-0180cd94ef2497ac7db8.js>; rel=preload; as=script
328+
Link: </component---src-templates-blog-post-js-517987eae96e75cddbe7.js>; rel=preload; as=script
329+
/my-second-post/
330+
Link: </webpack-runtime-acaa8994f1f704475e21.js>; rel=preload; as=script
331+
Link: </styles-565f081c8374bbda155f.js>; rel=preload; as=script
332+
Link: </app-f33c13590352da20930f.js>; rel=preload; as=script
333+
Link: </0-0180cd94ef2497ac7db8.js>; rel=preload; as=script
334+
Link: </component---src-templates-blog-post-js-517987eae96e75cddbe7.js>; rel=preload; as=script
335+
/hello-world/
336+
Link: </webpack-runtime-acaa8994f1f704475e21.js>; rel=preload; as=script
337+
Link: </styles-565f081c8374bbda155f.js>; rel=preload; as=script
338+
Link: </app-f33c13590352da20930f.js>; rel=preload; as=script
339+
Link: </0-0180cd94ef2497ac7db8.js>; rel=preload; as=script
340+
Link: </component---src-templates-blog-post-js-517987eae96e75cddbe7.js>; rel=preload; as=script
341+
/404/
342+
Link: </webpack-runtime-acaa8994f1f704475e21.js>; rel=preload; as=script
343+
Link: </styles-565f081c8374bbda155f.js>; rel=preload; as=script
344+
Link: </app-f33c13590352da20930f.js>; rel=preload; as=script
345+
Link: </0-0180cd94ef2497ac7db8.js>; rel=preload; as=script
346+
Link: </component---src-pages-404-js-53e6c51a5a7e73090f50.js>; rel=preload; as=script
347+
/
348+
Link: </webpack-runtime-acaa8994f1f704475e21.js>; rel=preload; as=script
349+
Link: </styles-565f081c8374bbda155f.js>; rel=preload; as=script
350+
Link: </app-f33c13590352da20930f.js>; rel=preload; as=script
351+
Link: </0-0180cd94ef2497ac7db8.js>; rel=preload; as=script
352+
Link: </component---src-pages-index-js-0bdd01c77ee09ef0224c.js>; rel=preload; as=script
353+
/404.html
354+
Link: </webpack-runtime-acaa8994f1f704475e21.js>; rel=preload; as=script
355+
Link: </styles-565f081c8374bbda155f.js>; rel=preload; as=script
356+
Link: </app-f33c13590352da20930f.js>; rel=preload; as=script
357+
Link: </0-0180cd94ef2497ac7db8.js>; rel=preload; as=script
358+
Link: </component---src-pages-404-js-53e6c51a5a7e73090f50.js>; rel=preload; as=script
359+
"
360+
`;

packages/gatsby-plugin-netlify/src/__tests__/build-headers-program.js

+22
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,28 @@ describe(`build-headers-program`, () => {
173173
).toMatchSnapshot()
174174
})
175175

176+
it(`without manifest['pages-manifest']`, async () => {
177+
const pluginData = await createPluginData()
178+
179+
// gatsby 2.9+ no longer has a pages-manifest key
180+
delete pluginData.manifest[`pages-manifest`]
181+
182+
const pluginOptions = {
183+
...DEFAULT_OPTIONS,
184+
mergeCachingHeaders: true,
185+
}
186+
187+
await buildHeadersProgram(pluginData, pluginOptions, reporter)
188+
189+
expect(reporter.warn).not.toHaveBeenCalled()
190+
const output = await fs.readFile(
191+
pluginData.publicFolder(`_headers`),
192+
`utf8`
193+
)
194+
expect(output).toMatchSnapshot()
195+
expect(output).not.toMatch(/\/undefined/g)
196+
})
197+
176198
it(`without caching headers`, async () => {
177199
const pluginData = await createPluginData()
178200

packages/gatsby-plugin-netlify/src/build-headers-program.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ const applyCachingHeaders = (
280280
const cachingHeaders = {}
281281

282282
files.forEach(file => {
283-
cachingHeaders[`/` + file] = [IMMUTABLE_CACHING_HEADER]
283+
if (typeof file === `string`) {
284+
cachingHeaders[`/` + file] = [IMMUTABLE_CACHING_HEADER]
285+
}
284286
})
285287

286288
return defaultMerge(headers, cachingHeaders, CACHING_HEADERS)

0 commit comments

Comments
 (0)