Skip to content

fix(browser): preserve funnel history in StrictMode - #185

Open
chungyo wants to merge 1 commit into
toss:mainfrom
chungyo:fix/strict-mode-history-cleanup
Open

fix(browser): preserve funnel history in StrictMode#185
chungyo wants to merge 1 commit into
toss:mainfrom
chungyo:fix/strict-mode-history-cleanup

Conversation

@chungyo

@chungyo chungyo commented Sep 1, 2026

Copy link
Copy Markdown

Why

React Strict Mode replays effects with an extra setup-cleanup-setup cycle in development. The browser adapter cleanup removes the funnel step from the URL and its context and histories from history.state, so the current screen survives the first reload while its persisted state is lost. A second reload then resets the funnel to its initial step.

Closes #170.

What changed

  • Restore cleanup state only when React reconnects effects on the same mounted funnel instance.
  • Use the exact cleaned URL and history.state entry as a compare-and-swap guard, so another navigation or state update is never overwritten.
  • Keep real unmount cleanup synchronous, preserve unrelated query, state, and hash values, and keep same-ID remounts starting from the initial step.
  • Add browser unit coverage, a Next App Router reload regression test, and a patch changeset.

Verification

  • pnpm --filter @use-funnel/browser exec vitest run (6 passed)
  • pnpm --filter @use-funnel/browser build
  • ESLint and Prettier checks for changed files
  • Next 14.2.13 / React 18.3.1 App Router E2E (3 passed)
  • Isolated Next 15.5.25 / React 19.0.8 regression E2E and TypeScript check
  • Existing core, Next, React Router, React Router DOM, and React Navigation Native test suites

React StrictMode replays effects in development, causing cleanup to remove the persisted step, context, and histories after a reload.

Restore the snapshot only when the same mounted funnel reconnects, while keeping cleanup synchronous for real unmounts.

Refs toss#170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: reactStrictMode가 켜져있을 시 새로고침 시 history가 날라갑니다.

1 participant