-
Notifications
You must be signed in to change notification settings - Fork 0
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
Next.js swc plugin not working for react hooks #184
Comments
Have you tried to use |
@XantreDev Alright I gave that a try and unfortunately, while it works to use that plugin option, I experience the exact same behavior with the buggy signals in the web app. So there is no difference in the runtime. |
My best guess would be that the plugin only addresses components, not hooks. We use signals a lot in custom hooks as well. Does that seem like it could be an underlying issue? |
Yep. The plugin transforms only components. But if you use option 'all' every component will be transformed any way |
I will try to implement hooks the transform, when I will have a free time. After this step my plugin can be moved to official repo |
So the |
Alright. It's a bit confusing because the official babel plugin doesn't clarify that it operates on hooks:
However when I use the babel plugin nearly all the signal usage appears to work which implies that it is maybe also operating on hooks as well as components 🤔. I suppose the 2nd heuristic implies they are looking at functions / components independently, though. |
It seems like docs is obsolete. I've read the implementation, it also adds useSignals to hooks |
You can check #187 version |
Thanks I’ll check it out first thing next week! |
Alright so with the latest updates on version Thanks for tackling that update—really appreciate it! |
I originally posted a comment here. I'll try to explain in more detail what I'm experiencing here. I really appreciate community work so up front I just want to say thanks for working on this stuff ❤️.
Basic info:
My understanding is the swc plugin in the safe react package is intended to have parity with the preact signals team official babel plugin. I've tested both, however we use swc and have no desire to switch back to babel—even for a short period of time. In my testing the babel plugin nearly works perfectly. The swc plugin works far less. To note there are no actual errors—just really buggy signal behavior which I believe stems from the plugin not wrapping everything up properly. Worth noting that your swc plugin does the best for me when I use the
all
mode but is still not sufficient.Currently all of our routes are still in the pages router since we cannot move anything over with this issue of the signals. For my use case here I'm looking at ~500ish typescript files in which I'd need to manually add
useSignals
to lacking a viable plugin to do it for me.I've tested across 3 scenarios: the babel plugin, your swc plugin and manually adding
useSignals
to necessary areas. So far the pattern that absolutely works is the manual pattern—when I test an area of the application and then manually adduseSignals
to the right spots I get full functionality as expected. The babel plugin is nearly perfect as an automated pattern but there are a few areas I'd need to address manually. The swc plugin is insufficient enough as an automated pattern that it's not worth using right now I don't think.I am not sure exactly what differs between your swc plugin and the babel plugin but I definitely don't experience full parity in real world testing on a complex next application. A viable swc plugin is ideal at this stage so I'm just wondering if there's any possibility in debugging what is going wrong here 🤷♂️
The text was updated successfully, but these errors were encountered: