Skip to content
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

Correct page path for GS(S)P data refreshing #16939

Merged
merged 1 commit into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/next/server/hot-reloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,9 @@ export default class HotReloader {
if (serverOnlyChanges.length > 0) {
this.send({
event: 'serverOnlyChanges',
pages: serverOnlyChanges.map((pg) => pg.substr('pages'.length)),
pages: serverOnlyChanges.map((pg) =>
denormalizePagePath(pg.substr('pages'.length))
),
})
}

Expand Down
25 changes: 25 additions & 0 deletions test/integration/gssp-ssr-change-reloading/pages/another/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useRouter } from 'next/router'

export default function Gsp(props) {
if (useRouter().isFallback) {
return 'Loading...'
}

return (
<>
<p id="change">change me</p>
<p id="props">{JSON.stringify(props)}</p>
</>
)
}

export const getStaticProps = async () => {
const count = 1

return {
props: {
count,
random: Math.random(),
},
}
}
25 changes: 25 additions & 0 deletions test/integration/gssp-ssr-change-reloading/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useRouter } from 'next/router'

export default function Gsp(props) {
if (useRouter().isFallback) {
return 'Loading...'
}

return (
<>
<p id="change">change me</p>
<p id="props">{JSON.stringify(props)}</p>
</>
)
}

export const getStaticProps = async () => {
const count = 1

return {
props: {
count,
random: Math.random(),
},
}
}
28 changes: 28 additions & 0 deletions test/integration/gssp-ssr-change-reloading/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,34 @@ describe('GS(S)P Server-Side Change Reloading', () => {
page.restore()
})

it('should update page when getStaticProps is changed only for /index', async () => {
const browser = await webdriver(appPort, '/')
await browser.eval(() => (window.beforeChange = 'hi'))

const props = JSON.parse(await browser.elementByCss('#props').text())
expect(props.count).toBe(1)

const page = new File(join(appDir, 'pages/index.js'))
page.replace('count = 1', 'count = 2')

expect(await browser.eval('window.beforeChange')).toBe('hi')
page.restore()
})

it('should update page when getStaticProps is changed only for /another/index', async () => {
const browser = await webdriver(appPort, '/another')
await browser.eval(() => (window.beforeChange = 'hi'))

const props = JSON.parse(await browser.elementByCss('#props').text())
expect(props.count).toBe(1)

const page = new File(join(appDir, 'pages/another/index.js'))
page.replace('count = 1', 'count = 2')

expect(await browser.eval('window.beforeChange')).toBe('hi')
page.restore()
})

it('should not reload page when client-side is changed too GSSP', async () => {
const browser = await webdriver(appPort, '/gssp-blog/first')
await browser.eval(() => (window.beforeChange = 'hi'))
Expand Down