Skip to content

CacheProvider not used in productionΒ #2902

@sarink

Description

@sarink

Current behavior:

We are using a custom cache and CacheProvider in our client-side rendered SPA so that <style> tags can be injected into the <head> (because the default implementation is to use insertRule).

In development mode, this works great, I see zillions of <style> tags in the head. However, when deploying to production, I see one empty style tag in the dom: <style data-emotion="css" data-s=""></style>. It's as if our CacheProvider is being completely ignored in production.

To reproduce:

const muiTheme = createTheme();

const cache = createCache({ key: 'css', container: document.head });

export const AppContainer: React.FC = () => (
    <CacheProvider value={cache}>
      <ThemeProvider theme={muiTheme}>
        <App/>
      </ThemeProvider>
    </CacheProvider>
);
  1. Do a build with NODE_ENV = "development", observe <style>t tags in the head
  2. Do a build wit NODE_ENV = "production", observe there are no <style> tags in the head

Expected behavior:

I expect the CacheProvider to work in production the same way it does in development

Environment information:

  • react version: 17.0.2
  • @emotion/react version: 11.9.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions