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

fix(Responsive): use setState() safely #2421

Merged
merged 1 commit into from Jan 11, 2018
Merged

Conversation

layershifter
Copy link
Member

Problem

Responsive uses RAF for event handling and it means that setState() will be called after component will be unmounted.

Here is repro on codesandox, just resize preview area multiple times and you will see:

Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.

Please check the code for the Responsive component.

Solution

Use safeSetState in same manner as in the Transition component.


Based on SO question.

@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@08c207b). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2421   +/-   ##
=========================================
  Coverage          ?   99.73%           
=========================================
  Files             ?      154           
  Lines             ?     2692           
  Branches          ?        0           
=========================================
  Hits              ?     2685           
  Misses            ?        7           
  Partials          ?        0
Impacted Files Coverage Δ
src/addons/Responsive/Responsive.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 08c207b...273f64c. Read the comment docs.

@levithomason
Copy link
Member

We've had this in a few areas. Seems we might need to find a permanent solution. This works for now, thanks!

@levithomason levithomason merged commit 0cbcc3f into master Jan 11, 2018
@levithomason levithomason deleted the fix/responsive-setstate branch January 11, 2018 00:59
@levithomason
Copy link
Member

Released in semantic-ui-react@v0.78.0.

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

Successfully merging this pull request may close these issues.

None yet

3 participants