fix: Race condition in withFeatureFlagsOverrideDecorator#584
Merged
Conversation
…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 started reviewing on behalf of
Patrick Lafrance (patricklafrance)
April 3, 2026 02:46
View session
@squide/core
@squide/env-vars
@squide/fakes
@squide/firefly
@squide/firefly-module-federation
@squide/firefly-rsbuild-configs
@squide/firefly-storybook
@squide/firefly-webpack-configs
@squide/i18next
@squide/launch-darkly
@squide/msw
@squide/react-router
commit: |
There was a problem hiding this comment.
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()toEditableLaunchDarklyClientand implement it in the in-memory and local-storage clients. - Update
withFeatureFlagsOverrideDecoratorto callresetTransaction()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. |
…or.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…add regression tests
Alexandre Asselin (alexasselin008)
approved these changes
Apr 3, 2026
d2a0d22
into
main
9 of 10 checks passed
Merged
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.
Fix issue #571