[FSSDK-12471] provider fix#332
Open
junaed-optimizely wants to merge 1 commit intomasterfrom
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates OptimizelyProvider lifecycle behavior to be compatible with React 18+ StrictMode and to prevent a race where cached datafiles can cause hooks to remain stuck in a “loading / no-config” state.
Changes:
- Remove the unmount cleanup behavior that eagerly reset the provider store / disposed the user-context manager.
- Merge
onReady()handling andOPTIMIZELY_CONFIG_UPDATEsubscription into a single effect, with aconfigReceivedflag to avoid double refreshes. - Update provider unit tests to reflect the new unmount semantics.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/provider/OptimizelyProvider.tsx |
Consolidates readiness + config-update handling and removes the unmount reset/dispose cleanup that breaks StrictMode remount behavior. |
src/provider/OptimizelyProvider.spec.tsx |
Updates cleanup-related expectations/descriptions to align with the new unmount behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+249
to
253
| // Store state is preserved — on real unmount, the store is | ||
| // garbage collected with the component tree. Eagerly resetting | ||
| // breaks React 18+ StrictMode (effect cleanup destroys state | ||
| // that the render body set, and no re-render restores it). | ||
| expect(store.getState().error).toBeNull(); |
Comment on lines
+249
to
+252
| // Store state is preserved — on real unmount, the store is | ||
| // garbage collected with the component tree. Eagerly resetting | ||
| // breaks React 18+ StrictMode (effect cleanup destroys state | ||
| // that the render body set, and no re-render restores it). |
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.
Summary
StrictMode compatibility (React 18+):
In dev mode, StrictMode runs effect cleanup→remount without re-running the render body. The cleanup effect called store.reset() (clearing userContext to null) and UCM.dispose() (aborting in-flight async operations like ODP segment fetches). Since the Provider doesn't re-render after effect remount, nobody restores the state — hooks stay stuck in isLoading: true forever. On real unmount, the store is garbage collected with the component tree, so eager reset is unnecessary.
Cached datafile race condition:
When the datafile response is served from the browser HTTP cache, the polling config manager loads it before the effect subscribes its CONFIG_UPDATE listener. Since the config doesn't change after subscription, the notification is never re-emitted, and hooks never transition from hasConfig: false to true. onReady().then() acts as a fallback for this case; the configReceived flag prevents a double-refresh when both fire on a cold cache.
Test plan
Issues
FSSDK-12471