w3ctag / design-principles

A small-but-growing set of design principles collected by the TAG while reviewing specifications
https://w3ctag.github.io/design-principles
174 stars 46 forks source link

New principle: CSS and HTML syntax should be side effect free #336

Open LeaVerou opened 3 years ago

LeaVerou commented 3 years ago

This was brought up in our design review of contain-intrinsic-size: auto.

While the design principle of CSS we were referring to seems obvious, it's still nowhere to be found in our design principles.

annevk commented 3 years ago

Note that depending on how you phrase this, it would outlaw <script>, <style>, <iframe>, background-image, cursor, etc.

LeaVerou commented 2 years ago

@annevk This was brought up in one of our breakouts this week, and we are not sure we understand how it would outlaw <style>, background-image, or cursor, could you please elaborate? And would it outlaw <iframe> because it can contain scripts that access the parent, or a different reason?

annevk commented 2 years ago

All those features have side effects in that they can cause network fetches, or cause CSS to be applied to a document. (And yeah, iframe is essentially a more powerful version of script; it ends up creating its own execution environment.)

LeaVerou commented 2 years ago

Yes, but the CSS applied to the document only as long as the CSS code is actually present in <style>, not after, therefore it is not a side effect. Same for any network fetches, minus any race conditions where e.g. the element that triggered the fetch gets removed right after the fetch was triggered. Am I missing something?

annevk commented 2 years ago

So it's not a side effect in your model if insert + remove is essentially a no-op?

I'm not sure how network fetches are similar? They seem like very much a side effect (and can cause their own side effects, such as setting cookies).

(style can also block subsequent script elements.)

LeaVerou commented 2 years ago

Yes, the design review that sparked this proposed a feature for CSS which would have violated the current implicit rule that rendered style is a function of the current state (and not past states that have stopped applying).

I do see your point however, and we should be careful in how this is phrased to allow for any side effects from network requests, otherwise anything sending network requests would be off-limits! Might even need to scope it to CSS explicitly, not sure.