Skip to content

useEffect is broken for React Native with JSC #14352

Closed
@bvaughn

Description

@bvaughn

As reported in open source (facebook/react-native/issues/21967), the useEffect hook is broken for React Native when using JavaScriptCore (which affects both iOS and Android).

This is because the setTimeout branch of scheduler specifies a 5000ms delay. This 5000ms is supposed to be the maximum expiration time, but in this fork it ends up being the minimum callback time (unless another state update forces us to sync-flush pending callbacks). Since useEffect is passive, this means React won't call it until after a few seconds have passed.

I assume we (React team) haven't noticed this because we're typically using the postMessage implementation, but with JavaScriptCore– React Native ends up using the setTimeout fork.

I think this was broken by commit 4d17c3f (PR #13740) which intentionally changed the delay under the (mistaken) assumption that it would only impact unit tests.

If we want to avoid using setTimeout for React Native, I think we'll need to add a scheduler implementation that does not require postMessage or MessageChannel, since JavaScript Core does not support either.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions