Repository navigation
fix(react): use a separate reloadOnError storage key per lazy component - #2001
Open
JeongHwan-dev wants to merge 1 commit into
Open
JeongHwan-dev wants to merge 1 commit into
JeongHwan-dev wants to merge 1 commit into
Conversation
reloadOnError keys its retry count by `load.toString()`, but the `load` it receives is the internal `loadNoReturn` wrapper, whose source text is identical for every component created by createLazy. All lazy components therefore shared one sessionStorage entry: a failing chunk bumped the count, any other component's successful load removed it, and the next page load started again from zero, so `retry: 1` could reload forever. Expose the user's original `load` source through `loadNoReturn.toString` so each lazy component gets its own key. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
People can be co-author:
|
Contributor
|
@JeongHwan-dev is attempting to deploy a commit to the Toss Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 4f45041 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2001 +/- ##
=======================================
Coverage 93.22% 93.22%
=======================================
Files 42 42
Lines 664 664
Branches 163 164 +1
=======================================
Hits 619 619
Misses 42 42
Partials 3 3
🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Overview
reloadOnErrorstores its retry count instorageunderload.toString(). Theloadpassed toonError/onSuccessis not the user's import function but the internal wrapper created increateLazy:That wrapper's source text is the same for every lazy component, so every component shares a single storage key. Checked in a test:
A.load.toString() === B.load.toString()istrue, and the key is literally"() => load().then(noop)".Before
With
retry: 1, a page that has one broken chunk (A) and one healthy one (B):1, the page reloads.onSuccesscallsremoveItemon the shared key.1, reloads again.retry: 1never stops the loop.Reproduced with the new spec on
main(three simulated page loads):The opposite also happens: once A has used up the shared count, an unrelated component B gets no retry at all.
After
loadNoReturnreports the user's originalloadsource fromtoString(), so each lazy component keys its retry count by its own import:Same scenario on this branch:
No public API changes.
Component.loadstill returnsPromise<void>; only itstoString()output changes, which is whatreloadOnErroralready relied on.Tests
Added
should keep a separate retry count per lazy componenttolazy.spec.tsx: renders a failing and a succeeding lazy component together, asserts theirload.toString()differ, that the succeeding component's load does not clear the failing one's count, and that a second page load does not reload again whenretry: 1is exhausted. The test fails onmainat the first assertion.Existing
reloadOnErrorspecs only ever used one component, which is why this went unnoticed. All 194 tests in@suspensive/reactpass.PR Checklist
🤖 Generated with Claude Code