-
Notifications
You must be signed in to change notification settings - Fork 182
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
stable clip paths #1624
stable clip paths #1624
Conversation
d4192ad
to
4a6ef93
Compare
cbeeb32
to
3c1176a
Compare
d99190a
to
6f95488
Compare
This comment was marked as outdated.
This comment was marked as outdated.
9f1aedd
to
74ad1cc
Compare
This seems ready now. |
rebased |
src/style.js
Outdated
break; | ||
} | ||
case "sphere": { | ||
const clips = context.clips ?? (context.clips = new Map()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These probably shouldn’t be exposed publicly on the context. Maybe use a WeakMap keyed by the context instead of assigning to a new property on the context? (Also note that the Context
interface is publicly documented in context.d.ts
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there only at most two keys in the clip cache (frame
and projection
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently yes, these are the only keys; related: #1109
This was clearly over engineered. I don't think we even need a WeakMap, as we could just do a quick check through the DOM with querySelector; we just need to pass the type of clip (frame, sphere) in a class or in the id, then select against it e.g. with |
Why do you think that (going through the DOM) is simpler or faster than a WeakMap? |
Using the DOM feels simpler [information-wise], in the sense that we wouldn't need to track the association of type of clip and clipPath in parallel, as we could just look it up. (It's hard to remember what I had in mind a year ago, though — I think I was probably trying to change the output as little as possible.) But I'm happy with this version too. |
I don’t follow that the DOM is simpler. In the DOM approach, you have to use some (serializable) identifier in the DOM such as an id prefix ( |
The way I think about the WeakMap is that there’s a |
Makes sense; you're right that there is as much tracking in both cases, just differently. To be clear my comment about over engineering was about the original introduction of the parallel tracking with Map; I could have used a className instead, but indeed it would have been visible in the output. |
new description!
By using (and reusing) the same clip-path when two renders are clipped with the same shape, we get:
Tested manually against #1623. The only reason why I based this PR on #1623 originally is that this forms a good test case: demo); for the same reason, merging this will change the snapshots for the new tests added in #1623, but they are independent concerns.