Skip to content

Conversation

@fcollonval
Copy link
Member

@fcollonval fcollonval commented Jun 22, 2024

References

Fixes #15320
Fixes #8652
Fixes #5867
Fixes #13493

It will also ease the integration of all or part of JupyterLab in third-party applications.

Code changes

Add a new class .jp-ThemedContainer to all DOM element requiring to be Jupyter styled
All global CSS rules are now scoped behind that new class

For reviewers, you should look for DOM element that are floating and not being attached within the shell to check everything is styled properly.

User-facing changes

None

Backwards-incompatible changes

Any extension that attach a DOM node outside the shell may loose part of its styling.
The fix is to add the new class jp-ThemedContainer [should be ok as body is tagged as themed container]

The theme now have scoped rule on tt, code, pre, samp and kbd tag. This increases the specificity of the selector and as it is applied later (due to the injection of the theme style sheet), it may impact the look and feel of those tags in extensions.
The fix is to add the new class .jp-ThemedContainer before the existing rule; e.g.

.jp-Inspector-content pre ➡️ .jp-ThemedContainer .jp-Inspector-content pre

@fcollonval fcollonval added enhancement tag:Design System CSS If a PR is editing any CSS files please add this tag for design team to review. labels Jun 22, 2024
@fcollonval fcollonval added this to the 4.3.0 milestone Jun 22, 2024
@jupyterlab-probot
Copy link

Thanks for making a pull request to jupyterlab!
To try out this branch on binder, follow this link: Binder

@fcollonval
Copy link
Member Author

cc @echarles

@fcollonval
Copy link
Member Author

To reduce friction with third party extensions, I could set the new class jp-ThemedContainer on the body element.

@fcollonval
Copy link
Member Author

bot please update galata snapshots

@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2024

Galata snapshots updated.

@fcollonval fcollonval marked this pull request as ready for review July 2, 2024 10:12
@fcollonval fcollonval requested a review from krassowski July 2, 2024 10:12
@krassowski krassowski changed the title Scope CSS rules to .jp-ThemedContainer class Scope CSS rules to a new .jp-ThemedContainer class Jul 3, 2024
Copy link
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

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

Just some comments and question on the migration guide.

Comment on lines +19 to +22
you should add the class ``jp-ThemedContainer`` to the DOM elements added outside the application shell.
- DOM elements ``code``, ``kbd``, ``pre``, ``samp`` and ``tt`` may have broken styles. To fix this,
prepend the class ``.jp-ThemedContainer`` to your rule; e.g.
``.jp-Inspector-content pre`` becomes ``.jp-ThemedContainer .jp-Inspector-content pre``
Copy link
Member

Choose a reason for hiding this comment

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

Is it still accurate after adding .jp-ThemedContainer to the body? Or does it only pertain custom shells?

Copy link
Member Author

@fcollonval fcollonval Jul 5, 2024

Choose a reason for hiding this comment

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

It is unfortunately for all cases because the scoping is changing the CSS selectivity of the rules that therefore may shadow previously applied rules. See for example in this PR, commits 943516a and 1b66679

fcollonval and others added 2 commits July 5, 2024 10:01
Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>
@fcollonval fcollonval force-pushed the fix/no-global-css branch from 49b30b4 to bb3b220 Compare July 8, 2024 10:00
@fcollonval fcollonval merged commit 8515c5e into jupyterlab:main Jul 8, 2024
@fcollonval fcollonval deleted the fix/no-global-css branch July 8, 2024 10:54
ImpSy pushed a commit to spotinst/jupyterlab that referenced this pull request Jan 7, 2025
* Scope CSS rules to .jp-ThemedContainer class

* Fix examples and some missed floating widgets

* Add migration note

* Add class jp-ThemedContainer on the JupyterLab application shell container

* Move the themed container in the template to limit contamination when reusing `JupyterLab`.

* Fix bug in notification status bar item

* Don't scope rule if it uses a jp class

* Fix pre/tt/code/samp/kbd specificity

* Reduce unneeded specificity as the rule already uses a jp class

* Update migration doc

* Fix CSS specificity for code tag in html

* Fix examples

* Fix cell example bg

* Update Playwright Snapshots

* Second attempt to fix cell bg

* Restore bg color for main too

* [skip ci] Improve doc wording

Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>

* Fix Markdown code block rendering

* Revert unwanted snapshot change

---------

Co-authored-by: Frédéric Collonval <fcollonval@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.