Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix out-of-order effect error when suspending in React Native #570

Merged
merged 8 commits into from
Jun 12, 2024

Conversation

developit
Copy link
Member

I have not managed to reproduce this in tests, since it only seems to happen in React Native, and I believe only with Hermes. In this environment, layout effects are flushed after a microtask (or synchronously?), and rendering can be triggered synchronously from them (via setState/useSyncExternalStore/etc). This means the "close current tracking context" operation we schedule after a Promise tick doesn't happen before the next render begins, which can cause an unmanaged useSignals() call to be left "open".

I've added a useLayoutEffect() to unmanaged useSignals() to address this, which just works by closing any open tracking context when React finishes the current render (as defined by the time at which React begins to execute effects).

As part of this, I also had to tweak store.f() to ignore repeated calls, as doing so could also trigger the "Out-of-order effect" exception (endEffect() does not guard against this internally as its only possible to trigger when reaching into the guts of signals-core as we do in the integration libraries).

@developit developit requested a review from andrewiggins June 12, 2024 02:49
Copy link

changeset-bot bot commented Jun 12, 2024

🦋 Changeset detected

Latest commit: 6d049c1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@preact/signals-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Jun 12, 2024

Deploy Preview for preact-signals-demo ready!

Name Link
🔨 Latest commit 6d049c1
🔍 Latest deploy log https://app.netlify.com/sites/preact-signals-demo/deploys/66699fc248c0350008d15616
😎 Deploy Preview https://deploy-preview-570--preact-signals-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Jun 12, 2024

Size Change: +30 B (+0.04%)

Total Size: 80.5 kB

Filename Size Change
docs/dist/assets/client.********.js 46.3 kB +28 B (+0.06%)
docs/dist/nesting-********.js 1.13 kB +1 B (+0.09%)
docs/dist/react-********.js 242 B +1 B (+0.41%)
ℹ️ View Unchanged
Filename Size
docs/dist/assets/index.********.js 838 B
docs/dist/assets/jsxRuntime.module.********.js 284 B
docs/dist/assets/preact.module.********.js 4.03 kB
docs/dist/assets/signals-core.module.********.js 1.4 kB
docs/dist/assets/signals.module.********.js 2.02 kB
docs/dist/assets/style.********.js 21 B
docs/dist/assets/style.********.css 1.21 kB
docs/dist/basic-********.js 244 B
docs/dist/demos-********.js 3.41 kB
packages/core/dist/signals-core.js 1.45 kB
packages/core/dist/signals-core.mjs 1.47 kB
packages/preact/dist/signals.js 1.27 kB
packages/preact/dist/signals.mjs 1.22 kB
packages/react-transform/dist/signals-*********.js 4.74 kB
packages/react-transform/dist/signals-transform.mjs 4 kB
packages/react-transform/dist/signals-transform.umd.js 4.86 kB
packages/react/dist/signals.js 188 B
packages/react/dist/signals.mjs 150 B

compressed-size-action

@developit developit merged commit 879ebe2 into main Jun 12, 2024
6 checks passed
@developit developit deleted the fix/react-unmanaged-out-of-order-effect branch June 12, 2024 13:20
@github-actions github-actions bot mentioned this pull request Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants