-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'canary' into update/use-pnpm
- Loading branch information
Showing
15 changed files
with
231 additions
and
22 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
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
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
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,6 @@ | ||
module.exports = { | ||
i18n: { | ||
locales: ['en', 'sv'], | ||
defaultLocale: 'en', | ||
}, | ||
} |
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,3 @@ | ||
export default function DynamicPage() { | ||
return <p id="page-type">dynamic</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,3 @@ | ||
export default function StaticPage() { | ||
return <p id="page-type">static</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,94 @@ | ||
import { join } from 'path' | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { check, waitFor } from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
|
||
import type { HistoryState } from '../../../packages/next/shared/lib/router/router' | ||
import { BrowserInterface } from 'test/lib/browsers/base' | ||
|
||
const emitPopsStateEvent = (browser: BrowserInterface, state: HistoryState) => | ||
browser.eval( | ||
`window.dispatchEvent(new PopStateEvent("popstate", { state: ${JSON.stringify( | ||
state | ||
)} }))` | ||
) | ||
|
||
describe('i18n: Event with stale state - static route previously was dynamic', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: { | ||
pages: new FileRef(join(__dirname, 'app/pages')), | ||
'next.config.js': new FileRef(join(__dirname, 'app/next.config.js')), | ||
}, | ||
dependencies: {}, | ||
}) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
test('Ignore event without query param', async () => { | ||
const browser = await webdriver(next.url, '/sv/static') | ||
browser.close() | ||
|
||
const state: HistoryState = { | ||
url: '/[dynamic]?', | ||
as: '/static', | ||
options: { locale: 'sv' }, | ||
__N: true, | ||
key: '', | ||
} | ||
|
||
expect(await browser.elementByCss('#page-type').text()).toBe('static') | ||
|
||
// 1st event is ignored | ||
await emitPopsStateEvent(browser, state) | ||
await waitFor(1000) | ||
expect(await browser.elementByCss('#page-type').text()).toBe('static') | ||
|
||
// 2nd event isn't ignored | ||
await emitPopsStateEvent(browser, state) | ||
await check(() => browser.elementByCss('#page-type').text(), 'dynamic') | ||
}) | ||
|
||
test('Ignore event with query param', async () => { | ||
const browser = await webdriver(next.url, '/sv/static?param=1') | ||
|
||
const state: HistoryState = { | ||
url: '/[dynamic]?param=1', | ||
as: '/static?param=1', | ||
options: { locale: 'sv' }, | ||
__N: true, | ||
key: '', | ||
} | ||
|
||
expect(await browser.elementByCss('#page-type').text()).toBe('static') | ||
|
||
// 1st event is ignored | ||
await emitPopsStateEvent(browser, state) | ||
await waitFor(1000) | ||
expect(await browser.elementByCss('#page-type').text()).toBe('static') | ||
|
||
// 2nd event isn't ignored | ||
await emitPopsStateEvent(browser, state) | ||
await check(() => browser.elementByCss('#page-type').text(), 'dynamic') | ||
}) | ||
|
||
test("Don't ignore event with different locale", async () => { | ||
const browser = await webdriver(next.url, '/sv/static?param=1') | ||
|
||
const state: HistoryState = { | ||
url: '/[dynamic]?param=1', | ||
as: '/static?param=1', | ||
options: { locale: 'en' }, | ||
__N: true, | ||
key: '', | ||
} | ||
|
||
expect(await browser.elementByCss('#page-type').text()).toBe('static') | ||
|
||
await emitPopsStateEvent(browser, state) | ||
await check(() => browser.elementByCss('#page-type').text(), 'dynamic') | ||
}) | ||
}) |
77 changes: 77 additions & 0 deletions
77
test/e2e/ignore-invalid-popstateevent/without-i18n.test.ts
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,77 @@ | ||
import { join } from 'path' | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { check, waitFor } from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
|
||
import type { HistoryState } from '../../../packages/next/shared/lib/router/router' | ||
import { BrowserInterface } from 'test/lib/browsers/base' | ||
|
||
const emitPopsStateEvent = (browser: BrowserInterface, state: HistoryState) => | ||
browser.eval( | ||
`window.dispatchEvent(new PopStateEvent("popstate", { state: ${JSON.stringify( | ||
state | ||
)} }))` | ||
) | ||
|
||
describe('Event with stale state - static route previously was dynamic', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
files: { | ||
pages: new FileRef(join(__dirname, 'app/pages')), | ||
// Don't use next.config.js to avoid getting i18n | ||
}, | ||
dependencies: {}, | ||
}) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
test('Ignore event without query param', async () => { | ||
const browser = await webdriver(next.url, '/static') | ||
browser.close() | ||
|
||
const state: HistoryState = { | ||
url: '/[dynamic]?', | ||
as: '/static', | ||
options: {}, | ||
__N: true, | ||
key: '', | ||
} | ||
|
||
expect(await browser.elementByCss('#page-type').text()).toBe('static') | ||
|
||
// 1st event is ignored | ||
await emitPopsStateEvent(browser, state) | ||
await waitFor(1000) | ||
expect(await browser.elementByCss('#page-type').text()).toBe('static') | ||
|
||
// 2nd event isn't ignored | ||
await emitPopsStateEvent(browser, state) | ||
await check(() => browser.elementByCss('#page-type').text(), 'dynamic') | ||
}) | ||
|
||
test('Ignore event with query param', async () => { | ||
const browser = await webdriver(next.url, '/static?param=1') | ||
|
||
const state: HistoryState = { | ||
url: '/[dynamic]?param=1', | ||
as: '/static?param=1', | ||
options: {}, | ||
__N: true, | ||
key: '', | ||
} | ||
|
||
expect(await browser.elementByCss('#page-type').text()).toBe('static') | ||
|
||
// 1st event is ignored | ||
await emitPopsStateEvent(browser, state) | ||
await waitFor(1000) | ||
expect(await browser.elementByCss('#page-type').text()).toBe('static') | ||
|
||
// 2nd event isn't ignored | ||
await emitPopsStateEvent(browser, state) | ||
await check(() => browser.elementByCss('#page-type').text(), 'dynamic') | ||
}) | ||
}) |
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
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