未验证 提交 9c8d0465 编写于 作者: J JJ Kasper 提交者: GitHub

Ensure all entries are cleared from cache on runtime change (#20652)

上级 16d464ca
...@@ -153,7 +153,7 @@ jobs: ...@@ -153,7 +153,7 @@ jobs:
- run: cat package.json | jq '.resolutions."react-dom" = "^17.0.1"' > package.json.tmp && mv package.json.tmp package.json - run: cat package.json | jq '.resolutions."react-dom" = "^17.0.1"' > package.json.tmp && mv package.json.tmp package.json
- run: yarn install --check-files - run: yarn install --check-files
- run: yarn list webpack react react-dom - run: yarn list webpack react react-dom
- run: xvfb-run node run-tests.js test/integration/link-ref/test/index.test.js test/integration/production/test/index.test.js test/integration/basic/test/index.test.js test/integration/async-modules/test/index.test.js test/integration/font-optimization/test/index.test.js test/acceptance/*.test.js - run: xvfb-run node run-tests.js test/integration/{link-ref,production,basic,async-modules,font-optimization,ssr-ctx}/test/index.test.js test/acceptance/*.test.js
testFirefox: testFirefox:
name: Test Firefox (production) name: Test Firefox (production)
......
...@@ -38,20 +38,28 @@ export class NextJsRequireCacheHotReloader implements Plugin { ...@@ -38,20 +38,28 @@ export class NextJsRequireCacheHotReloader implements Plugin {
compilation.outputOptions.path, compilation.outputOptions.path,
'webpack-runtime.js' 'webpack-runtime.js'
) )
deleteCache(runtimeChunkPath) deleteCache(runtimeChunkPath)
for (const outputPath of this.previousOutputPathsWebpack5) { // we need to make sure to clear all server entries from cache
if (!this.currentOutputPathsWebpack5.has(outputPath)) { // since they can have a stale webpack-runtime cache
deleteCache(outputPath) // which needs to always be in-sync
} const entries = [...compilation.entries.keys()].filter((entry) =>
} entry.toString().startsWith('pages/')
this.previousOutputPathsWebpack5 = new Set(
this.currentOutputPathsWebpack5
) )
this.currentOutputPathsWebpack5.clear()
entries.forEach((page) => {
const outputPath = path.join(
compilation.outputOptions.path,
page + '.js'
)
deleteCache(outputPath)
})
}) })
this.previousOutputPathsWebpack5 = new Set(
this.currentOutputPathsWebpack5
)
this.currentOutputPathsWebpack5.clear()
return return
} }
......
import React from 'react'
export const Idk = React.createContext(null)
export const useIdk = () => React.useContext(Idk)
import { Idk } from '../context'
export default function MyApp({ Component, pageProps }) {
return (
<Idk.Provider value="hello world">
<Component {...pageProps} />
</Idk.Provider>
)
}
import React from 'react' import React from 'react'
import { useIdk } from '../context'
const Idk = React.createContext(null)
const Page = () => { const Page = () => {
const idk = useIdk()
console.log(idk)
return ( return (
<div> <>
<Idk.Provider value="hello world"> <p>Value: {idk}</p>
<Idk.Consumer>{(idk) => <p>Value: {idk}</p>}</Idk.Consumer> </>
</Idk.Provider>
</div>
) )
} }
......
...@@ -2,29 +2,66 @@ ...@@ -2,29 +2,66 @@
import { join } from 'path' import { join } from 'path'
import { import {
File,
killApp, killApp,
findPort, findPort,
nextStart, nextStart,
nextBuild, nextBuild,
renderViaHTTP, renderViaHTTP,
check,
launchApp,
} from 'next-test-utils' } from 'next-test-utils'
jest.setTimeout(1000 * 30) jest.setTimeout(1000 * 30)
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
const appPg = new File(join(appDir, 'pages/_app.js'))
let appPort let appPort
let app let app
describe('Production Usage', () => { const runTests = (isDev) => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
it('should render a page with context', async () => { it('should render a page with context', async () => {
const html = await renderViaHTTP(appPort, '/') const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/Value: .*?hello world/) expect(html).toMatch(/Value: .*?hello world/)
}) })
if (isDev) {
it('should render with context after change', async () => {
appPg.replace('hello world', 'new value')
try {
await check(() => renderViaHTTP(appPort, '/'), /Value: .*?new value/)
} finally {
appPg.restore()
}
await check(() => renderViaHTTP(appPort, '/'), /Value: .*?hello world/)
})
}
}
describe('React Context', () => {
describe('dev mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
appPg.restore()
})
runTests(true)
})
describe('production mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
}) })
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册