fix(core): clear cached promise in lazy() on rejection (#2999) - #3002
Closed
webdevsamran wants to merge 1 commit into
Closed
fix(core): clear cached promise in lazy() on rejection (#2999)#3002webdevsamran wants to merge 1 commit into
webdevsamran wants to merge 1 commit into
Conversation
When lazy(fn) runs, if the dynamic import promise rejected (e.g. transient network or chunk load failure), the rejected promise was cached indefinitely. This caused: 1. Client: ErrorBoundary / Errored retry flows could never recover because remounting the component returned the cached rejected promise without invoking fn() again. 2. Server: Module-scoped lazy promises that rejected would poison all subsequent SSR requests for the lifetime of the process. 3. Unhandled rejection when fn() rejects since previous .then() had no rejection handler. This patch: - In both client and server lazy(), clears the cached promise reference p if the promise rejects, allowing subsequent load() / preload() calls to retry fn(). - Added unit test in lazy.spec.tsx verifying retry behavior after rejection. Fixes solidjs#2999
|
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Clears the cached promise in
lazy()on rejection, allowing dynamic imports that fail due to transient network or chunk-load errors to be retried on subsequent renders/preloads without requiring a hard page reload or permanently poisoning SSR.Problem
In both client (
packages/solid/src/render/component.ts) and server (packages/solid/src/server/rendering.ts) implementations oflazy(), the promise returned byfn()was cached permanently in closure variablep.If
fn()rejected:<Errored fallback={(_, reset) => <button onClick={reset}>Retry</button>}>) could never recover. Resetting/remounting the boundary simply re-observed the cached rejected promise without invokingfn()again..then()calls lacked a rejection handler, emitting unhandled promise rejections.Solution
lazy(), attach a rejection callback to the active promisecurthat clearsp(if (p === cur) p = undefined).load()/preload()invocations will callfn()afresh.fn()succeeds on retry,comp/resolvedis populated normally.packages/solid/web/test/lazy.spec.tsxverifying thatlazy().preload()retriesfn()after an initial rejection.Fixes #2999