Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/canary' into invalid-relative-…
Browse files Browse the repository at this point in the history
…href
  • Loading branch information
ijjk committed Jan 1, 2021
2 parents 1944640 + fad3256 commit 5d65dc2
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: yarn install --check-files
- 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:
name: Test Firefox (production)
Expand Down
5 changes: 3 additions & 2 deletions docs/api-reference/next.config.js/rewrites.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ module.exports = {
destination: '/another', // automatically becomes /docs/another
},
{
// does not add /docs since basePath: false is set
// does not add /docs to /without-basePath since basePath: false is set
// Note: this can not be used for internal rewrites e.g. `destination: '/another'`
source: '/without-basePath',
destination: '/another',
destination: 'https://example.com',
basePath: false,
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,28 @@ export class NextJsRequireCacheHotReloader implements Plugin {
compilation.outputOptions.path,
'webpack-runtime.js'
)

deleteCache(runtimeChunkPath)

for (const outputPath of this.previousOutputPathsWebpack5) {
if (!this.currentOutputPathsWebpack5.has(outputPath)) {
deleteCache(outputPath)
}
}

this.previousOutputPathsWebpack5 = new Set(
this.currentOutputPathsWebpack5
// we need to make sure to clear all server entries from cache
// since they can have a stale webpack-runtime cache
// which needs to always be in-sync
const entries = [...compilation.entries.keys()].filter((entry) =>
entry.toString().startsWith('pages/')
)
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
}

Expand Down
5 changes: 5 additions & 0 deletions test/integration/ssr-ctx/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react'

export const Idk = React.createContext(null)

export const useIdk = () => React.useContext(Idk)
9 changes: 9 additions & 0 deletions test/integration/ssr-ctx/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Idk } from '../context'

export default function MyApp({ Component, pageProps }) {
return (
<Idk.Provider value="hello world">
<Component {...pageProps} />
</Idk.Provider>
)
}
15 changes: 8 additions & 7 deletions test/integration/ssr-ctx/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from 'react'

const Idk = React.createContext(null)
import { useIdk } from '../context'

const Page = () => {
const idk = useIdk()

console.log(idk)

return (
<div>
<Idk.Provider value="hello world">
<Idk.Consumer>{(idk) => <p>Value: {idk}</p>}</Idk.Consumer>
</Idk.Provider>
</div>
<>
<p>Value: {idk}</p>
</>
)
}

Expand Down
53 changes: 45 additions & 8 deletions test/integration/ssr-ctx/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,66 @@

import { join } from 'path'
import {
File,
killApp,
findPort,
nextStart,
nextBuild,
renderViaHTTP,
check,
launchApp,
} from 'next-test-utils'

jest.setTimeout(1000 * 30)

const appDir = join(__dirname, '../')
const appPg = new File(join(appDir, 'pages/_app.js'))

let appPort
let app

describe('Production Usage', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))

const runTests = (isDev) => {
it('should render a page with context', async () => {
const html = await renderViaHTTP(appPort, '/')
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()
})
})

0 comments on commit 5d65dc2

Please sign in to comment.