rsnext/test/integration/client-404
Joe Haddad 0a72d14deb
Make loadPage track success of script loading (#16334)
Prior to this PR, `loadPage` would call `loadScript` which would then report if the script failed to load.

This was problematic because `loadScript` notified a failure to load via `pageRegisterEvents`, which would not set the `pageCache` value for future requests.
This means a one-off promise rejection would happen, [in lieu of being] typically consumed within the client-side router, causing a server-side reload.

However, when `loadPage` was used independently (i.e. to preload pages), this promise rejection would be ignored as a preload failure.
When the real routing request comes in, the `loadPage` function skips its attempt to load the `<script>` because it was already in the DOM, and the router would stop functioning.

---

To fix this behavior, I've removed erroneous emits on `pageRegisterEvents` to only happen during the page registration lifecycle (its intended use).

The new behavior is that `loadScript` returns a `Promise` that `loadPage` can track, and if any of the page(s) scripts fail to load, we mark the entire page as errored in `pageCache`. This ensures future requests to `loadPage` will always immediately reject with a `PAGE_LOAD_ERROR`, which causes the server-side redirect at the appropriate point.

---

Fixes #16333
2020-08-19 11:41:01 +00:00
..
pages Make loadPage track success of script loading (#16334) 2020-08-19 11:41:01 +00:00
test Make loadPage track success of script loading (#16334) 2020-08-19 11:41:01 +00:00
next.config.js Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00