-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to merge props from GSSP methods with _app pageProps (#11709)
* Add warning for pageProps GSSP conflict * Update warning * Update to merge pageProps instead of warn on conflict * bump * Update merging
- Loading branch information
Showing
5 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,10 @@ | ||
const App = ({ Component, pageProps }) => <Component {...pageProps} /> | ||
|
||
App.getInitialProps = () => ({ | ||
pageProps: { | ||
hi: 'override me', | ||
hello: 'world', | ||
}, | ||
}) | ||
|
||
export default App |
This file contains 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,2 @@ | ||
export const getStaticProps = () => ({ props: { hi: 'hi' } }) | ||
export default props => <p>{JSON.stringify(props)}</p> |
This file contains 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,2 @@ | ||
export const getServerSideProps = () => ({ props: { hi: 'hi' } }) | ||
export default props => <p>{JSON.stringify(props)}</p> |
This file contains 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,81 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import fs from 'fs-extra' | ||
import { join } from 'path' | ||
import cheerio from 'cheerio' | ||
import { | ||
findPort, | ||
launchApp, | ||
killApp, | ||
renderViaHTTP, | ||
nextBuild, | ||
nextStart, | ||
} from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 | ||
const appDir = join(__dirname, '..') | ||
const nextConfig = join(appDir, 'next.config.js') | ||
|
||
let appPort | ||
let app | ||
|
||
const runTests = () => { | ||
it('should merge _app pageProps and getServerSideProps props', async () => { | ||
const html = await renderViaHTTP(appPort, '/gssp') | ||
const $ = cheerio.load(html) | ||
expect(JSON.parse($('p').text())).toEqual({ hi: 'hi', hello: 'world' }) | ||
}) | ||
|
||
it('should merge _app pageProps and getStaticProps props', async () => { | ||
const html = await renderViaHTTP(appPort, '/gsp') | ||
const $ = cheerio.load(html) | ||
expect(JSON.parse($('p').text())).toEqual({ hi: 'hi', hello: 'world' }) | ||
}) | ||
} | ||
|
||
describe('pageProps GSSP conflict', () => { | ||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
|
||
describe('production mode', () => { | ||
beforeAll(async () => { | ||
const { code } = await nextBuild(appDir) | ||
if (code !== 0) throw new Error(`build failed with code ${code}`) | ||
|
||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
|
||
describe('serverless mode', () => { | ||
beforeAll(async () => { | ||
await fs.writeFile( | ||
nextConfig, | ||
`module.exports = { | ||
target: 'experimental-serverless-trace' | ||
}` | ||
) | ||
const { code } = await nextBuild(appDir) | ||
if (code !== 0) throw new Error(`build failed with code ${code}`) | ||
|
||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(async () => { | ||
await fs.remove(nextConfig) | ||
await killApp(app) | ||
}) | ||
|
||
runTests() | ||
}) | ||
}) |