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

Toaster doesn't work with SSR/SSG #398

Open
jpeterson opened this issue Aug 13, 2020 · 5 comments
Open

Toaster doesn't work with SSR/SSG #398

jpeterson opened this issue Aug 13, 2020 · 5 comments
Labels

Comments

@jpeterson
Copy link
Member

Expected Behavior

The Toaster component should work the same in a SSR/SSG app as it does in a client-rendered app.

Current Behavior

./node_modules/react-toastify/dist/ReactToastify.css being imported causes the following error:

This error is documented here:
https://github.com/vercel/next.js/blob/master/errors/css-npm.md

Possible Solution

Steps to Reproduce (for bugs)

  1. Go to this sandbox: https://codesandbox.io/s/tender-panini-hhx11?file=/pages/index.js
  2. Note the use of ToastContainer
  3. Note the error in the console:
error - ./node_modules/react-toastify/dist/ReactToastify.css
Global CSS cannot be imported from within node_modules.
Read more: https://err.sh/next.js/css-npm
Location: node_modules/calcite-react/Toaster/Toaster.js

Context + Screenshots

image

Your Environment

@jpeterson jpeterson added the bug label Aug 13, 2020
@jpeterson
Copy link
Member Author

@codylawson do you have any thoughts on this?

It looks like react-toastify can be used with SSR, but there is currently no way to tell CR not to import the CSS file behind the scenes.

@codylawson
Copy link
Contributor

@jpeterson What's the preferred way for it to work? Import the css manually instead?

@jpeterson
Copy link
Member Author

@codylawson I'm not entirely sure of the best approach here, but based on this page, I feel like we need a way for users to take on the responsibility of importing the CSS.

I wonder if we could come up with a solution where passing a prop like <ToastContainer omitStyles /> to skip importing the CSS file?

I don't know if what we're doing now is an anti-pattern, but I don't want this to introduce a breaking change or make it harder to use for anyone not concerned with SSR/SSG.

@codylawson
Copy link
Contributor

Are there any babel/webpack plugins that take care of this? Not that we shouldn't handle it ourselves, just curious what options there are.

@jpeterson
Copy link
Member Author

This is no longer a problem with NextJS apps as of NextJS 9.5.4

announcement: https://nextjs.org/blog/next-10#importing-css-from-third-party-react-components
doc: https://nextjs.org/docs/basic-features/built-in-css-support#import-styles-from-node_modules

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

No branches or pull requests

2 participants