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(build): only exports vanilla in React Server Component #2274

Closed
wants to merge 7 commits into from

Conversation

himself65
Copy link
Collaborator

@himself65 himself65 commented Nov 26, 2023

Related Issues or Discussions

Revert: #2245

Fixes: #2269

Summary

Only exports vanilla files in react server condition when importing jotai.

This behavior will be similar to swr(https://github.com/vercel/swr/blob/main/core/src/index.react-server.ts). Like they only exports few function when react server

Check List

  • yarn run prettier for formatting code and docs

Copy link

vercel bot commented Nov 26, 2023

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

Name Status Preview Comments Updated (UTC)
jotai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 27, 2023 0:07am

Copy link

codesandbox-ci bot commented Nov 26, 2023

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 142ba5b:

Sandbox Source
React Configuration
React TypeScript Configuration
React Browserify Configuration
React Snowpack Configuration
Next.js Configuration
Next.js with custom Babel config Configuration
React with custom Babel config Configuration

package.json Outdated
Comment on lines 48 to 71
"./react": {
"import": {
"types": "./esm/react.d.mts",
"react-server": "./esm/error.mjs",
"default": "./esm/react.mjs"
},
"default": {
"react-server": "./error.js",
"types": "./react.d.ts",
"default": "./react.js"
}
},
"./react/*": {
"import": {
"types": "./esm/*.d.mts",
"react-server": "./esm/error.mjs",
"default": "./esm/*.mjs"
},
"default": {
"types": "./*.d.ts",
"react-server": "./error.js",
"default": "./*.js"
}
},
Copy link
Collaborator Author

@himself65 himself65 Nov 26, 2023

Choose a reason for hiding this comment

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

I go through the code, and all react* files uses or useAtom which is not accepted in react server environment

@dai-shi
Copy link
Member

dai-shi commented Nov 26, 2023

While this might improve the RSC developer experience, I don't think it solves #2241.

At this point, I don't think adding react-server entry point to show an error is necessary. React should be showing errors anyway. Or, we can add client-only if we want an explicit error.

If we don't have a solution with 'use client', let's revert #2245.

@dai-shi dai-shi closed this Nov 26, 2023
@himself65
Copy link
Collaborator Author

While this might improve the RSC developer experience, I don't think it solves #2241.

At this point, I don't think adding react-server entry point to show an error is necessary. React should be showing errors anyway. Or, we can add client-only if we want an explicit error.

If we don't have a solution with 'use client', let's revert #2245.

revert would be better

@himself65
Copy link
Collaborator Author

himself65 commented Nov 26, 2023

There might be another approach. We have index.react-server.ts that only exports vanilla.ts.

This might help if people did import jotai but only used atom. Otherwise, they have to import jotai/vanilla, which might be a little complicated because I have to check all of the files, like when I transfer some demos to next.js that only uses atom

@himself65 himself65 reopened this Nov 27, 2023
@himself65
Copy link
Collaborator Author

himself65 commented Nov 27, 2023

I made some changes, reopening...

@himself65 himself65 changed the title build: fix bundler might cause error feat(build): only exports vanilla in React Server Component Nov 27, 2023
@dai-shi
Copy link
Member

dai-shi commented Nov 27, 2023

Unfortunately, it doesn't change my previous comment. I feel it's worse because it hides the error.

Otherwise, they have to import jotai/vanilla,

That's recommended. So, it's a doc issue.

@himself65 himself65 closed this Nov 27, 2023
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.

Vite 5 / Rollup 4 build warning in v2.6.0
2 participants