Re: [csswg-drafts] [css-pseudo-4] Identity of Element.pseudo() return value (#3607)

The CSS Working Group just discussed `CSS Pseudo Elements`.

<details><summary>The full IRC log of that discussion</summary>
&lt;fantasai> Topic: CSS Pseudo Elements<br>
&lt;fantasai> github: https://github.com/w3c/csswg-drafts/issues/3607<br>
&lt;fantasai> heycam: Last time we discussed this on a call, I was suggesting that the pseudo() function which returns a CSSPseudoElement object<br>
&lt;fantasai> heycam: should always return the same object regardless of what values content has<br>
&lt;fantasai> heycam: just so that we don't have to rely on what the current style state is to know when these objects should be dropped and recreated<br>
&lt;fantasai> heycam: It felt a little strange at the time<br>
&lt;fantasai> heycam: one thing that might argue against returning same object is if we have an API in the future that can create from script one of htese objects and insert it into the tree<br>
&lt;fantasai> heycam: Might be problematic to have stable objet identiy created for style, vs created from script<br>
&lt;fantasai> heycam: But that's similar to what we do for @font-face<br>
&lt;fantasai> TabAtkins: If you reparse the style sheet, we'll create new objects<br>
&lt;fantasai> myles: Actually, I spent a week of my time making that not true.<br>
&lt;fantasai> TabAtkins: Can you open an issue on not doing that?<br>
&lt;fantasai> myles: I originally wanted to do the thing you said<br>
&lt;fantasai> myles: was brought to my attention that it was very common in JS that authors would tack on properties to random objects<br>
&lt;fantasai> myles: so you can't just delete and recreate them<br>
&lt;fantasai> mstensho: For Blink implementation, we used to recreate the speudo-element internally when content changed, but we don't do that anymore<br>
&lt;fantasai> mstensho: when content property changes, we regenerate ... but the object stays the same<br>
&lt;mstensho> That's futhark speaking, not me<br>
&lt;fantasai> emilio: But you still regenerate when you switch content property to none and back again, right?<br>
&lt;fantasai> TabAtkins: If you turn content to none and then ask for the pseudo, you do return an object that you can return style on right?<br>
&lt;astearns> s/mstensho/futhark/<br>
&lt;fantasai> mstensho: Are you talking about the pseudo() method or gCS()<br>
&lt;fantasai> TabAtkins: pseudo<br>
&lt;fantasai> futhark: We don't implement it<br>
&lt;fantasai> emilio: Do we want to keep them lightweight objects or do we add .style?<br>
&lt;fantasai> emilio: If we add .style we need to keep the ? around anyway<br>
&lt;gregwhitworth> fantasai: currently we've dropped .style from the spec<br>
&lt;gregwhitworth> TabAtkins: wait, we dropped .style?<br>
&lt;fantasai> heycam: we kept .type and .element and it's an event target<br>
&lt;fantasai> TabAtkins: OK<br>
&lt;fantasai> emilio: If you add some stateful thing that we don't want to disappear randomly, then keeping object itself around is not a huge deal because you need to keep that info around<br>
&lt;fantasai> emilio: but if not, then recreating it would be better<br>
&lt;fantasai> TabAtkins: I think it should have .style<br>
&lt;fantasai> TabAtkins: later<br>
&lt;fantasai> TabAtkins: Because pseudos act like DOM elements, they fill a similar purpose<br>
&lt;fantasai> TabAtkins: Having object identity work it's nice<br>
&lt;fantasai> TabAtkins: Without that it's more annoying<br>
&lt;fantasai> TabAtkins: ...<br>
&lt;fantasai> TabAtkins: Myles's argument about FontFace objects suggests that they should stay around on these objects, too.<br>
&lt;fantasai> myles: I don't know how applicable that argument is to pseudos<br>
&lt;florian> q+<br>
&lt;fantasai> dbaron: I think one other comment about expandos is that CSSOM objects are historically one of the objects where expandos don't stay around<br>
&lt;fantasai> dbaron: They stay around in lots of places, but not in CSSOM objects<br>
&lt;fantasai> TabAtkins: Is it just font face objects that are conneted, or ??<br>
&lt;fantasai> q+<br>
&lt;fantasai> myles: Font face rules will change... I don't remember.<br>
&lt;florian> q-<br>
&lt;fantasai> florian: Another argument in favor of long-lived is if they're not, we need to specify in detail what their lifecycles are<br>
&lt;fantasai> florian: And if we don't we'll expose a lot of implementation details<br>
&lt;AmeliaBR> https://developer.mozilla.org/en-US/docs/Glossary/Expando "Expando properties are properties added to DOM nodes with JavaScript, where those properties are not part of the object's DOM specification"<br>
&lt;fantasai> florian: Do you regenerate on  content property changing form on estring to another? flipt o none and back? n a display : none subtree?<br>
&lt;fantasai> florian: etc.<br>
&lt;fantasai> TabAtkins: [soething about garbage collector]<br>
&lt;fantasai> TabAtkins: Need to be either long-lived or regenerated on every call<br>
&lt;fantasai> myles: Most important part is that right now it's undefiend when the CSS engine decides to reparse rules or recreate derived objects<br>
&lt;fantasai> myles: That's pretty important fo roptimization<br>
&lt;fantasai> myles: so tying JS-visible semantics to that schedule would be scary<br>
&lt;fantasai> myles: Instead we should define something more rigorous<br>
&lt;fantasai> dbaron: Why is your GC idea not viable?<br>
&lt;fantasai> TabAtkins: It allows you to detect when GC happens by seeing how long the expando survives<br>
&lt;fantasai> dbaron: traditional way around that is that the expando makes it not collectible<br>
&lt;fantasai> TabAtkins: OK. My idea was to just hold it as a weak ref<br>
&lt;fantasai> dbaron: I think your weak ref idea is workable if we make expandos make it not collectible.<br>
&lt;fantasai> myles: It's true in our engine also<br>
&lt;fantasai> TabAtkins: If that's the case, then all the exposed possibibitlities for GC are handled if expando force a strong reference<br>
&lt;florian> ScribeScribe: Florian<br>
&lt;xfq> ack fantasai<br>
&lt;florian> fantasai: one concern was about keeping around a lot of memory if you iterate the entire tree<br>
&lt;florian> fantasai: if the pseudo doesn't generate a box, you return null, but as soon as you generate a box you generate the object and keep it around<br>
&lt;fantasai> emilio: that's also incompatible with making that API work with stuff like selection<br>
&lt;fantasai> TabAtkins^: incompatible with .style<br>
&lt;fantasai> emilio: For ::first-line ::first-letter, fine, but won't work for some other stuff<br>
&lt;fantasai> TabAtkins: I think returning null is OK only for things that don't exist, like the name is invalid<br>
&lt;TabAtkins> s/[soething about garbage collector]/If we just make the element have a weak ref to its pseudo, then expandos let you observe GC.<br>
&lt;fantasai> fantasai: Shouldn't that throw an error?<br>
&lt;fantasai> TabAtkins: No<br>
&lt;fantasai> astearns: We already talked about that<br>
&lt;fantasai> florian: How long-lived is it?<br>
&lt;fantasai> heycam: So we always return the same object, and it's kinda like it's connected to the element you call it on<br>
&lt;fantasai> TabAtkins: You're allowed to drop the object if doing so is unobservable<br>
&lt;fantasai> TabAtkins: e.e.g if no expando, no references, can drop it and recreate it<br>
&lt;fantasai> TabAtkins: I guess you can't observe object identity without a reference<br>
&lt;fantasai> smfr: Same object in IDL?<br>
&lt;fantasai> TabAtkins: That's advisory in the IDL. Have to say in algorithm what happens<br>
&lt;fantasai> myles: Can we make another IDL attribute that means "for real"? :)<br>
&lt;smfr> [SameObject]<br>
&lt;fantasai> heycam: What it means for a particular API is not particularly clear, so need to sayin the prose what type of object and stuff.<br>
&lt;fantasai> heycam: It's a hint to the JS engine, that's all.<br>
&lt;fantasai> myles^: so it means nothing<br>
&lt;fantasai> florian: There's a hint to the spec reader that there's some prose somewhere that matters?<br>
&lt;fantasai> TabAtkins: yes<br>
&lt;fantasai> astearns: So afaict, the proposed resolution is that pseudo() will return the same object always<br>
&lt;TabAtkins> Proposed Resolution: pseudo() must always return the same object (up to observability)<br>
&lt;fantasai> astearns: and we will have text suggesting that htis can be GC if that is unobservable<br>
&lt;fantasai> astearns: Objections/concerns?<br>
&lt;TabAtkins> "same object" for a given element/pseudo pair<br>
&lt;fantasai> RESOLVE: pseudo() must always return the same object. Note that object can be GC'd if this is unobservable.<br>
</details>


-- 
GitHub Notification of comment by css-meeting-bot
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/3607#issuecomment-467136978 using your GitHub account

Received on Monday, 25 February 2019 19:01:11 UTC