Skip to content

The result of getServerSnapshot should be cached to avoid an infinite loop #10

Description

@intrepidsg

Hey, @nikgraf , thanks for the updated react connector! I was mucking around with useY in Next and got this error from useSyncExternalStore(_, _, getServerSnapshot). According to react docs it seems to stem from the mutability of the return data from that parameter.

(https://react.dev/reference/react/useSyncExternalStore#im-getting-an-error-the-result-of-getsnapshot-should-be-cached)

This can be avoided by bypassing SSR but I found that using

() => {
    const data = yData.toJSON();
    if (equalityDeep(prevDataRef.current, data)) {
        return prevDataRef.current;
    } else {
        prevDataRef.current = data;
        return prevDataRef.current;
    }
}

For both parameters was able to work with SSR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions