• J
    Make `loadPage` track success of script loading (#16334) · 0a72d14d
    Joe Haddad 提交于
    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
    0a72d14d
page-loader.ts 16.4 KB