updateStyle(): Make it possible to update element styles for the same style object #3023
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses the case in #2915 where styles are not updated by the same style object.
Description
In this PR, if the old and new style objects are the same, clear the style and then re-set the properties. This is the same process as when updating from a null or string style to an object style.
Motivation and Context
This same style object case is taken into account in v1 and works fine (flems v1.1.7.)
mithril.js/render/render.js
Line 564 in 35ab329
In v2, however, the style updates were skipped completely for the same style object (flems v2.3.0.) It appears to have been omitted in the v2 changes (8134c51). This case has no note in the documentation and no warning like the same
attrs
.The case of reusing objects may not be preferable. However, I think this case works well and is better to fix than warnings or documentation.
In the performance context, skipping style updates would also be possible with string styles or class, which would be better for performance.
How Has This Been Tested?
npm run test
with additional testI also confirmed that the bundle file works fine with the above flems.
Types of changes
Checklist