From ea08a30fb763785635f6a181d18e40b52c66d138 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 8 Sep 2020 10:32:02 -0500 Subject: [PATCH] Correct page page for GS(S)P data refreshing --- packages/next/server/hot-reloader.ts | 4 ++- .../pages/another/index.js | 25 +++++++++++++++++ .../gssp-ssr-change-reloading/pages/index.js | 25 +++++++++++++++++ .../test/index.test.js | 28 +++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 test/integration/gssp-ssr-change-reloading/pages/another/index.js create mode 100644 test/integration/gssp-ssr-change-reloading/pages/index.js diff --git a/packages/next/server/hot-reloader.ts b/packages/next/server/hot-reloader.ts index c7fc19ff00fdf..abeb3872300c9 100644 --- a/packages/next/server/hot-reloader.ts +++ b/packages/next/server/hot-reloader.ts @@ -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)) + ), }) } diff --git a/test/integration/gssp-ssr-change-reloading/pages/another/index.js b/test/integration/gssp-ssr-change-reloading/pages/another/index.js new file mode 100644 index 0000000000000..679405ddf80ad --- /dev/null +++ b/test/integration/gssp-ssr-change-reloading/pages/another/index.js @@ -0,0 +1,25 @@ +import { useRouter } from 'next/router' + +export default function Gsp(props) { + if (useRouter().isFallback) { + return 'Loading...' + } + + return ( + <> +

change me

+

{JSON.stringify(props)}

+ + ) +} + +export const getStaticProps = async () => { + const count = 1 + + return { + props: { + count, + random: Math.random(), + }, + } +} diff --git a/test/integration/gssp-ssr-change-reloading/pages/index.js b/test/integration/gssp-ssr-change-reloading/pages/index.js new file mode 100644 index 0000000000000..679405ddf80ad --- /dev/null +++ b/test/integration/gssp-ssr-change-reloading/pages/index.js @@ -0,0 +1,25 @@ +import { useRouter } from 'next/router' + +export default function Gsp(props) { + if (useRouter().isFallback) { + return 'Loading...' + } + + return ( + <> +

change me

+

{JSON.stringify(props)}

+ + ) +} + +export const getStaticProps = async () => { + const count = 1 + + return { + props: { + count, + random: Math.random(), + }, + } +} diff --git a/test/integration/gssp-ssr-change-reloading/test/index.test.js b/test/integration/gssp-ssr-change-reloading/test/index.test.js index 1701a47de9e15..ea08563720e5c 100644 --- a/test/integration/gssp-ssr-change-reloading/test/index.test.js +++ b/test/integration/gssp-ssr-change-reloading/test/index.test.js @@ -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'))