Skip to content
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

Update Trans.tsx to 'use client' #1899

Closed
wants to merge 1 commit into from
Closed

Conversation

mhfaust
Copy link

@mhfaust mhfaust commented Mar 29, 2024

This only works in client components anyway. Why not add 'use client' here so that it doesn't blow up when composed in server components?

Description

//: # The Trans component as is cannot be used directly in Server Components. If we make a wrapper for it, then it ruins extraction for the instances that use the wrapper. I believe this would solve that issue. It appears that the eventual solution for an RSC version would involve an alternate version of the component that is swapped in via a compile time plugin, so we may as well go with the fact that this specific component will be exlcusive to the client side, and mark it as such ('use client') so that it integrates with RSCs better.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Examples update

Fixes # (issue)

Checklist

  • I have read the CONTRIBUTING and CODE_OF_CONDUCT docs
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

This only works in client components anyway. Why not add 'use client' here so that it doesn't blow up when composed in server components?
Copy link

vercel bot commented Mar 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
js-lingui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 29, 2024 10:32pm

Copy link

size-limit report 📦

Path Size
./packages/core/dist/index.mjs 2.86 KB (0%)
./packages/detect-locale/dist/index.mjs 723 B (0%)
./packages/react/dist/index.mjs 1.67 KB (0%)
./packages/remote-loader/dist/index.mjs 7.26 KB (0%)

@mhfaust mhfaust marked this pull request as draft March 29, 2024 23:43
@fromthemills
Copy link

fromthemills commented Mar 30, 2024

Thank you for this! We should also add "use client" to the I18nProvider as it is also considered a client component.

@timofei-iatsenko
Copy link
Collaborator

So the thing is, NexJS team doesn't provide library authors with a clear guideline how to incorporate this "use client" in the usual library building pipeline.

The problem is, code of the library transpiled and bundled into one file, so this "use client" will not appear at the top of the module, and will not work as you are expecting.

@fromthemills
Copy link

Yes this a thing... bundler support for "use client" is subpar for now. In the Nextjs docs they talk about it and have some examples of how to do it with esbuild I think.

@timofei-iatsenko
Copy link
Collaborator

Well, it seems the "proposed way" is to just turn the whole bundle into "use client". Since we have a separate entrypoint for TransNoContext that may work...

@andrii-bodnar
Copy link
Contributor

Closed in favor of #1902

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.

4 participants