Skip to content

Conversation

@DeaMariaLeon
Copy link
Member

@DeaMariaLeon DeaMariaLeon commented Dec 4, 2025

Reference Issues/PRs

#32834

What does this implement/fix? Explain your changes.

Maybe the template/substitution can be avoided.
The css doesn't change for each estimator, so why do we need a dynamic selector?

Edit: Removed #$id to estimator.css to avoid the dynamic behaviour. Added a selector called css-selector instead.
On estimator.py I'm adding a class with the same name - css-selector.
That way we don't need to substitute the id number, that I believe it's not needed.
Worked locally with vscode and jupyter notebook.

AI usage disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Any other comments?

@DeaMariaLeon DeaMariaLeon marked this pull request as ready for review December 4, 2025 15:24
@DeaMariaLeon DeaMariaLeon changed the title Poc for improvement of HTML Display Remove CSS template substitution in estimators' HTML Display Dec 5, 2025
@glemaitre
Copy link
Member

I recall @rouk1 complained about the way we were doing our CSS there. Was it this way you thought it would be better done?

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From memory, I had the $id because I did not know how dynamic the CSS would be in the future. For example, lets say we had a CSS very specific to a particular estimator, then the id prevents that CSS from impacting all the other estimators.

From looking at the code now, I do not think thats the case, so I'm okay with a global selector.

(An interesting follow is to only write the CSS on the first repr call that is also in Jupyter, so it does not get copied over and over again.)

@@ -1,4 +1,4 @@
#$id {
.css-selector {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be prefixed with sk, i.e. .sk-css-selector? There is the edge case where another library may add CSS to the page with the same name and override our selector.

@glemaitre
Copy link
Member

From memory, I had the $id because I did not know how dynamic the CSS would be in the future. For example, lets say we had a CSS very specific to a particular estimator, then the id prevents that CSS from impacting all the other estimators.

In this case, I think that we should do something similar to skrub by having a shadow DOM. We already have some side-effect depending on the IDE like jupyter or vs code that define some CSS variable that alter the behaviour of the estimator. Having the CSS scoped to each estimator seems to be something desirable.

@DeaMariaLeon
Copy link
Member Author

(An interesting follow is to only write the CSS on the first repr call that is also in Jupyter, so it does not get copied over and over again.)

@thomasjpfan It would be great, that's what I wanted to do here*: RFC: Potential improvement of HTML Display's css logic. But Olivier thought that it wasn't possible. Moreover, Guillaume prefers to aim for the shadow DOM.

*Just sharing for background.

@rouk1
Copy link
Contributor

rouk1 commented Dec 15, 2025

I recall @rouk1 complained about the way we were doing our CSS there. Was it this way you thought it would be better done?

Using a class is fine, as stated above the only edge case is if something uses the same class name. So I advise to use something long and semantically consistent to avoid collision.

Using a shadow DOM cover this edge case but adds complexity that's a tradeoff...

Note: vscode uses iframe to render cell outputs so serializing only once the css code will lead to un-styled estimator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants