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
Support shared signals in Preact islands #4763
Conversation
🦋 Changeset detectedLatest commit: 8ecb0bc The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
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 |
@@ -35,7 +35,8 @@ | |||
"@babel/core": ">=7.0.0-0 <8.0.0", | |||
"@babel/plugin-transform-react-jsx": "^7.17.12", | |||
"babel-plugin-module-resolver": "^4.1.0", | |||
"preact-render-to-string": "^5.2.0" | |||
"preact-render-to-string": "^5.2.0", | |||
"@preact/signals": "1.0.3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a dep and not a peerDep so that it doesn't require users to use preact/signals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! Looks really cool, would love to think about this a bit more before pulling the trigger.
Do you know if anyone from the Preact team might want to vet this as well?
Sure, can pull some people in, what specific questions would you ask of them? Whether this is a good idea or something about implementation? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it and I'm convinced this is a great idea! Could be super useful. Definitely fine with getting this out and we can circle back if the Preact team has any feedback.
I'm not trying to rush this out or anything, happy to wait on it for a while to gather feedback. I'll ping @marvinhagemeister and @developit to see if they have any thoughts on the design. Basically the idea is to create signals in Astro components and then pass them into islands. On the client we recreate that by creating an id for each signal and then ensure that all islands get the same value.
|
@@ -1,3 +1,4 @@ | |||
// @ts-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Was the preact/debug
import erroring? If we're lacking type definitions we can easily PR that to preact
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, preact/debug
doesn't have types at the moment: https://unpkg.com/browse/preact@10.11.0/debug/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no, filed a PR. Next version will have typings for that: preactjs/preact#3732
Basically the idea is to create signals in Astro components and then pass them into islands. On the client we recreate that by creating an id for each signal and then ensure that all islands get the same value.
Yup, that's one of the exact use cases they were designed for. Since they're not bound to components it makes perfect sense to instantiate them outside of that and pass the signals to the islands directly.
Sounds good! You can hardly go wrong with the serialization approach. The little more tricky bit is probably restoring the state graph on the client. It's something we had in mind when building signals, but didn't have the time to explore yet. That said it should be rather straightforward for as long as you can identify each signal.
Good point. I think you made the best choice for Astro. Much easier when folks don't have to worry about Really excited about the things you're doing here! That's awesome stuff 👍 |
5f5465e
to
1915f23
Compare
@marvinhagemeister we had to revert this for the time being due to preactjs/signals#197. Will release this another day though. |
preactjs/signals#197 is fixed, could we get this back pretty please?! 😄 Thank you for your work on astro @matthewp! |
Thanks for the reminder @merlindru, do you want to submit a PR that reverts #4843 and updates the library version? If not I'll get around to it eventually. |
Changes
Testing
Docs
N/A