Skip to content

[Bug] mobx-react-lite observer not working due to a react bug #4608

@jzhan-canva

Description

@jzhan-canva

I have reported this bug to react. a tl;dr is in strict mode, sometime react calls unsubscribe then immediately subscribe on useSyncExternalStore without getting snapshot or re-render

What this means to mobx-react-lite is, the useObserver destroy reaction in unsubscribe, then creates new reaction in subscribe, and depending on re-render to track that reaction. This react behaviour breaks this cycle.

I suggest we add a if(__DEV__) {onStoreChange()} to the subscribe method, to ensure a re-render is scheduled

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions