-
Notifications
You must be signed in to change notification settings - Fork 29.9k
[turbopack] Enable the filesystem cache for dev in canary builds #85940
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
Open
lukesandberg
wants to merge
4
commits into
canary
Choose a base branch
from
ship_ship_ship
base: canary
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,313 @@ | ||
| import { nextTestSetup, isNextDev } from 'e2e-utils' | ||
| import { waitFor } from 'next-test-utils' | ||
|
|
||
| process.env.NEXT_PUBLIC_ENV_VAR = 'hello world' | ||
| // Make it easier to run in development, test directories are cleared between runs already so this is safe. | ||
| process.env.TURBO_ENGINE_IGNORE_DIRTY = '1' | ||
| // decrease the idle timeout to make the test more reliable | ||
| process.env.TURBO_ENGINE_SNAPSHOT_IDLE_TIMEOUT_MILLIS = '1000' | ||
|
|
||
| for (const cacheEnabled of [false, true]) { | ||
| describe(`filesystem-caching with cache ${cacheEnabled ? 'enabled' : 'disabled'}`, () => { | ||
| const { skipped, next, isTurbopack } = nextTestSetup({ | ||
| files: __dirname, | ||
| skipDeployment: true, | ||
| packageJson: { | ||
| scripts: { | ||
| build: `ENABLE_CACHING=${cacheEnabled ? '1' : ''} next build`, | ||
| dev: `ENABLE_CACHING=${cacheEnabled ? '1' : ''} next dev`, | ||
| start: 'next start', | ||
| }, | ||
| }, | ||
| // We need to use npm here as pnpms symlinks trigger a weird bug (kernel bug?) | ||
| installCommand: 'npm i', | ||
| // Next is always started with caching, but this can disable it for the followup restarts | ||
| buildCommand: `npm run build`, | ||
| startCommand: isNextDev ? 'npm run dev' : 'npm run start', | ||
| }) | ||
|
|
||
| if (skipped) { | ||
| return | ||
| } | ||
|
|
||
| beforeAll(() => { | ||
| // We can skip the dev watch delay since this is not an HMR test | ||
| ;(next as any).handleDevWatchDelayBeforeChange = () => {} | ||
| ;(next as any).handleDevWatchDelayAfterChange = () => {} | ||
| }) | ||
|
|
||
| async function restartCycle() { | ||
| await stop() | ||
| await start() | ||
| } | ||
|
|
||
| async function stop() { | ||
| if (isNextDev) { | ||
| // Give FileSystem Cache time to write to disk | ||
| // Turbopack is configured to wait 1s above. | ||
| // Webpack has an idle timeout (after large changes) of 1s | ||
| // and we give time a bit more to allow writing to disk | ||
| await waitFor(3000) | ||
| } | ||
| await next.stop() | ||
| } | ||
|
|
||
| async function start() { | ||
| await next.start() | ||
| } | ||
|
|
||
| it('should cache or not cache loaders', async () => { | ||
| let appTimestamp, unchangedTimestamp, appClientTimestamp, pagesTimestamp | ||
| { | ||
| const browser = await next.browser('/') | ||
| appTimestamp = await browser.elementByCss('main').text() | ||
| expect(appTimestamp).toMatch(/Timestamp = \d+$/) | ||
| await browser.close() | ||
| } | ||
| { | ||
| const browser = await next.browser('/unchanged') | ||
| unchangedTimestamp = await browser.elementByCss('main').text() | ||
| expect(unchangedTimestamp).toMatch(/Timestamp = \d+$/) | ||
| await browser.close() | ||
| } | ||
| { | ||
| const browser = await next.browser('/client') | ||
| appClientTimestamp = await browser.elementByCss('main').text() | ||
| expect(appClientTimestamp).toMatch(/Timestamp = \d+$/) | ||
| await browser.close() | ||
| } | ||
| { | ||
| const browser = await next.browser('/pages') | ||
| pagesTimestamp = await browser.elementByCss('main').text() | ||
| expect(pagesTimestamp).toMatch(/Timestamp = \d+$/) | ||
| await browser.close() | ||
| } | ||
| await restartCycle() | ||
|
|
||
| { | ||
| const browser = await next.browser('/') | ||
| const newTimestamp = await browser.elementByCss('main').text() | ||
| expect(newTimestamp).toMatch(/Timestamp = \d+$/) | ||
| if (cacheEnabled) { | ||
| expect(newTimestamp).toBe(appTimestamp) | ||
| } else { | ||
| expect(newTimestamp).not.toBe(appTimestamp) | ||
| } | ||
| await browser.close() | ||
| } | ||
| { | ||
| const browser = await next.browser('/unchanged') | ||
| const newTimestamp = await browser.elementByCss('main').text() | ||
| expect(newTimestamp).toMatch(/Timestamp = \d+$/) | ||
| if (cacheEnabled) { | ||
| expect(newTimestamp).toBe(unchangedTimestamp) | ||
| } else { | ||
| expect(newTimestamp).not.toBe(unchangedTimestamp) | ||
| } | ||
| await browser.close() | ||
| } | ||
| { | ||
| const browser = await next.browser('/client') | ||
| const newTimestamp = await browser.elementByCss('main').text() | ||
| expect(newTimestamp).toMatch(/Timestamp = \d+$/) | ||
| if (cacheEnabled) { | ||
| expect(newTimestamp).toBe(appClientTimestamp) | ||
| } else { | ||
| expect(newTimestamp).not.toBe(appClientTimestamp) | ||
| } | ||
| await browser.close() | ||
| } | ||
| { | ||
| const browser = await next.browser('/pages') | ||
| const newTimestamp = await browser.elementByCss('main').text() | ||
| expect(newTimestamp).toMatch(/Timestamp = \d+$/) | ||
| if (cacheEnabled) { | ||
| expect(newTimestamp).toBe(pagesTimestamp) | ||
| } else { | ||
| expect(newTimestamp).not.toBe(pagesTimestamp) | ||
| } | ||
| await browser.close() | ||
| } | ||
| }) | ||
|
|
||
| function makeTextCheck(url: string, text: string) { | ||
| return textCheck.bind(null, url, text) | ||
| } | ||
|
|
||
| async function textCheck(url: string, text: string) { | ||
| const browser = await next.browser(url) | ||
| expect(await browser.elementByCss('p').text()).toBe(text) | ||
| await browser.close() | ||
| } | ||
|
|
||
| function makeFileEdit(file: string) { | ||
| return async (inner: () => Promise<void>) => { | ||
| await next.patchFile( | ||
| file, | ||
| (content) => { | ||
| return content.replace('hello world', 'hello filesystem cache') | ||
| }, | ||
| inner | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| interface Change { | ||
| checkInitial(): Promise<void> | ||
| withChange(previous: () => Promise<void>): Promise<void> | ||
| checkChanged(): Promise<void> | ||
| fullInvalidation?: boolean | ||
| } | ||
| const POTENTIAL_CHANGES: Record<string, Change> = { | ||
| 'RSC change': { | ||
| checkInitial: makeTextCheck('/', 'hello world'), | ||
| withChange: makeFileEdit('app/page.tsx'), | ||
| checkChanged: makeTextCheck('/', 'hello filesystem cache'), | ||
| }, | ||
| 'RCC change': { | ||
| checkInitial: makeTextCheck('/client', 'hello world'), | ||
| withChange: makeFileEdit('app/client/page.tsx'), | ||
| checkChanged: makeTextCheck('/client', 'hello filesystem cache'), | ||
| }, | ||
| 'Pages change': { | ||
| checkInitial: makeTextCheck('/pages', 'hello world'), | ||
| withChange: makeFileEdit('pages/pages.tsx'), | ||
| checkChanged: makeTextCheck('/pages', 'hello filesystem cache'), | ||
| }, | ||
| 'rename app page': { | ||
| checkInitial: makeTextCheck('/remove-me', 'hello world'), | ||
| async withChange(inner) { | ||
| await next.renameFolder('app/remove-me', 'app/add-me') | ||
| try { | ||
| await inner() | ||
| } finally { | ||
| await next.renameFolder('app/add-me', 'app/remove-me') | ||
| } | ||
| }, | ||
| checkChanged: makeTextCheck('/add-me', 'hello world'), | ||
| }, | ||
| // TODO fix this case with Turbopack | ||
| ...(isTurbopack | ||
| ? {} | ||
| : { | ||
| 'loader change': { | ||
| async checkInitial() { | ||
| await textCheck('/loader', 'hello world') | ||
| await textCheck('/loader/client', 'hello world') | ||
| }, | ||
| withChange: makeFileEdit('my-loader.js'), | ||
| async checkChanged() { | ||
| await textCheck('/loader', 'hello filesystem cache') | ||
| await textCheck('/loader/client', 'hello filesystem cache') | ||
| }, | ||
| fullInvalidation: !isTurbopack, | ||
| }, | ||
| }), | ||
| 'next config change': { | ||
| async checkInitial() { | ||
| await textCheck('/next-config', 'hello world') | ||
| await textCheck('/next-config/client', 'hello world') | ||
| }, | ||
| withChange: makeFileEdit('next.config.js'), | ||
| async checkChanged() { | ||
| await textCheck('/next-config', 'hello filesystem cache') | ||
| await textCheck('/next-config/client', 'hello filesystem cache') | ||
| }, | ||
| fullInvalidation: !isTurbopack, | ||
| }, | ||
| 'env var change': { | ||
| async checkInitial() { | ||
| await textCheck('/env', 'hello world') | ||
| await textCheck('/env/client', 'hello world') | ||
| }, | ||
| async withChange(inner) { | ||
| process.env.NEXT_PUBLIC_ENV_VAR = 'hello filesystem cache' | ||
| try { | ||
| await inner() | ||
| } finally { | ||
| process.env.NEXT_PUBLIC_ENV_VAR = 'hello world' | ||
| } | ||
| }, | ||
| async checkChanged() { | ||
| await textCheck('/env', 'hello filesystem cache') | ||
| await textCheck('/env/client', 'hello filesystem cache') | ||
| }, | ||
| }, | ||
| } as const | ||
|
|
||
| // Checking only single change and all combined for performance reasons. | ||
| const combinations = Object.entries(POTENTIAL_CHANGES).map(([k, v]) => [ | ||
| k, | ||
| [v], | ||
| ]) as Array<[string, Array<Change>]> | ||
| combinations.push([ | ||
| Object.keys(POTENTIAL_CHANGES).join(', '), | ||
| Object.values(POTENTIAL_CHANGES), | ||
| ]) | ||
|
|
||
| for (const [name, changes] of combinations) { | ||
| it(`should allow to change files while stopped (${name})`, async () => { | ||
| let fullInvalidation = !cacheEnabled | ||
| for (const change of changes) { | ||
| await change.checkInitial() | ||
| if (change.fullInvalidation) { | ||
| fullInvalidation = true | ||
| } | ||
| } | ||
|
|
||
| let unchangedTimestamp: string | ||
| if (!fullInvalidation) { | ||
| const browser = await next.browser('/unchanged') | ||
| unchangedTimestamp = await browser.elementByCss('main').text() | ||
| expect(unchangedTimestamp).toMatch(/Timestamp = \d+$/) | ||
| await browser.close() | ||
| } | ||
|
|
||
| async function checkChanged() { | ||
| for (const change of changes) { | ||
| await change.checkChanged() | ||
| } | ||
|
|
||
| if (!fullInvalidation) { | ||
| const browser = await next.browser('/unchanged') | ||
| const timestamp = await browser.elementByCss('main').text() | ||
| expect(unchangedTimestamp).toEqual(timestamp) | ||
| await browser.close() | ||
| } | ||
| } | ||
|
|
||
| await stop() | ||
|
|
||
| async function inner() { | ||
| await start() | ||
| await checkChanged() | ||
| // Some no-op change builds | ||
| for (let i = 0; i < 2; i++) { | ||
| await restartCycle() | ||
| await checkChanged() | ||
| } | ||
| await stop() | ||
| } | ||
|
|
||
| let current = inner | ||
| for (const change of changes) { | ||
| const prev = current | ||
| current = () => change.withChange(prev) | ||
| } | ||
| await current() | ||
|
|
||
| await start() | ||
| for (const change of changes) { | ||
| await change.checkInitial() | ||
| } | ||
|
|
||
| if (!fullInvalidation) { | ||
| const browser = await next.browser('/unchanged') | ||
| const timestamp = await browser.elementByCss('main').text() | ||
| expect(unchangedTimestamp).toEqual(timestamp) | ||
| await browser.close() | ||
| } | ||
| }, 200000) | ||
| } | ||
| }) | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.