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: add "use client" to components that use client side only React APIs (support for RSC) #2874

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

tujoworker
Copy link
Member

@tujoworker tujoworker commented Nov 10, 2023

We have received several request to add a "use client" directive on top of each React component file that uses client side only React APIs.

The reason is because Next.js takes in use a beta version of React to make RSC work (which is not OK in my opinion – its a super aggressive move 😣).

To make a first move on this from our side, I think we should automate this. And one way to do so, is to use Babel.js – because we use it in our tool-chain.

There is already a very well written and tested plugin, written by Kyle Tsang I suggest to try out.

👉 babel-plugin-transform-next-use-client

This must be the first time we take in use a dependency with 0 GitHub stars. If it turns out to work as expected, we should all give it a star of course!

Other notes:

  • I have tested it locally and also added a post build test.
  • We skip rollup builds (UMD/ESM) bundles. But they are not uses in Next.js anyway.
  • Time will tell of we need to add more custom config.

Copy link

vercel bot commented Nov 10, 2023

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

Name Status Preview Comments Updated (UTC)
eufemia ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 10, 2023 8:56am

…APIs (support for RSC)

We have received several request to add a ["use client"](https://react.dev/reference/react/use-client) directive on top of each React component file that uses client side only React APIs.

The reason is because Next.js takes in use a beta version of React to make RSC work (which is not OK in my opinion – its a super aggressive move 😣).

To make a first move on this, I think we should automate this. And one way to do so, is to use Babel.js – because we use it in our tool-chain.

There is already a very well written and tested plugin, written by Kyle Tsang I suggest to try out.

👉 [babel-plugin-transform-next-use-client](https://github.com/kyletsang/babel-plugin-transform-next-use-client)

This must be the first time we take in use a dependency with 0 GitHub stars. If it turns out to work as expected, we should all give it a start of course.
Copy link
Contributor

@langz langz left a comment

Choose a reason for hiding this comment

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

Great, let's give it a go 👍
Better than adding these lines of code in all our components, etc.

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit b49a404:

Sandbox Source
eufemia-starter Configuration

@tujoworker tujoworker merged commit a84e962 into main Nov 10, 2023
7 checks passed
@tujoworker tujoworker deleted the feat/rsc-use-client branch November 10, 2023 10:18
tujoworker pushed a commit that referenced this pull request Nov 12, 2023
## [10.13.0](v10.12.0...v10.13.0) (2023-11-12)

### 🐛 Bug Fixes

* **Autocomplete:** ensure correct value selection during data change ([#2863](#2863)) ([d229ec2](d229ec2))
* **Autocomplete:** ensure on_change is firered during dataset update ([266ab6a](266ab6a))
* **PhoneNumber:** ensure correct selection of value ([#2852](#2852)) ([a20a764](a20a764))
* remove nullish operator to support Storybook v6 ([#2873](#2873)) ([f0bab63](f0bab63))
* typescript react type resolution in monorepos ([#2866](#2866)) ([44f04f3](44f04f3))

### ✨ Features

* **Accordion:** change sbanken expand icon to chevron ([#2854](#2854)) ([a7cb8b9](a7cb8b9))
* add "use client" to components that use client side only React APIs (support for RSC) ([#2874](#2874)) ([a84e962](a84e962))
* **Button:** change sbanken primary button text color to white ([#2855](#2855)) ([1571138](1571138))
* **Typography:** change sbanken bold to medium ([#2808](#2808)) ([4b0f930](4b0f930))

### 📝 Documentation

* **About:** add Snorre/Henrik/Ynge as contributors ([#2885](#2885)) ([fff72da](fff72da))
* **Autocomplete:** adds default value to keep_value props ([#2867](#2867)) ([7cae1fd](7cae1fd))
* fix font docs ([#2849](#2849)) ([13beec9](13beec9))
* **Ingress:** adds Ingress to docs ([#2879](#2879)) ([f771f3d](f771f3d))
* **Lead:** adds Lead to docs ([#2877](#2877)) ([0c0da7f](0c0da7f))
@tujoworker
Copy link
Member Author

🎉 This PR is included in version 10.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants