rsnext/packages/next
Jan Potoms 381e44f324
Fix static data fetching when using absolute assetprefix (#15287)
Fixes https://github.com/vercel/next.js/issues/15188

`parseRelativeUrl` was used on urls that weren't always relative. It was used to generate a cache key, but we actually don't need these cache keys to be relative if the urls aren't relative.

Also took a look at the overall static data fetching logic and found a few things:

- [x] cache key is unnecessarily transformed through `prepareRoute`, we can just cache by resolved `dataHref` and remove that function. Pretty sure that `prepareRoute` was also introducing edge cases with `assetPath` and `delBasePath`
- [x] there is [a bug in the caching logic](ebdfa2e7a3/packages/next/next-server/lib/router/router.ts (L898)) that made it fail on the second visit: it should be `Promise.resolve(this.sdc[pathname])` instead of `Promise.resolve(this.sdc[dataHref])`. Also added a test for this
- [x] ~converted to async await to improve stacktraces and readability.~ I assumed this was fine since I saw some async/awaits in that file already but it seems to just blow up the size of the non-modern bundle.
- [x] extracted nested `getResponse` function and define it top level. this should improve runtime performance
- [x] convert `_getStaticData` and `_getServerData` to class methods instead of properties. Not sure why they were defined as properties but I think they belong on the prototype instead.
- [x] remove `cb` property from `fetchNextData`, it's unnecessary and makes the async flow hard to understand.  The exact same logic can go in the `.then` instead.
- [ ] data fetching logic [retries on 5xx errors](ebdfa2e7a3/packages/next/next-server/lib/router/router.ts (L157)), but not on network level errors. It should also retry on those. It should also not retry on every 5xx, probably only makes sense on 502, 503 and 504. (e.g. 500 is a server error that I wouldn't expect to succeed on a retry)

The overall result also is a few bytes smaller in size
2020-07-19 04:02:01 +00:00
..
bin Update references to zeit/next.js (#13463) 2020-05-27 17:51:11 -04:00
build Fix app-document-import-order test for webpack 5 (#15224) 2020-07-17 10:38:06 +02:00
cli Fix: Invalid flag provided to next build results in UnhandledPromiseRejectionWarning (#15049) 2020-07-13 23:07:35 +02:00
client Fix no-anon-default-export for webpack 5 (#15293) 2020-07-18 18:34:05 +00:00
compiled Make type checking compatible with webpack 5 (#15158) 2020-07-15 13:56:27 -04:00
export Remove buildId from server-side files (#14413) 2020-06-22 21:12:36 +00:00
lib Drop module: esnext requirement in tsconfig.json (#15276) 2020-07-18 19:37:13 +00:00
next-server Fix static data fetching when using absolute assetprefix (#15287) 2020-07-19 04:02:01 +00:00
pages Add warning when viewport meta tag is added to _document.js (#13452) 2020-07-07 01:43:16 -04:00
server Fix DevServer#close doesn't close all resources (#15247) 2020-07-17 09:07:48 +00:00
telemetry Record presence of reportWebVitals (#13155) 2020-05-20 18:44:39 +00:00
types Fix app-document-import-order test for webpack 5 (#15224) 2020-07-17 10:38:06 +02:00
amp.d.ts Remove re-exports of default when they don't exist (#9450) 2019-11-18 20:11:59 -06:00
amp.js Move next-server back into next package (#8613) 2019-09-04 10:00:54 -04:00
app.d.ts Move syntax formatting to prettier (#7454) 2019-05-29 13:57:26 +02:00
app.js Add missing dependencies to server (#5369) 2018-10-03 00:08:57 +02:00
babel.d.ts Remove re-exports of default when they don't exist (#9450) 2019-11-18 20:11:59 -06:00
babel.js Monorepo (#5341) 2018-10-01 01:02:10 +02:00
client.d.ts Move syntax formatting to prettier (#7454) 2019-05-29 13:57:26 +02:00
client.js Monorepo (#5341) 2018-10-01 01:02:10 +02:00
config.d.ts Move next-server back into next package (#8613) 2019-09-04 10:00:54 -04:00
config.js Move next-server back into next package (#8613) 2019-09-04 10:00:54 -04:00
constants.d.ts Remove default export from constants.d.ts (#8979) 2019-10-07 14:30:07 +02:00
constants.js Move next-server back into next package (#8613) 2019-09-04 10:00:54 -04:00
data.d.ts Remove re-exports of default when they don't exist (#9450) 2019-11-18 20:11:59 -06:00
data.js amp-bind data injection (#6840) 2019-04-02 16:09:34 +02:00
document.d.ts Move syntax formatting to prettier (#7454) 2019-05-29 13:57:26 +02:00
document.js Add missing dependencies to server (#5369) 2018-10-03 00:08:57 +02:00
dynamic.d.ts Move next-server back into next package (#8613) 2019-09-04 10:00:54 -04:00
dynamic.js Move next-server back into next package (#8613) 2019-09-04 10:00:54 -04:00
error.d.ts Move syntax formatting to prettier (#7454) 2019-05-29 13:57:26 +02:00
error.js Add missing dependencies to server (#5369) 2018-10-03 00:08:57 +02:00
head.d.ts Move next-server back into next package (#8613) 2019-09-04 10:00:54 -04:00
head.js Move next-server back into next package (#8613) 2019-09-04 10:00:54 -04:00
license.md Update year on license files 2020-04-21 12:24:08 +02:00
link.d.ts Move syntax formatting to prettier (#7454) 2019-05-29 13:57:26 +02:00
link.js Bring back module.exports because of backwards compat (#5815) 2018-12-04 15:26:20 +01:00
package.json v9.4.5-canary.37 2020-07-17 11:08:33 +02:00
README.md Change authors member and links (#14367) 2020-07-05 11:36:50 +02:00
router.d.ts Move syntax formatting to prettier (#7454) 2019-05-29 13:57:26 +02:00
router.js Bring back module.exports because of backwards compat (#5815) 2018-12-04 15:26:20 +01:00
taskfile-babel.js Add support for debugging Next.js core (#13101) 2020-05-20 03:18:02 +00:00
taskfile-ncc.js Lint for invalid imports (#13482) 2020-05-28 08:23:10 +00:00
taskfile.js Use single webpack runtimeChunk for Node.js compilation (#14722) 2020-07-01 15:34:00 +00:00
tsconfig.json Move next-server back into next package (#8613) 2019-09-04 10:00:54 -04:00

Next.js

Getting Started

Visit https://nextjs.org/learn to get started with Next.js.

Documentation

Visit https://nextjs.org/docs to view the documentation.

Contributing

Please see our contributing.md.

Authors