Skip to content

fix(react): use a separate reloadOnError storage key per lazy component - #2001

Open
JeongHwan-dev wants to merge 1 commit into
toss:mainfrom
JeongHwan-dev:fix/react-reload-on-error-storage-key
Open

JeongHwan-dev wants to merge 1 commit into
toss:mainfrom
JeongHwan-dev:fix/react-reload-on-error-storage-key

Conversation

@JeongHwan-dev

Copy link
Copy Markdown
Contributor

Overview

reloadOnError stores its retry count in storage under load.toString(). The load passed to onError/onSuccess is not the user's import function but the internal wrapper created in createLazy:

const loadNoReturn = () => load().then(noop)

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() is true, 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. A fails, the shared count becomes 1, the page reloads.
  2. After the reload B loads successfully and its onSuccess calls removeItem on the shared key.
  3. A fails again, reads no count, writes 1, reloads again.
  4. Repeat. retry: 1 never stops the loop.

Reproduced with the new spec on main (three simulated page loads):

A.load.toString() === B.load.toString() -> true
after A fails:    storage = [ ['() => load().then(noop)', '1'] ]
after B succeeds: storage = []
distinct storage keys written: 1
reload() calls after 3 page loads with retry: 1 -> 3

The opposite also happens: once A has used up the shared count, an unrelated component B gets no retry at all.

After

loadNoReturn reports the user's original load source from toString(), so each lazy component keys its retry count by its own import:

const loadNoReturn = Object.assign(() => load().then(noop), { toString: () => load.toString() })

Same scenario on this branch:

A.load.toString() === B.load.toString() -> false
after A fails:    storage = [ ["() => failingImport('/failing-component')", '1'] ]
after B succeeds: storage still holds A's count
reload() calls after 2 page loads with retry: 1 -> 1

No public API changes. Component.load still returns Promise<void>; only its toString() output changes, which is what reloadOnError already relied on.

Tests

Added should keep a separate retry count per lazy component to lazy.spec.tsx: renders a failing and a succeeding lazy component together, asserts their load.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 when retry: 1 is exhausted. The test fails on main at the first assertion.

Existing reloadOnError specs only ever used one component, which is why this went unnoticed. All 194 tests in @suspensive/react pass.

PR Checklist

  • I did below actions if need
  1. I read the Contributing Guide
  2. I added documents and tests.

🤖 Generated with Claude Code

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>
@coauthors

coauthors Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

People can be co-author:

Candidate Reasons Count Add this as commit message
@JeongHwan-dev #2001 1 Co-authored-by: JeongHwan-dev <68452755+JeongHwan-dev@users.noreply.github.com>
@codecov-commenter #2001 (comment) 1 Co-authored-by: codecov-commenter <65553080+codecov-commenter@users.noreply.github.com>

@vercel

vercel Bot commented Nov 8, 2026

Copy link
Copy Markdown
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-bot

changeset-bot Bot commented Nov 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4f45041

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@suspensive/react Patch
@suspensive/codemods Patch
@suspensive/jotai Patch
@suspensive/react-query-4 Patch
@suspensive/react-query-5 Patch
@suspensive/react-query Patch

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-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.22%. Comparing base (5b76bda) to head (4f45041).

Additional details and impacted files

Impacted file tree graph

@@           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           
Components Coverage Δ
@suspensive/react 100.00% <100.00%> (ø)
@suspensive/react-query 95.83% <ø> (ø)
@suspensive/react-query-4 100.00% <ø> (ø)
@suspensive/react-query-5 100.00% <ø> (ø)
@suspensive/jotai 100.00% <ø> (ø)
@suspensive/codemods 81.60% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants