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

ThemeContext.Extend causing issue in production build with rollup and treeshake enabled #6602

Open
jbpenrath opened this issue Jan 26, 2023 · 5 comments
Labels
bug issue that does not match design or documentation and requires code changes to address

Comments

@jbpenrath
Copy link

Expected Behavior

I want to be able to use ThemeContext module into my React application based on Grommet then build it with vite/rollup for production with treeshaking enabled.

Actual Behavior

Currently, if I used <ThemeContext.Extend /> into my application then I build it for production with vite/rollup, I get the following error :

Error: Minified React error #130;
visit https://reactjs.org/docs/error-decoder.html?invariant=130&args[]=undefined&args[]= for the
full message or use the non-minified dev environment for full errors and additional helpful warnings.

Identified workarounds

  • Disable treeshaking from rollupOptions fix the problem but we do not have bundle size optimization that is really weird.
  • It appears that removing sideEffects property into grommet package.json file fix the issue 🤔

URL, screen shot, or Codepen exhibiting the issue

image

Steps to Reproduce

  1. Bootstrap an application with vite (npx create-vite)
  2. Install grommet (npm install grommet styled-components)
  3. Import ThemeContext module in your main module
  4. Wrap your <App /> within <ThemeContext.Extend>
  5. Build your application npm run build
  6. Run the preview of your application npm run preview
  7. Go to http://localhost:4173 then see your broken application 😢

Your Environment

  • Vite version: 4.0.0
  • Rollup version: 3.11.0
  • Grommet version: 2.29.1
  • Browser Name and version: Brave 1.47.171
  • Operating System and version (desktop or mobile): Mac OS 13.1
@floreks
Copy link

floreks commented Jan 26, 2023

Just hit this issue today in our project. Somehow importing ThemeContext from grommet/contexts instead of grommet worked for me. Might be a good way to temporarily fix that before it gets fixed upstream.

@jcfilben jcfilben added the bug issue that does not match design or documentation and requires code changes to address label Jan 27, 2023
@jcfilben jcfilben added this to Triage in Grommet/Design System Backlog via automation Jan 27, 2023
@ShimiSun
Copy link
Member

Hey! Our team is also running into a similar issue. We currently can't use Grommet's ThemeContext due to rollup. Please share your findings.

@ericsoderberghp
Copy link
Member

Hey! Our team is also running into a similar issue. We currently can't use Grommet's ThemeContext due to rollup. Please share your findings.

Is the suggested workaround: import { ThemeContext } from 'grommet/contexts' not working anymore?

@kariwhitcomb
Copy link

I just ran into this issue when building our app using vitejs. The workaround does still work. import { ThemeContext } from 'grommet/context'.

I played around and it also seems that if grommet's package.json was updated to include "./contexts/ThemeContext/ThemeContext.js" in the sideEffects, then importing just from grommet would work correctly.

@danielm-hpe
Copy link

danielm-hpe commented Mar 7, 2024

We also just encountered this issue after migrating our app from CRA to vitejs v4. We were not having any issues using CRA. The issue was only seen in prod builds.

The workaround does still work. import { ThemeContext } from 'grommet/context'

This workaround also worked for us

I think that #7122 is likely also related to this issue, even if they're not exact duplicates.

I see there was some past history here with #2669

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issue that does not match design or documentation and requires code changes to address
Projects
Development

No branches or pull requests

7 participants