Code Monkey home page Code Monkey logo

Comments (5)

shilman avatar shilman commented on June 26, 2024

@kasperpeulen @valentinpalkovic @ndelangen can we get storybook to bundle react-server code into our browser bundles by default?

from storybook.

kasperpeulen avatar kasperpeulen commented on June 26, 2024

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

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.

shilman avatar shilman commented on June 26, 2024

@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.

kasperpeulen avatar kasperpeulen commented on June 26, 2024

@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.

shilman avatar shilman commented on June 26, 2024

Good call @kasperpeulen ! @shawngustaw is that a change you might be able to contribute?

from storybook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.