Skip to content

Commit 13bac7c

Browse files
dan-weaverijjk
andauthored
fix popstate detection for safari when basepath is present (vercel#32687)
* fix popstate detection for safari when basepath is present * Add test case Co-authored-by: JJ Kasper <jj@jjsweb.site>
1 parent c529140 commit 13bac7c

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

.github/workflows/build_test_deploy.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ jobs:
432432
BROWSERSTACK: true
433433
BROWSER_NAME: 'safari'
434434
NEXT_TELEMETRY_DISABLED: 1
435+
NEXT_TEST_MODE: 'start'
435436
SKIP_LOCAL_SELENIUM_SERVER: true
436437
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
437438
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
@@ -464,7 +465,7 @@ jobs:
464465
- run: '[[ -z "$BROWSERSTACK_ACCESS_KEY" ]] && echo "Skipping for PR" || npm i -g browserstack-local@1.4.0'
465466
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
466467

467-
- run: '[[ -z "$BROWSERSTACK_ACCESS_KEY" ]] && echo "Skipping for PR" || node run-tests.js -c 1 test/integration/production/test/index.test.js'
468+
- run: '[[ -z "$BROWSERSTACK_ACCESS_KEY" ]] && echo "Skipping for PR" || node run-tests.js -c 1 test/integration/production/test/index.test.js test/e2e/basepath.test.ts'
468469
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
469470

470471
testSafariOld:

packages/next/shared/lib/router/router.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,11 @@ export default class Router implements BaseRouter {
824824

825825
// Make sure we don't re-render on initial load,
826826
// can be caused by navigating back from an external site
827-
if (this.isSsr && as === this.asPath && pathname === this.pathname) {
827+
if (
828+
this.isSsr &&
829+
as === addBasePath(this.asPath) &&
830+
pathname === addBasePath(this.pathname)
831+
) {
828832
return
829833
}
830834

test/e2e/basepath.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,29 @@ describe('basePath', () => {
9797
afterAll(() => next.destroy())
9898

9999
const runTests = (dev = false) => {
100+
it('should navigate to external site and back', async () => {
101+
const browser = await webdriver(next.url, `${basePath}/external-and-back`)
102+
const initialText = await browser.elementByCss('p').text()
103+
expect(initialText).toBe('server')
104+
105+
await browser
106+
.elementByCss('a')
107+
.click()
108+
.waitForElementByCss('input')
109+
.back()
110+
.waitForElementByCss('p')
111+
112+
await waitFor(1000)
113+
const newText = await browser.elementByCss('p').text()
114+
expect(newText).toBe('server')
115+
})
116+
117+
if (process.env.BROWSER_NAME === 'safari') {
118+
// currently only testing the above test in safari
119+
// we can investigate testing more cases below if desired
120+
return
121+
}
122+
100123
it('should navigate back correctly to a dynamic route', async () => {
101124
const browser = await webdriver(next.url, `${basePath}`)
102125

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const Page = ({ from }) => (
2+
<div>
3+
<p>{from}</p>
4+
<a href="https://google.com">External link</a>
5+
</div>
6+
)
7+
8+
Page.getInitialProps = () => {
9+
return { from: typeof window === 'undefined' ? 'server' : 'client' }
10+
}
11+
12+
export default Page

0 commit comments

Comments
 (0)