react-client icon indicating copy to clipboard operation
react-client copied to clipboard

Additional re-renders on any feature flag changes due to lastUpdate

Open ewdicus opened this issue 6 months ago • 7 comments

Hello!

We were previously using version 1.13.0 and updated to 2.1.0. We then started seeing re-renders for any feature flag changes. When diffing the context against a stored version, the only value that's changed is lastUpdate, but this is causing a total re-render because the context has changed.

This is how I'm inspecting the context:

const CustomSplitClient = ({ children }: Props) => {
  // Get a user ID
  const userId = useMemo(
    () => someFunction(),
  );

  const splitContext = useSplitClient({ splitKey: userId });
  const splitContextRef = useRef(splitContext);

  const contextValue = useMemo(() => {
    const newValue = JSON.stringify(splitContext);
    const previousValue = JSON.stringify(splitContextRef.current);
    if (newValue !== previousValue) {
      console.log("Context Changed");
      console.log('New Value-->\n', newValue, '\n<--');
      console.log('Previous Value-->\n', previousValue, '\n<--');
      splitContextRef.current = splitContext;
    }
    return splitContextRef.current;
  }, [splitContext]);

  return <SplitContext.Provider value={contextValue}>{children}</SplitContext.Provider>;
};

Happy to provide any other info that can help. Thank you!

ewdicus avatar Apr 14 '25 22:04 ewdicus