Comments (5)
@kasperpeulen @valentinpalkovic @ndelangen can we get storybook to bundle react-server
code into our browser bundles by default?
from storybook.
Thanks for the detailed issue! @shawngustaw
For now I can recommend the following work-around:
// main.ts
webpackFinal: (config) => {
config.resolve?.conditionNames?.unshift('react-server')
config.resolve!.alias = {
...config.resolve?.alias,
'client-only': false
}
return config;
}
![image](https://private-user-images.githubusercontent.com/1035299/337202487-68320fe5-c4c2-420a-8dec-a544736f6de1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk0MDczNjksIm5iZiI6MTcxOTQwNzA2OSwicGF0aCI6Ii8xMDM1Mjk5LzMzNzIwMjQ4Ny02ODMyMGZlNS1jNGMyLTQyMGEtOGRlYy1hNTQ0NzM2ZjZkZTEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjZUMTMwNDI5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NDM2NTc0MDNjN2Y0ZTAwMzlmOWUzNDY4YmEwZTkzMDZlZDM0MzI1Y2M3Y2QwNTUwNmQ3MjIxYzY4ZTI4NjkyMiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.xnlEK7LDeILkzb0-ibA5BQgxqWjQdU4BkRizLYL1t-A)
I'm going to investigate how to best solve this in general.
It is kind of tricky. In storybook, we do run the async RSC components as async client components.
And we recommend people to use module mocking to avoid running node specific code in the browser.
This is our RSC demo that uses an in-memory database in storybook:
https://github.com/storybookjs/storybook-rsc-demo/blob/6cca874e7736d70d36d770b42dfc6ccf98ce125a/package.json#L12-L15
Running both the server and client stuff in one environment (the browser) has a lot of advantages as it comes to a true unit-testing experience. It is super fast, and you can both set a server mock, spy on a function and access a dom element in the same unit/component test:
https://github.com/storybookjs/storybook-rsc-demo/blob/main/app/note/edit/page.stories.tsx
My feeling is that the best thing we can do, is trick the bundler, to think of storybook as both a react-server and a react-client in the same time, which is what the above tries to achieve.
from storybook.
@kasperpeulen Thanks so much for tracking that down. If we can't safely apply this configuration automatically by default, at least we can add that configuration (and its Vite equivalent) prominently in our RSC docs once that's a thing. cc @kylegach
from storybook.
@shilman After thinking a bit more about it. Maybe we should just do add it to the nextjs framework by default when experimentalRSC: true
is set to the 8.2 alpha release. And see what it breaks.
I can imagine that in theory this does unwanted stuff, for example, when a library exports both a RSC and client variant of the same component. I only don't know if this is really what the ecosystem is gonna do, or that this is just an imaginary example.
In this worst case scenario, I think we should recommend people to have 2 storybooks. One that is for RSC components, and one for client only components.
from storybook.
Good call @kasperpeulen ! @shawngustaw is that a change you might be able to contribute?
from storybook.
Related Issues (20)
- [Bug]: Show missing `vite.config.js` file in migration notification while the `vite.config.ts` exists HOT 1
- [Bug]: Unable to Mock Modules in Storybook HOT 3
- [Bug]: a11y-addon - APCA Contrast check - Can't pass custom evaluate function to rule
- [Bug]: Package exports are not properly interpreted in a mono-repo setup
- [Bug]: Unable to add storybook to existing nextjs project HOT 1
- [Bug]: previewMainTemplate Option Ignored, Default Template Used Instead
- [Bug]: RollupError: "createRequire" is not exported by "__vite-browser-external" HOT 1
- [Bug]: Small visual bug in Controls UI loading state HOT 1
- [Bug]: tocbot dependency causing `ERR_REQUIRE_ESM` error on `next dev` and `next build` HOT 4
- [Documentation]: <Source> format prop incorrectly states it takes in BuiltInParserName
- [Bug]: theme not working in decorators HOT 1
- Upgrade to Node 20 in dev
- [Bug]: "useArgs" hook updates wrong story when rendered in "Stories" block
- [Bug]: Can't build storybook after setCustomElementsManifest
- [Bug]: Storybook angular custom source preview broken because of Prettier Angular praser is enforced
- [Bug]: Failed to resolve import
- [Bug]: StoryBook + NextJS based NPM is not working
- [Bug]: webpack-dev-middleware Error: ENOENT: no such file or directory on Windows
- [Bug]: Storybook7 corrupted unicode
- [Bug]: "Show code" doesn't render JSX anymore after updating to v8 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from storybook.