Skip to content

[css-pseudo-4] Should parent and element attributes of CSSPseudoElement interface be nullable? #12115

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

Open
danielsakhapov opened this issue Apr 24, 2025 · 5 comments

Comments

@danielsakhapov
Copy link
Contributor

https://drafts.csswg.org/css-pseudo-4/#CSSPseudoElement-interface has

readonly attribute Element element;
readonly attribute (Element or CSSPseudoElement) parent;

but, given the outcome of #3607, and e.g.

fc = div.firstChild;
div.removeChild(fc);
fc.parentElement; <-- is null.

I would expect the following to return null:

.beforePseudo::before { content: "before"; }

before = target.pseudo("::before");
div.classList.remove("beforePseudo");
before.parent; <-- should be null, since the pseudo is now ~"detached from DOM"?

So, I guess that parent and element attributes of CSSPseudoElement interface should be nullable?

@emilio @fantasai ?

@emilio
Copy link
Collaborator

emilio commented Apr 24, 2025

Maybe? I think ::before / ::after's relationship with the DOM is not super well defined. Implementation wise we do remove them, but I think per spec they're supposed to be always present?

@danielsakhapov
Copy link
Contributor Author

Would you expect it to behave the same as for the first child example?

@emilio
Copy link
Collaborator

emilio commented Apr 25, 2025

Not sure, I think we need to define whether changing / removing the content property removes the pseudo element or not. Same for display. Also same for elements that don't generate these like input elements. What does the spec say for those?

@emilio
Copy link
Collaborator

emilio commented Apr 25, 2025

The problem with your class list example is that it'd require .parent to synchronously run styling right? Which is a bit surprising at least, and a perf footgun

@danielsakhapov
Copy link
Contributor Author

Right, sorry, I forgot to mention that I didn't include synchronisation lines (like offsetTop) between actions, just to show the need for nullability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants