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

feat(react): introduce TransNoContext component for future RSC support #1738

Merged

Conversation

timofei-iatsenko
Copy link
Collaborator

Description

Small step towards RSC support, more context in this comment: #1698 (comment)

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

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 necessary documentation (if appropriate)

@vercel
Copy link

vercel bot commented Jul 31, 2023

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 Jul 31, 2023 10:36am

@github-actions
Copy link

github-actions bot commented Jul 31, 2023

size-limit report 📦

Path Size
./packages/core/dist/index.mjs 2.76 KB (0%)
./packages/detect-locale/dist/index.mjs 721 B (0%)
./packages/react/dist/index.mjs 1.62 KB (0%)
./packages/remote-loader/dist/index.mjs 7.24 KB (0%)

@timofei-iatsenko timofei-iatsenko changed the title feature(react): introduce TransNoContext component for future RSC support feat(react): introduce TransNoContext component for future RSC support Jul 31, 2023
@timofei-iatsenko timofei-iatsenko marked this pull request as ready for review July 31, 2023 10:34
const { i18n, defaultComponent } = useLingui()
const { render, component, id, message, formats } = props
const lingui = useLingui()
return React.createElement(TransNoContext, { ...props, lingui })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also spread ...lingui here?
It feels a little cleaner to pass the props directly rather than wrapping them 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a bit of mess with component and defaultComponent. It would look weird when they would be on the same level in props. I just wanted to save structure as it was in context.

return React.createElement(TransNoContext, { ...props, lingui })
}

export function TransNoContext(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very familiar with RSC yet.
Do we need a new component? Is this going to be part of the public api?

Can we distinguish RSC / client component at the useLingui level so that the current Trans works for both? I think a new component is fine, just wondering.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a new component? Is this going to be part of the public api?

Yes. Yes.

The new component might not be used directly, but as part of the nextjs integration. But because we could not predict all cases upfront it's better to make it as part of a public api. Having this, you can start directly using it in RSC and next app router without waiting for other changes to the lib or special integrations.

Can we distinguish RSC / client component at the useLingui level so that the current Trans works for both?

You don't have information is it executed in RSC or just SSR (client components) in runtime. Or i didn't find that.

The only way of detecting RSC i've found in the compile / webpack level. Which is not ideal. So some of the users may want to avoid compile time transformations and use NoContext version directly. For others we could create a nextjs plugin which would do a heavy lifting under the hood (see my explanation comment)

I'm opened for discussion / brainstorming how to support RSC better.

@andrii-bodnar andrii-bodnar merged commit 8c1c70c into lingui:main Aug 2, 2023
12 checks passed
@timofei-iatsenko timofei-iatsenko deleted the feature/trans-no-context branch August 2, 2023 13:55
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.

3 participants