Replies: 1 comment
-
Oh yeah that pattern is not good 🤔 As soon as a tag changes React discards the entire tree downstream. Have you tried with statsig's own guide? https://docs.statsig.com/client/javascript-sdk/next-js/ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hi,
We are looking at using the Flags SDK with Statsig. The Statsig doc recommends to check out this example for a reference implementation on static pages.
Observed Behavior
For static pages, Statsig recommends using client bootstrapping. We've noticed that the current implementation of
StaticStatsigProvider
(link to example code) causes the entire application tree (passed as children) to unmount and then re-mount when the asynchronous data from the useBootstrap hook becomes available.This behavior is caused by the conditional rendering logic that inserts the
BootstrappedStatsigProvider
into the component tree only after the data has loaded, which fundamentally changes the tree structure and triggers a full re-mount from React.Here is the relevant code snippet from
statsig-provider.tsx
(link to example code)):The reason for the re-mount seems to be the change in the React component tree structure:
!data
): The tree isStatsigAppBootstrapContext.Provider
->children
.StatsigAppBootstrapContext.Provider
->BootstrappedStatsigProvider
->children
.This structural change causes React to discard the old tree and mount a new one, which can lead to undesirable side effects like loss of component state, re-running expensive
useEffect
hooks, and potential UI flashes.Note: in the example, the client components also mount/remount.
Our Use Case and Challenge
Our primary use case for Client Bootstrapping is for client-side analytics and event logging (e.g., logging exposures, clicks, impressions, etc.). We have static pages
Given this, the current behavior presents a challenge:
Questions
Thanks for your time and any guidance you can provide!
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions