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.

Invalid "Mutating `style` is deprecated." warning in 0.14.0-rc1?

See original GitHub issue

I get the following warning in 0.14.0-rc1:

Warning: div was passed a style object that has previously been mutated. Mutating style is deprecated. Consider cloning it beforehand. Check the render of Preview. Previous style: {“color”:“#747474”,“backgroundColor”:“#009988”,“fontSize”:null,“fontWeight”:“300”}. Mutated style: {“color”:“#747474”,“backgroundColor”:“#009988”,“fontSize”:null,“fontWeight”:“300”}.

I’m confused why this warning appears because the “Previous style” and the “Mutated style” look exactly the same.

To reproduce the issue:

$ git clone git@github.com:moroshko/accessible-colors.git
$ cd accessible-colors
$ git checkout 1d8efda7145ff316b78e60cc0f0ebe113da11367
$ npm install
$ npm start

Then open http://localhost:3000/dist/index.html in a browser, and:

  1. Type “1” in the font size field
  2. Blur that field Now you should see the warning in the console.

Why this warning is displayed? How could I fix it?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:24 (11 by maintainers)

github_iconTop GitHub Comments

7reactions
bradbytecommented, Feb 10, 2016

I ran into this issue while using Object.assign. I just set the target to be an empty object so there’s a new memory reference.

... style={Object.assign({}, styles.input, this.state.error ? {color: 'red'} : {}) ...
5reactions
rickhanloniicommented, Sep 14, 2016

@AoDev the first does not throw a warning because of this line:

const style = { ... };

That’s creating a new style object with a new memory reference, so you’re actually not passing a mutated object. In the second you’re passing store.style which is the same object with the same reference before and after mutation.

You can fix the second with:

<div style={Object.assign({}, store.style)} />

Be sure to do this with care though because of the performance implications (passing props like this to pure children will always force a render, removing the benefits of pure components).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why was mutating style deprecated? - reactjs - Stack Overflow
You can work around this problem by copying the the previous style into a new variable and copying the previous style object. Example:...
Read more >
SciPy 1.8.0 Release Notes — SciPy v1.9.3 Manual
NumericalInverseHermite has been deprecated from scipy.stats and moved to the ... #14140: Likely unnecessary invalid value warning from PchipInterpolator.
Read more >
Changelog and Migration Guide - Detekt
We deprecated the MultiRule class as it was overly complicated. The suggested approach is to just provide separated rules.
Read more >
Important notes — Borg - Deduplicating Archiver 1.2.3 ...
As they were considered invalid, borg discarded them. ... C / Cython compiler warnings, deprecation warnings; fix zstd.h include for bundled zstd, #6369....
Read more >
@material-ui/styles | Yarn - Package Manager
@material-ui/styles. owner mui-org7.1mMITdeprecated4.11.5TS vulns 0 vulnerabilities.
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