Skip to content

Support signals without importing preact-hooks #718

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

JoviDeCroock
Copy link
Member

@JoviDeCroock JoviDeCroock commented Jul 5, 2025

Resolves #670

This is a proposal to allow us to leverage signals without the need for the Preact Hooks implementation, this should save about 1.2kb gzipped as we aren't pulling in all of the other hooks. The main thing that people might miss are useMemo/useCallback - in theory we could use useComputed for that with .value however now sure we want to encourage that.

We could export a version of useStoreValue for this?

Additionally, useRef is replaced with useSignalRef.

In the ecosystem we'll nee to add support for this in prefresh, which comes down to adding the new property in here

For consumers who leverage both signals and hooks this is a slight downgrade, however, the added bytes are minimal in signals so I would encourage catering to users who use one of both rather than both.

Thinking more about this, a lot of our ecosystem libraries like i.e. preact-iso do leverage signals so in that regards this would be just an addition in byte-size. Gotta think this through a bit more.

Copy link

changeset-bot bot commented Jul 5, 2025

⚠️ No Changeset found

Latest commit: b18697e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link

netlify bot commented Jul 5, 2025

Deploy Preview for preact-signals-demo ready!

Name Link
🔨 Latest commit b18697e
🔍 Latest deploy log https://app.netlify.com/projects/preact-signals-demo/deploys/6868de97436e00000854aee7
😎 Deploy Preview https://deploy-preview-718--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.

Copy link
Contributor

github-actions bot commented Jul 5, 2025

Size Change: +275 B (+0.31%)

Total Size: 87.9 kB

Filename Size Change
docs/dist/assets/index.********.js 838 B -255 B (-23.33%) 🎉
docs/dist/assets/signals-core.module.********.js 1.53 kB +4 B (+0.26%)
docs/dist/assets/signals.module.********.js 1.79 kB -251 B (-12.29%) 👏
docs/dist/demos-********.js 4.32 kB +4 B (+0.09%)
docs/dist/react-********.js 241 B +2 B (+0.84%)
packages/core/dist/signals-core.js 1.56 kB +3 B (+0.19%)
packages/core/dist/signals-core.mjs 1.57 kB +3 B (+0.19%)
packages/preact/dist/signals.js 1.95 kB +385 B (+24.54%) 🚨
packages/preact/dist/signals.mjs 1.91 kB +380 B (+24.77%) 🚨
ℹ️ View Unchanged
Filename Size
docs/dist/assets/bench.********.js 1.59 kB
docs/dist/assets/client.********.js 46.2 kB
docs/dist/assets/jsxRuntime.module.********.js 283 B
docs/dist/assets/preact.module.********.js 4.01 kB
docs/dist/assets/style.********.js 21 B
docs/dist/assets/style.********.css 1.24 kB
docs/dist/basic-********.js 243 B
docs/dist/nesting-********.js 1.13 kB
packages/react-transform/dist/signals-*********.js 5.93 kB
packages/react-transform/dist/signals-transform.mjs 5.12 kB
packages/react-transform/dist/signals-transform.umd.js 6.04 kB
packages/react/dist/signals.js 188 B
packages/react/dist/signals.mjs 150 B

compressed-size-action

@JoviDeCroock JoviDeCroock marked this pull request as draft July 5, 2025 08:47
@rschristian
Copy link
Member

Thinking more about this, a lot of our ecosystem libraries like i.e. preact-iso do leverage signals so in that regards this would be just an addition in byte-size.

I imagine you mean "...do leverage hooks..." (emphasis mine), but indeed.

I originally gave the feature request a thumbs up, but now that you've laid this out, I'm thinking you're right, this would just be a regression for most users. I suppose unbundled apps might get to drop an additional network request for preact/hooks but neither that nor -1.2kb is super interesting. Equally though, a slight increase in size shouldn't cause anyone problems either.

Biggest selling point might just be the purity of the implementation but even that's pretty moot.

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.

Feature request: a build of @preact/signals with no dependency on preact/hooks
2 participants