Page MenuHomePhabricator

Use Codex experimental build in Minerva to allow codex components to appear in night mode
Closed, ResolvedPublic3 Estimated Story Points

Description

User Story

As a user, I want all codex components to appear in night mode so that I can have a consistent experience

Background

NOTE: This should upgrade Codex components to the night mode theme.

The design systems team provided an experimental build in T356542. This will allow us to simplify the code in Minerva - specifically how we map LESS variables to CSS variables. Note this task should be considered timeboxed, and if unexpected issues arise, we should repurpose this as a spike and create follow up tickets/tasks.

Roan created the following POC: https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1003571 / https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1003572/2

TODO

QA

Sign-off

  • Provide a note in the comments for DST documenting any work-arounds or feedback regarding the initial implementation of the experimental build.

QA Results - Beta

https://phabricator.wikimedia.org/T358059#9629018

QA Results - Prod

Related Objects

Event Timeline

Jdlrobson renamed this task from [placeholder] Use Codex experimental build to Use Codex experimental build in Minerva.Feb 20 2024, 11:03 PM
Jdlrobson added a project: MinervaNeue.
Jdlrobson updated the task description. (Show Details)
Jdlrobson triaged this task as Medium priority.Feb 20 2024, 11:03 PM
Jdlrobson raised the priority of this task from Medium to High.Feb 22 2024, 12:27 AM
Jdlrobson updated the task description. (Show Details)
ovasileva renamed this task from Use Codex experimental build in Minerva to Use Codex experimental build in Minerva to allow codex components to appear in night mode.Feb 22 2024, 10:15 AM
ovasileva updated the task description. (Show Details)

Our night mode implementation is evolving quickly. We've implemented two changes this week that will have an effect on how we integrate the Codex experimental build.

In Map color-based skin variables to CSS variables we've implemented a Less <-> CSS variable referencing strategy in the Minerva skin ie: @color-base: var(--color-base);. The Codex experimental build does this for us, yay! That should mean we get to delete all this.

Because of this approach, CSS variables now get propagated across the wikiverse (to core and extensions) giving us at least partial night theme support across extensions without having to actually modify them (largely thanks to @Volker_E 's work in implementing these variables everywhere 🎉). However, we still need to use an invert() strategy in some cases. When we do that, we want to make sure that the element we're inverting use the light-theme variables.

To accomplish that, in this patch we did this:

:root, 
.skin-invert {
--color-base: lightModeColor;
}

The Codex experimental build doesn't come with that .skin-invert class on the :root element (and I don't think it should).

So in order to add it to the :root block, we should use the Less extend() functionality on the .skin-invert selector like so:

Screenshot 2024-02-22 at 10.17.09 AM.png (574×2 px, 135 KB)

If you need Codex to produce the list of variables without them being wrapped in a :root {} block, we may be able to do that. I think we may need to do something like that anyway in the near future, since we plan to put the night mode color palette in the codex-design-tokens package and have Minerva import those values from there, rather than putting those values in Minerva itself.

ovasileva set the point value for this task to 3.Feb 22 2024, 6:26 PM

Change 1006985 had a related patch set uploaded (by Jdrewniak; author: Jdrewniak):

[mediawiki/skins/MinervaNeue@master] [WIP] Integrate experimental build of Codex design tokens

https://gerrit.wikimedia.org/r/1006985

Test wiki created on Patch demo by EGardner (WMF) using patch(es) linked to this task:
https://patchdemo.wmflabs.org/wikis/3ec0027625/w

Change 1006985 merged by jenkins-bot:

[mediawiki/skins/MinervaNeue@master] Integrate Codex experimental design token build

https://gerrit.wikimedia.org/r/1006985

Edtadros subscribed.

Test Result - Beta

Status: ✅ PASS
Environment: beta
OS: macOS Sonoma
Browser: Chrome
Device: MBA
Emulated Device:NA

Test Artifact(s):

QA Steps

✅ AC1: Make sure no visual regressions occur in Pixel.

screenshot 625.png (380×1 px, 58 KB)

