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

registerApolloClient is not a function when using RSC's with Storybook #307

Open
shawngustaw opened this issue Jun 3, 2024 · 4 comments

Comments

@shawngustaw
Copy link

I'm trying to upgrade from v0.5.* to latest, and noticed when I upgrade this package my storybook starts to have issues bundling things correctly. Anyone have any ideas how to fix this? The docs on using RSC's with storybook are here: https://storybook.js.org/blog/storybook-react-server-components/

@phryneas
Copy link
Member

phryneas commented Jun 3, 2024

We are following the server module convention of "react-server" conditional exports for code that is meant to run in RSC. (See https://github.com/reactjs/rfcs/blob/main/text/0227-server-module-conventions.md#react-server-conditional-exports )

That means that registerApolloClient is available only in certain environments, to prevent you from accidentally using it in Client Components, which would be a bug.

Unfortunately, if you are experiencing this with StoryBook, it seems that they are not adhering to those conventions - they would need to set the "react-server" condition when trying to import your code for RSC. I believe you'd have to bring that up with Storybook, I'm sorry :/

@phryneas
Copy link
Member

phryneas commented Jun 3, 2024

PS: I believe you should be able to manually set that as shown in

https://webpack.js.org/configuration/resolve/#resolveconditionnames

but that would probably set it for all your components and as a result break your Client Components.

It might be worth a try though - but in the end, this can only be solved on the StoryBook side.

@shawngustaw
Copy link
Author

Thanks for the quick response! and yeah, that makes sense. Seems like the storybook implementation of RSC's is fully client side (storybookjs/storybook#25091) so this might be an issue for everyone trying to use this lib with storybook. Will raise the issue with them and see if theres a path forward. Thanks again!

@phryneas
Copy link
Member

phryneas commented Jun 4, 2024

Thank you! Following the discussion over there :)

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

No branches or pull requests

2 participants