Page MenuHomePhabricator

Font modes: Remove Less calculations involving font-size and line-height tokens from downstream projects
Closed, ResolvedPublic2 Estimated Story Points

Description

Overview

The proposed font modes feature for Codex (see T387778) would update some existing token values for font-size and line-height tokens to reference CSS variables (similar to how we handle color modes).

Before that work can be released, we need to ensure that any code downstream (in MW Core, skins, extensions, etc) which uses font-size or line-height tokes in Less calculations must be updated to be compatible with CSS variables. If this is not done, Less compilation will fail and styles will break in a very visible way.

@AnneT discovered this issue when she deployed a patchdemo instance based on the main patch These errors are due to calculations that use Codex tokens that previously had rem or em units and now reference CSS variables (since all font-size tokens now do so, e.g. @font-size-medium: var( --font-size-medium, 1rem )).


Impacted projects

Below is a list of references to Codex design tokens (found via Codesearch) that will need to be updated before the font modes work can move forward.

CodeSearch example font-size
CodeSearch example line-height

Note: OOUI is not included in this list because it relies on a "frozen" set of Codex design tokens from v1.3.5. OOUI does not need to be updated in order for Codex font modes to be released, but OOUI widgets will not participate in font-mode switching.


Examples
Example 1: Less unit() calc to output relative em/rem sizes

From Vector:

Less_Exception_Compiler: Operation on an invalid type in variables.less on line 88, column 1
86| 
87| // Search
88| @max-width-search: unit( ( 500px / @font-size-browser / @font-size-small ), em ); // 35.71428571em @ 16 & 0.875em T270202

Note that @font-size-browser = 16. The Codex token @font-size-small used to be 0.875rem and is being updated to var( --font-size-small, 0.875rem ). This is happening because you can't use CSS variables inside most Less functions, like unit().

Example 2: Less combinatory calculations to be explicit where output is from

From Extension:Popups:

Less_Exception_Compiler: Operation on an invalid type in settingsDialog.less on line 24, column 4
22| 		> div {
23| 			display: table-cell;
24| 			width: @size-icon-medium + ( 2 * @width-icon-gutter );
25| 			vertical-align: middle;
26| 			cursor: pointer;
27| 		}

Note that @width-icon-gutter = 1em. The Codex token @size-icon-medium used to be 1.25rem and is being updated to @font-size-x-large which is var( --font-size-x-large, 1.25rem ). This is happening because you can't do operations like addition on CSS variables without using calc().


These are just two examples, but there are likely more (possibly many) depending on which page you're on and which extensions are enabled. Note that these issues are not specific to the MediaWiki Less.php compiler. This is similar to T357740.


Next steps

DST would like to go in now and fix the references listed above to no longer rely on Less calculation. This work will pave the way for a near-future Codex release that will include support for font-mode switching. We will rely on PatchDemo to test for visual parity after any changes.

  • For places where calculations are being done directly in Less, we will typically be able to replace this with use of CSS calc() – this will preserve any original styling but it will also work the same way when CSS variables are used.
  • For places where the Less unit() function is used, we will need to understand the specific intent and update accordingly. Many of these cases will actually be better served by the ability to rely on font-mode-aware CSS variables in the future. In the worst-case scenario, we may need to temporarily hard-code the current computed values, and then go back once font-modes land to write the styles in a CSS-var-aware way.

DST will coordinate with the Web team and other feature teams who manage impacted codebases. The new font modes feature will not be merged until this issue is addressed. If things prove more complicated for whatever reason, the font modes work may need to be delayed until such a time that we can fix these problems.

Event Timeline

CCiufo-WMF set the point value for this task to 2.EditedMar 17 2025, 9:46 PM

Defaulting to 2 points of investigation and discussion of available solutions.

A few instant notes before the engineering enclave meeting tmrw:

  • OOUI wouldn't be directly affected as it uses a statically set, outdated version of the Codex Design Tokens – v1.3.5.
  • The calculations in Vector should be clarified if these are in any ways relative in legacy and Vector 2022 or those styles are only used in one fixed size, then I'd propose to use static replacements of these few values for the time being until we can revisit these styles with font mode guidance and the Web team. As font tokens aren't used widely, I'd opt for amending them in such way now, that's easily tackled
  • Negation is simply worked around by calc( -1 * var( --font-size-x-small, 0.75rem ) ) for example
egardner renamed this task from Tokens that now reference CSS variables break calculations to Font modes: Remove Less calculations involving font-size and line-height tokens from downstream projects.Mar 18 2025, 6:55 PM
egardner updated the task description. (Show Details)

Change #1131030 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[mediawiki/skins/Vector@master] styles: Use `calc()` to enable use of CSS custom properties

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

Change #1129602 had a related patch set uploaded (by VolkerE; author: VolkerE):

[mediawiki/skins/Vector@master] styles: Harden design token usage in calculations by using `calc()`

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

Change #1131030 abandoned by VolkerE:

[mediawiki/skins/Vector@master] styles: Use `calc()` to enable use of CSS custom properties

Reason:

Merged into I11181d9f416

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

Change #1129918 had a related patch set uploaded (by VolkerE; author: VolkerE):

[mediawiki/skins/Vector@master] styles: Remove obsolete vars relying on problematic Less calculations

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

Change #1131790 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[mediawiki/extensions/Popups@master] styles: Use `calc()` with Codex token `@size-icon-medium`

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

Change #1131790 merged by jenkins-bot:

[mediawiki/extensions/Popups@master] styles: Use `calc()` with Codex token `@size-icon-medium`

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

CCiufo-WMF changed the task status from Open to In Progress.Mar 31 2025, 3:40 PM

Change #1129602 merged by jenkins-bot:

[mediawiki/skins/Vector@master] styles: Harden design token usage in calculations by using `calc()`

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

Change #1129918 merged by jenkins-bot:

[mediawiki/skins/Vector@master] styles: Remove obsolete vars relying on problematic Less calculations

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

With the updated CodeSearch results in, we can successfully resolve this.
There's been two small further discoveries, which were not falling under the task descriptions scope. Both small issues in MinervaNeue with patches provided by myself.