Skip to content

Detect and unwrap signal properties #424

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

Merged
merged 2 commits into from
Aug 8, 2025
Merged

Conversation

JoviDeCroock
Copy link
Member

Fixes #422

Copy link

changeset-bot bot commented Aug 6, 2025

🦋 Changeset detected

Latest commit: e7d241c

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

This PR includes changesets to release 1 package
Name Type
preact-render-to-string 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

src/index.js Outdated
Comment on lines 746 to 748
function isSignal(x) {
return x instanceof Signal;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should use duck-typing here like https://github.com/denoland/fresh/blob/e65643c482de9b5afee5d52af3ccc88941c35b5c/src/runtime/server/preact_hooks.tsx#L355-L362 . That way we can keep rts dependency free and don't have to keep it in sync with major @preact/signals version increases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might end up being a much larger perf hit in the critical path though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if x !== null && typeof x === "object" is more or less expensive than an instanceof check. I let you decide on that one.

Copy link
Member

@rschristian rschristian Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather avoid adding a dep for a singular instanceof check myself, and at least as of a few years ago, duck-typing with 1-2 properties usually outperformed instanceof in Chrome. No idea of what fully happens internally there, but naively, makes sense to me.

If you've measured it & it is a perf issue, fair enough of course. I'll have some time in a bit to check the benches (if you haven't already).

Edit: At least on my system, the check Marvin linked to above doesn't seem to perform any worse than instanceof. Ran the benches a few times and there wasn't any noticeable drop.

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@marvinhagemeister marvinhagemeister merged commit 4a8d4a0 into main Aug 8, 2025
1 check passed
@marvinhagemeister marvinhagemeister deleted the fix-signals-support branch August 8, 2025 12:21
@github-actions github-actions bot mentioned this pull request Aug 8, 2025
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.

Not working properly when using signals on "disabled" attribute
3 participants