✅ AC2: Check Special:Nearby - it should appear in a night-mode like theme https://en.m.wikipedia.beta.wmflabs.org/wiki/Special:Nearby?minervanightmode=1 - it should appear in a night-mode like theme
screenshot 626.png (842×389 px, 35 KB)

✅ AC3: Check RelatedArticles at the bottom of a page e.g. https://en.m.wikipedia.beta.wmflabs.org/wiki/Related_Articles_3?minervanightmode=1 - it should appear in a night-mode like theme
screenshot 627.png (842×389 px, 114 KB)

✅ AC4: Check the Echo overlay, (when clicking on notifications) it should appear in a night-mode like theme e.g https://en.m.wikipedia.beta.wmflabs.org/wiki/E._J._Scovell?minervanightmode=1#/notifications
note: the url in the task description omits the url parameter. I have updated it here
screenshot 628.png (842×389 px, 84 KB)

❓AC5: Check the bug described in T358407: https://en.m.wikipedia.beta.wmflabs.org/wiki/User_talk:Jdlrobson?minervanightmode=1 should have no color contrast issues
@Jdlrobson, This looks like there are some issues. Are there specific elements I'm concerned with and others I can ignore?
screenshot 629.png (1×1 px, 218 KB)

AC5

@Edtadros the bug only relates to errors in the dialog window. It can be found in the more menu - I can confirm it's a pass!

Screenshot 2024-03-05 at 8.49.28 AM.png (1×1 px, 235 KB)

Looks like the experimental Codex styles are working as intended.

There is one small issue with the CSS-only Select (dropdown) component where the little icon won't invert its color yet. We have T358703 to track it and there is a patch with a workaround solution up now.

I'm sure that you will notice other small issues with Codex (components not using the right tokens or the right tokens not being exposed in the first place). Just let us know and we can get fixes into an upcoming Codex release.

Test Result - Beta

Status: ✅ PASS
Environment: beta
OS: macOS Sonoma
Browser: Chrome
Device: MBA
Emulated Device:NA

Test Artifact(s):

QA Steps

✅ AC5: Check the bug described in T358407: https://en.m.wikipedia.beta.wmflabs.org/wiki/User_talk:Jdlrobson?minervanightmode=1 should have no color contrast issues
per https://phabricator.wikimedia.org/T358059#9602157 this only covers the dialog below. Note the contrast errors are not on the dialog.

screenshot 633.png (1×1 px, 273 KB)

As part of this ticket, I wanted to leave a comment documenting any edge-cases or workarounds I ran into with the initial implementation.

Implementation feedback

Using SkinCodexThemes in skin.json - It looks like adding the following lines in skin.json "SkinCodexThemes": {"minerva": "experimental"} loads the CSS variable aware version of Codex, but it doesn't load the CSS variables themselves. This actually works to our advantage since we need to explicitly import the experimental theme in order to modify the :root selector, but I'm just pointing out that it wasn't obvious to me until the very end of this implementation (when we realized the RelatedArticles extension didn't appear in night mode without it).

modifying the :root selector - As part of the night-mode feature, we're developing affordances for opting out of night-mode using css classes, i.e. .notheme and .skin-invert. We need to make sure these classes are always in day-mode and recieve the day-mode variables. To do this, we group these classes with the :root selector using the Less extend function: CSSCustomProperties.less#31:

.skin-invert:extend(:root), 
.notheme:extend(:root) {}

Producing the following output:

:root, 
.skin-invert, 
.notheme {...}

This works for us. I'm noting it since it depends on the Less :extend() feature, which is not commonly used.

Integration with the mediawiki.skins.variables system - The functionality of the experimental build that references Less variables to CSS variables: @color-base: var( --color-base ); is very valuable for us at a skin level because it lets us propagate the CSS variables to extension and core, thereby adding night-mode support, without even having to touch those repositories. To make this work however, we have to using the Less @import (reference) feature mediawiki.skin.variables.less#21 So that the CSS :root selector is not duplicated anytime someone uses @import mediawiki.skins.variables.less.

@import ( reference ) 'mediawiki.skin.codex-design-tokens/theme-wikimedia-ui-experimental.less';

