Skip to content

Conversation

@JoviDeCroock
Copy link
Member

@JoviDeCroock JoviDeCroock commented Nov 12, 2025

Resolves #768

This effectively addresses the "missing lifecycle" problem of React, when React suspends during mount it will discard any in progress work which means that the store won't be disposed and hence the subscriptions/... won't be discarded. We circumvent this by overriding the Signal _subscribe method, which sets up the subscriptions, to track all subscriptions for a store and only subscribe them when we are sure the component is fully mounted. This prevents us from subscribing on a work-in-progress state which will just be discarded.

Why do I think this is breaking? React already has a rule not to setState during render but we can't be sure everyone expects that, hence we are marking this as breaking. No synchronous work should be able to intervene during component rendering hence this forking of Signal.prototype._subscribe is safe as long as we ensure it's restored in the end.

Thanks to the finally cleaning up with store.f() we are sure this restoration happens correctly. In the manual unmamaged one we might have patterns where we don't which I am fine with due to this being a major bump.

TODO:

  • Add tests asserting that Signal.prototype._subscribe is restored to its initial form

@changeset-bot
Copy link

changeset-bot bot commented Nov 12, 2025

🦋 Changeset detected

Latest commit: 2f22abe

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

This PR includes changesets to release 2 packages
Name Type
@preact/signals-react Major
@preact/signals-react-transform 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

@netlify
Copy link

netlify bot commented Nov 12, 2025

Deploy Preview for preact-signals-demo ready!

Name Link
🔨 Latest commit 2f22abe
🔍 Latest deploy log https://app.netlify.com/projects/preact-signals-demo/deploys/6914dbe76af68500083dbe00
😎 Deploy Preview https://deploy-preview-794--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 project configuration.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 12, 2025

Size Change: +125 B (+0.12%)

Total Size: 106 kB

Filename Size Change
docs/dist/assets/client.********.js 46.3 kB +126 B (+0.27%)
docs/dist/react-********.js 241 B -1 B (-0.41%)
ℹ️ View Unchanged
Filename Size
docs/dist/assets/bench.********.js 1.59 kB
docs/dist/assets/devtools.********.js 1.03 kB
docs/dist/assets/index.********.js 7.04 kB
docs/dist/assets/jsxRuntime.module.********.js 297 B
docs/dist/assets/preact.module.********.js 4.72 kB
docs/dist/assets/signals-core.module.********.js 1.56 kB
docs/dist/assets/signals.module.********.js 2.56 kB
docs/dist/assets/style.********.css 1.27 kB
docs/dist/assets/style.********.js 21 B
docs/dist/basic-********.js 246 B
docs/dist/nesting-********.js 1.13 kB
packages/core/dist/signals-core.js 1.59 kB
packages/core/dist/signals-core.mjs 1.6 kB
packages/debug/dist/debug.js 3.64 kB
packages/debug/dist/debug.mjs 3.18 kB
packages/preact-transform/dist/signals-*********.js 1.3 kB
packages/preact-transform/dist/signals-transform.mjs 1.29 kB
packages/preact-transform/dist/signals-transform.umd.js 1.42 kB
packages/preact/dist/signals.js 1.71 kB
packages/preact/dist/signals.mjs 1.66 kB
packages/react-transform/dist/signals-*********.js 6.89 kB
packages/react-transform/dist/signals-transform.mjs 6.09 kB
packages/react-transform/dist/signals-transform.umd.js 7.01 kB
packages/react/dist/signals.js 188 B
packages/react/dist/signals.mjs 150 B

compressed-size-action

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.

Signals never unwatched when using hooks and suspenses

2 participants