question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Un-mount and re-mount JssProvider

See original GitHub issue

Expected behavior: Expect dynamically generated style names and statically generated style names to be unique

Describe the bug: I have a component wrapped by a JssProvider and Theme provider eg.

const jss = createJss()
jss.use(global(), nested(), extend(), compose(), camelCase(), vendorPrefixer())

      <JssProvider classNamePrefix={this.props.classNamePrefix} jss={jss}>
        <ThemeProvider theme={this.props.theme}>
          {this.props.children}
        </ThemeProvider>
      </JssProvider>

When I unmount this component and re-mount this component, any dynamically generated styles in the child components now have style names that clash with the original statically generated styles.

Codesandbox link: Only happens in production. Will try to write an example soon

Versions:

  • jss: “jss”: “^9.8.1”, “jss-camel-case”: “^6.1.0”, “jss-compose”: “^5.0.0”, “jss-global”: “^3.0.0”, “jss-nested”: “^6.0.1”, “jss-vendor-prefixer”: “^8.0.1”,
  • Browser [e.g. chrome, safari]: latest Chrome (Version 70.0.3538.77 (Official Build) (64-bit) ), latest Firefox (63.0 (64-bit))
  • OS [e.g. Windows, macOS]: Ubuntu 18.10

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:20 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
kofcommented, Jan 23, 2019

Do we have a test that makes sure this keeps working?

1reaction
scaredcatcommented, Jan 23, 2019

It seems v10 of react-jss has the issue fixed regardless of whether re-using generateId or not: Previously with v8 the static ID generator was re-used but the dynamic style Id started from scratch…

v8

First mount screenshot from 2019-01-23 11-41-29 Remount screenshot from 2019-01-23 11-41-44 Notice how the dynamic style classes have an ID generated that clash with the static styles on the re-mount. At this stage I’m not sure what was the cause of this, or why the same IDs for static styles were used.

v10

First mount screenshot from 2019-01-23 11-40-14 Remount screenshot from 2019-01-23 11-40-28 In v10 regardless of whether generateId was passed in as a prop, it seems to keep around the pointer to the generator used when re-mounting and increment both the static and dymanic style IDs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React unmount and remount child component - Stack Overflow
For example, is there a way for me to unmount and mount again a child component based on the parent component's "componentWillReceiveProps"?
Read more >
Using React's Key Attribute to remount a Component - Nik Graf
First we checkout how React's key can be used, then walk through a real world scenario and finally discuss if we should use...
Read more >
JSS integration with React
... Sheets are created when a component mounts and removed when it's unmounted. ... 'react-dom' import {JssProvider} from 'react-jss' import MyApp from '....
Read more >
Solve React 18 mount, unmount, remount in Strict Mode
React 18 introduced a breaking change. In Strict Mode, all components mount and unmount. solve this by using a useEffectOnce hook as workaround....
Read more >
Avoid unnecessary remounting of DOM elements in React
Log to the console when it's mounted and unmounted from the DOM. class ... I expected React to not unmount and then remount...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found