Closed richardantao closed 1 year ago
In const { initialFlagState } = await getFlags({ context });
you are not passing the user
, so the flags in initialFlagState
are not evaluated for a user. When the initialFlagState then makes it to the client, useFlags
detects that it is being passed a user but that the initialFlagState
was not evaluated for a user. It then refetches which causes the flicker.
To fix it, you need to pass the user to getFlags({ context, user })
I also noticed you are importing from @happykit/flags/dist/client
and @happykit/flags/dist/context
. You should be able to remove the /dist
When the initialFlagState then makes it to the client, useFlags detects that it is being passed a user but that the initialFlagState was not evaluated for a user. It then refetches which causes the flicker.
Makes sense! Will close this issue.
I also noticed you are importing from
@happykit/flags/dist/client
and@happykit/flags/dist/context
. You should be able to remove the/dist
Thanks. That's the path Intellisense provided.
I am getting the
initialFlagState
insidegetServerSideProps
so thatuseFlags.initialState
is defined when the page mounts, as shown below.When I only provide
{ initialState: initialFlagState }
touseFlags
, there is no issue on the initial render, but when I provide{ initialState: initialFlagState, user }
touseFlags
, the boolean flagflags?.NOTE_UPLOAD
changes state, causing the button wrapped in the flag to flicker.user
should not change when the page mounts because it is fetched via SSR, but for some reason it looks like it causesuseFlags
to rerender, thereby causing the flicker.Any suggestions?