Skip to content

fix: Race condition in withFeatureFlagsOverrideDecorator#584

Merged
Patrick Lafrance (patricklafrance) merged 5 commits into
mainfrom
fix/issue-571
Apr 3, 2026
Merged

fix: Race condition in withFeatureFlagsOverrideDecorator#584
Patrick Lafrance (patricklafrance) merged 5 commits into
mainfrom
fix/issue-571

Conversation

@patricklafrance
Copy link
Copy Markdown
Member

Fix issue #571

…deDecorator (#571)

Add resetTransaction() to EditableLaunchDarklyClient to safely undo any
lingering transaction before starting a new one. This fixes a race condition
where a new OverrideFeatureFlags instance renders (calling startTransaction())
before the old instance's useEffect cleanup has run.

Neither useLayoutEffect nor useEffect can fix this because React's render
phase always executes before the commit phase where cleanup runs.

Also add ForceRemount regression stories that deterministically trigger
the race condition via a React key change to prevent regressions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 3, 2026 02:46
@patricklafrance Patrick Lafrance (patricklafrance) changed the title fix: Race conditions in withFeatureFlagsOverrideDecorator fix: Race condition in withFeatureFlagsOverrideDecorator Apr 3, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 3, 2026

Open in StackBlitz

@squide/core

pnpm add https://pkg.pr.new/@squide/core@584

@squide/env-vars

pnpm add https://pkg.pr.new/@squide/env-vars@584

@squide/fakes

pnpm add https://pkg.pr.new/@squide/fakes@584

@squide/firefly

pnpm add https://pkg.pr.new/@squide/firefly@584

@squide/firefly-module-federation

pnpm add https://pkg.pr.new/@squide/firefly-module-federation@584

@squide/firefly-rsbuild-configs

pnpm add https://pkg.pr.new/@squide/firefly-rsbuild-configs@584

@squide/firefly-storybook

pnpm add https://pkg.pr.new/@squide/firefly-storybook@584

@squide/firefly-webpack-configs

pnpm add https://pkg.pr.new/@squide/firefly-webpack-configs@584

@squide/i18next

pnpm add https://pkg.pr.new/@squide/i18next@584

@squide/launch-darkly

pnpm add https://pkg.pr.new/@squide/launch-darkly@584

@squide/msw

pnpm add https://pkg.pr.new/@squide/msw@584

@squide/react-router

pnpm add https://pkg.pr.new/@squide/react-router@584

commit: d20b38e

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a Storybook crash caused by a LaunchDarkly transaction race when withFeatureFlagsOverrideDecorator is unmounted/remounted before effect cleanup runs.

Changes:

  • Add resetTransaction() to EditableLaunchDarklyClient and implement it in the in-memory and local-storage clients.
  • Update withFeatureFlagsOverrideDecorator to call resetTransaction() during render and avoid double-undo() on cleanup.
  • Add Storybook sample stories that force a remount to reproduce/regress the original crash (both in-memory and local-storage clients).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
samples/storybook/host/src/ForceRemount.stories.tsx Adds a Storybook reproduction/regression story that forces a subtree remount.
samples/storybook/host/src/ForceRemountLocalStorageClient.stories.tsx Same forced-remount regression story, but using the LocalStorage LD client.
packages/launch-darkly/src/EditableLaunchDarklyClient.ts Extends the editable client contract with resetTransaction() and documents the rationale.
packages/launch-darkly/src/InMemoryLaunchDarklyClient.ts Implements resetTransaction() by undoing an active transaction.
packages/launch-darkly/src/LocalStorageLaunchDarklyClient.ts Implements resetTransaction() by undoing an active transaction.
packages/firefly-storybook/src/withFeatureFlagsOverrideDecorator.tsx Calls resetTransaction() before startTransaction() to avoid the remount race; guards cleanup.
.mcp.json Adds MCP server configuration for chrome-devtools.

Comment thread packages/firefly-storybook/src/withFeatureFlagsOverrideDecorator.tsx Outdated
Comment thread packages/launch-darkly/src/EditableLaunchDarklyClient.ts
Comment thread .mcp.json
@patricklafrance Patrick Lafrance (patricklafrance) merged commit d2a0d22 into main Apr 3, 2026
9 of 10 checks passed
@patricklafrance Patrick Lafrance (patricklafrance) deleted the fix/issue-571 branch April 3, 2026 03:06
@github-actions github-actions Bot mentioned this pull request Apr 3, 2026
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.

3 participants