Fix edge cases for /* @once */ static marker
#438
Merged
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.
Fixes a couple of edge cases when using
/* @once */:@oncenow works in nested objects,<div style={/* @once */ { width: props.width, height: props.height }} />- Problem was that when the@onceexpression was found, it was removed, so any nested object became dynamic again.<div style={/* @once */prop.style}/>- problem was thatclassListand style were hardcoded to be dynamic, not respecting the@oncemark.<div { /* @once */ ... props}/>but only top level - this was just never considered.A note about spreads, consider the following:
What should happen is that
propsSpreadandcolor()fordata-staticshould be static.If we look at the generated code, it becomes more evident that the issue is
mergePropsrather thanspread, as spread has no option but to add the effect for the props that are actually dynamic.As a compromise, the spread value is now spreaded (when used with
@once), meaning thatmergePropswon't track the top level of the object. If access happens in any sub-objects then it will track. This solution is simple enough and possibly covers the immediate expectation.Related:
/* @once */seems to work only for first child of object #252