-
Notifications
You must be signed in to change notification settings - Fork 92
fix(perf): exclude /_next/static/*
from generated functions
#3100
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
Merged
+87
−7
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
43776d0
fix(perf): exclude `/_next/static/*` from generated functions
mrstork 1f1eef0
test: improve message in immutable cache test
mrstork 51da495
test: update request path to include base path
mrstork 55f2ac5
test: include base path in more page router tests
mrstork cba698e
Merge branch 'main' into exclude-static-paths
mrstork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { expect } from '@playwright/test' | ||
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs' | ||
import { test } from '../utils/playwright-helpers.js' | ||
import { join } from 'node:path' | ||
import { readdir } from 'node:fs/promises' | ||
|
||
export function waitFor(millis: number) { | ||
return new Promise((resolve) => setTimeout(resolve, millis)) | ||
|
@@ -614,6 +616,34 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => { | |
/(s-maxage|max-age)/, | ||
) | ||
}) | ||
|
||
test.describe('static assets and function invocations', () => { | ||
test('should return 200 for an existing static asset without invoking a function', async ({ | ||
page, | ||
pageRouter, | ||
}) => { | ||
// Since assets are hashed, we can't hardcode anything here. Find something to fetch. | ||
const [staticAsset] = await readdir( | ||
join(pageRouter.isolatedFixtureRoot, '.next', 'static', 'chunks'), | ||
) | ||
expect(staticAsset).toBeDefined() | ||
|
||
const response = await page.goto(`${pageRouter.url}/_next/static/chunks/${staticAsset}`) | ||
|
||
expect(response?.status()).toBe(200) | ||
expect(response?.headers()).not.toHaveProperty('x-nf-function-type') | ||
}) | ||
|
||
test('should return 404 for a nonexistent static asset without invoking a function', async ({ | ||
page, | ||
pageRouter, | ||
}) => { | ||
const response = await page.goto(`${pageRouter.url}/_next/static/stale123abcdef.js`) | ||
|
||
expect(response?.status()).toBe(404) | ||
expect(response?.headers()).not.toHaveProperty('x-nf-function-type') | ||
}) | ||
}) | ||
}) | ||
|
||
test.describe('Page Router with basePath and i18n', () => { | ||
|
@@ -1352,13 +1382,15 @@ test.describe('Page Router with basePath and i18n', () => { | |
|
||
test('requesting a non existing page route that needs to be fetched from the blob store like 404.html', async ({ | ||
page, | ||
pageRouter, | ||
pageRouterBasePathI18n, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch! |
||
}) => { | ||
const response = await page.goto(new URL('non-existing', pageRouter.url).href) | ||
const response = await page.goto( | ||
new URL('base/path/non-existing', pageRouterBasePathI18n.url).href, | ||
) | ||
const headers = response?.headers() || {} | ||
expect(response?.status()).toBe(404) | ||
|
||
expect(await page.textContent('p')).toBe('Custom 404 page') | ||
expect(await page.textContent('p')).toBe('Custom 404 page for locale: en') | ||
|
||
// https://github.com/vercel/next.js/pull/69802 made changes to returned cache-control header, | ||
// after that 404 pages would have `private` directive, before that it would not | ||
|
@@ -1375,13 +1407,15 @@ test.describe('Page Router with basePath and i18n', () => { | |
|
||
test('requesting a non existing page route that needs to be fetched from the blob store like 404.html (notFound: true)', async ({ | ||
page, | ||
pageRouter, | ||
pageRouterBasePathI18n, | ||
}) => { | ||
const response = await page.goto(new URL('static/not-found', pageRouter.url).href) | ||
const response = await page.goto( | ||
new URL('base/path/static/not-found', pageRouterBasePathI18n.url).href, | ||
) | ||
const headers = response?.headers() || {} | ||
expect(response?.status()).toBe(404) | ||
|
||
expect(await page.textContent('p')).toBe('Custom 404 page') | ||
expect(await page.textContent('p')).toBe('Custom 404 page for locale: en') | ||
|
||
expect(headers['debug-netlify-cdn-cache-control']).toBe( | ||
nextVersionSatisfies('>=15.0.0-canary.187') | ||
|
@@ -1390,4 +1424,36 @@ test.describe('Page Router with basePath and i18n', () => { | |
) | ||
expect(headers['cache-control']).toBe('public,max-age=0,must-revalidate') | ||
}) | ||
|
||
test.describe('static assets and function invocations', () => { | ||
test('should return 200 for an existing static asset without invoking a function', async ({ | ||
page, | ||
pageRouterBasePathI18n, | ||
}) => { | ||
// Since assets are hashed, we can't hardcode anything here. Find something to fetch. | ||
const [staticAsset] = await readdir( | ||
join(pageRouterBasePathI18n.isolatedFixtureRoot, '.next', 'static', 'chunks'), | ||
) | ||
expect(staticAsset).toBeDefined() | ||
|
||
const response = await page.goto( | ||
`${pageRouterBasePathI18n.url}/base/path/_next/static/chunks/${staticAsset}`, | ||
) | ||
|
||
expect(response?.status()).toBe(200) | ||
expect(response?.headers()).not.toHaveProperty('x-nf-function-type') | ||
}) | ||
|
||
test('should return 404 for a nonexistent static asset without invoking a function', async ({ | ||
page, | ||
pageRouterBasePathI18n, | ||
}) => { | ||
const response = await page.goto( | ||
`${pageRouterBasePathI18n.url}/base/path/_next/static/stale123abcdef.js`, | ||
) | ||
|
||
expect(response?.status()).toBe(404) | ||
expect(response?.headers()).not.toHaveProperty('x-nf-function-type') | ||
}) | ||
}) | ||
}) |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.