That imports the variables and spreads them across the ecosystem, while omitting the CSS :root block. This works, but it's also an uncommon technique. It would be preferable if the CSS variables and the Less/CSS variable conversion were split into two separate files.

Adding custom CSS variables to the :root block - We discovered the need to add Minerva specific CSS variables for custom colors. We achieved this by doing the following. CSSCustomProperties.less

:root {
	--minerva-diff-addedline: @color-success;
	--minerva-diff-deletedline: @color-destructive;
	--box-shadow-color-drawer: rgba( 0, 0, 0, 0.35 );
}

this mix of CSS variables and Less variables looks a bit odd, and it's probably something we should reconsider in the future.

Silent failures with missing CSS custom properties - Not necessarily related to the Codex experimental build specifically, more so working with CSS custom properties in general. Before the Codex experimental build was released, we had converted all our Less variables into CSS custom properties in Minerva. This included some non-standard variables which I accidentally deleted when integrating the experimental build. This lead to some high-priority bugs in which link colors were black instead of blue because their colors were assigned to css variables that didn't exist, e.g: var( --link-color--visited ). CI passed on these patches, and I couldn't find any way to enforce the existence of CSS custom properties through StyleLint. If these were Less variables, they would have failed compilation and the errors would be obvious. I ended up writing a Gist that tests the CSS output with PostCSS for undefined CSS variables. This might not be specific to the Codex build, but it's something I'm still wary of moving forward with CSS custom properties. Maybe using the referenced Less variables instead is the way to avoid this?

Jdlrobson updated the task description. (Show Details)

Test Result - Prod

Status: ✅ PASS / ❓
Environment: enwiki
OS: macOS Sonoma
Browser: Chrome
Device: MBA
Emulated Device:NA

Test Artifact(s):

QA Steps

✅ AC1: Make sure no visual regressions occur in Pixel.
n/a for production
✅ AC2: Check Special:Nearby - it should appear in a night-mode like theme https://en.m.wikipedia.org/wiki/Special:Nearby?minervanightmode=1 - it should appear in a night-mode like theme

screenshot 705.png (931×431 px, 32 KB)

✅ AC3: Check RelatedArticles at the bottom of a page e.g. https://en.m.wikipedia.org/wiki/369_Washington_Street?minervanightmode=1 - it should appear in a night-mode like theme
screenshot 706.png (936×434 px, 76 KB)

✅ AC4: Check the Echo overlay, (when clicking on notifications) it should appear in a night-mode like theme e.g https://en.m.wikipedia.org/wiki/E._J._Scovell?minervanightmode=1#/notifications
screenshot 707.png (932×431 px, 112 KB)

❓AC5: Check the bug described in T358407: https://en.m.wikipedia.beta.wmflabs.org/wiki/User_talk:Jdlrobson?minervanightmode=1 should have no color contrast issues
@Jdlrobson, I am unable to see the Report menu item with any of my QTE users in production so I cannot verify this.

This comment was removed by Jdlrobson.

That's fine @Edtadros - this one can be skipped in production.

Integration with the mediawiki.skins.variables system - The functionality of the experimental build that references Less variables to CSS variables: @color-base: var( --color-base ); is very valuable for us at a skin level because it lets us propagate the CSS variables to extension and core, thereby adding night-mode support, without even having to touch those repositories. To make this work however, we have to using the Less @import (reference) feature mediawiki.skin.variables.less#21 So that the CSS :root selector is not duplicated anytime someone uses @import mediawiki.skins.variables.less.

@import ( reference ) 'mediawiki.skin.codex-design-tokens/theme-wikimedia-ui-experimental.less';

That imports the variables and spreads them across the ecosystem, while omitting the CSS :root block. This works, but it's also an uncommon technique. It would be preferable if the CSS variables and the Less/CSS variable conversion were split into two separate files.

I've filed T360577 for this.

Test wiki on Patch demo by EGardner (WMF) using patch(es) linked to this task was deleted:

https://patchdemo.wmflabs.org/wikis/3ec0027625/w/