blitz-js / babel-plugin-superjson-next

Automatically transform your Next.js Pages to use SuperJSON
MIT License
125 stars 15 forks source link

Support Next `/app` Server Components #139

Closed jokull closed 1 year ago

jokull commented 1 year ago

It would be cool if this plugin also patched the network boundary between server and client components in Next 13 /app. If it's already supported it should be added to the README. Happy to help out if you think this is a good idea!

Skn0tt commented 1 year ago

Hey @jokull, thanks for opening the issue! Could you elaborate on why you closed it again? 😅

jokull commented 1 year ago

I thought next-superjson-plugin superseded this package. But I might be wrong :)

Ran into an issue with it and opened a relevant issue for that.

Skn0tt commented 1 year ago

Nope, we'll keep on maintaining both until SWC plugins become stable :)

I'm not sure if it's possible to patch the network boundary between react client/server components. If you were to do this manually within your application's code, how would you approach that? Maybe we can try to replicate that in the Babel / SWC plugins.

jokull commented 1 year ago

"patch network boundary" is a terrible way to communicate what I was thinking. I just meant if this had a nice wrapper for Server Component > Client Component in /app.

orionmiz commented 1 year ago

@Skn0tt SWC Plugin has started supporting this feature. Sorry for the late feedback.

Here's a past issue used as RFC:

The point is that there's no way for the transpiler plugin to know which child component in a server component is the real client component. So I approached it using a method that allows users to insert data-superjson attribute into the child client component manually.

Example: Input / Output

Do you have any better ideas?

jokull commented 1 year ago

I love this approach, using it already. I'll let @Skn0tt close it or keep open if he wants to do it with babel.

Skn0tt commented 1 year ago

This sounds like non-trivial added complexity. I have the assumption (not sure if its' right) that users who're using React Server Components will also be using SWC, so adding this functionality to the babel plugin wouldn't add any massive value. I'll close this issue for now.

To anyone who reads this: If you need this feature, please put a comment below! That helps me gauge the need for this. If we find substantial need for this from users of this plugin, i'll reconsider :)