Skip to content

Commit b0a4692

Browse files
kertaltimneutkens
authored andcommitted
Close #5607 - Bug in examples/with-data-prefetch (#6093)
ctx.pathname was set to url including the query of the page to prefetch therefore the page was cached with the wrong key (article%3Fid=1?id=1), and that's why the cache didn't work (right key: article?id=1)
1 parent 0714300 commit b0a4692

File tree

1 file changed

+3
-5
lines changed
  • examples/with-data-prefetch/components

1 file changed

+3
-5
lines changed

examples/with-data-prefetch/components/link.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@ export const prefetch = async href => {
1111

1212
const url = typeof href !== 'string' ? format(href) : href
1313

14-
const { pathname } = window.location
14+
const parsedHref = resolve(window.location.pathname, url)
1515

16-
const parsedHref = resolve(pathname, url)
17-
18-
const { query } = typeof href !== 'string' ? href : parse(url, true)
16+
const { query, pathname } = typeof href !== 'string' ? href : parse(url, true)
1917

2018
const Component = await Router.prefetch(parsedHref)
2119

2220
// if Component exists and has getInitialProps
2321
// fetch the component props (the component should save it in cache)
2422
if (Component && Component.getInitialProps) {
25-
const ctx = { pathname: href, query, isVirtualCall: true }
23+
const ctx = { pathname, query, isVirtualCall: true }
2624
await Component.getInitialProps(ctx)
2725
}
2826
}

0 commit comments

Comments
 (0)