Transparent observation using plugin #4537
Replies: 8 comments 6 replies
-
Looks cool! My only concern is that I’m using Next.js and server-side components, which might affect how these transforms work on the server side. I totally get the idea behind making Mobx observation transparent – the Babel/SWC plugin sounds like a neat way to streamline it. But I’m curious about how it handles SSR or if there are any potential gotchas in that context. Have you tested this setup with server-side rendering in Next.js, or do you think there could be issues? 😅 |
Beta Was this translation helpful? Give feedback.
-
@christianalfoni Hey, it looks awesome, thank you for the library! 👍 I have tried it on a pet project and it helped to eliminate all the
I have a few questions:
|
Beta Was this translation helpful? Give feedback.
-
Hi @kubk! Thanks for testing it and thanks for the input! I will add these improvements to the README as well 😄 👍
I'll put a note to update the docs and implement the exclusion of paths ASAP 👍 |
Beta Was this translation helpful? Give feedback.
-
This is pretty cool @christianalfoni! Feel free to add a link to the plugin in the MobX setup/installation docs and the observer docs as a community / non-official feature! (A lot of people have been asking for this over the years, but all earlier attempts tried to monkey patch React internals, which is too risky) |
Beta Was this translation helpful? Give feedback.
-
What happens if |
Beta Was this translation helpful? Give feedback.
-
Hi @christianalfoni, is the source code for |
Beta Was this translation helpful? Give feedback.
-
@codeBelt Jup! Here it is 😄 : https://github.com/christianalfoni/observing-components Let me know if you have any concerns! |
Beta Was this translation helpful? Give feedback.
-
@christianalfoni I love your plugin and everything worked fine using Vite and SWC until I received my new laptop with a Snapdragon CPU (ARM64). I didn't get any errors yet my components were no longer wrapped with "observer()". Switching to babel and everything worked again as expected. Could it be that your plugin and especially swc-plugin-observing-components is only compiled for win X86/64 and not ARM64 yet? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
So I work on other relatable state management solutions, but as part of that I built a project that enables Babel and SWC to transform components to be observers.
As the author of Mobx ones famously said: "Just put observers on all components" 😂
This package mobx-react-observer has a babel and SWC plugin which allows you to just consume Mobx in React, making observation transparent.
The project is running in production on a big project, removing 250 observers from the codebase.
What do we think about this? 😅
Beta Was this translation helpful? Give feedback.
All reactions