Skip to content

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

@ewdicus

Description

@ewdicus

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions