From b0a469233b6069627d3cf1e232fd05077f5c798b Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Sun, 20 Jan 2019 13:41:49 +0100 Subject: [PATCH] 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) --- examples/with-data-prefetch/components/link.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/with-data-prefetch/components/link.js b/examples/with-data-prefetch/components/link.js index e772bdbd..504397b1 100644 --- a/examples/with-data-prefetch/components/link.js +++ b/examples/with-data-prefetch/components/link.js @@ -11,18 +11,16 @@ export const prefetch = async href => { const url = typeof href !== 'string' ? format(href) : href - const { pathname } = window.location + const parsedHref = resolve(window.location.pathname, url) - const parsedHref = resolve(pathname, url) - - const { query } = typeof href !== 'string' ? href : parse(url, true) + const { query, pathname } = typeof href !== 'string' ? href : parse(url, true) const Component = await Router.prefetch(parsedHref) // if Component exists and has getInitialProps // fetch the component props (the component should save it in cache) if (Component && Component.getInitialProps) { - const ctx = { pathname: href, query, isVirtualCall: true } + const ctx = { pathname, query, isVirtualCall: true } await Component.getInitialProps(ctx) } }