Skip to content

Make optical size auto work: fix stale slider CSS, add an Auto toggle - #163

Open
MarkFonts wants to merge 4 commits into
arrowtype:mainfrom
MarkFonts:fix/stale-css-after-worker-restart
Open

MarkFonts wants to merge 4 commits into
arrowtype:mainfrom
MarkFonts:fix/stale-css-after-worker-restart

Conversation

@MarkFonts

@MarkFonts MarkFonts commented Oct 13, 2026 •

Copy link
Copy Markdown

Fixes #159.

In #159, font-optical-sizing: auto never took effect. That came from two separate problems, and this PR fixes both.

1. Slider values stuck after switching to "[Inherit page styles]"

service-worker.js kept track of the CSS it had injected into each tab in a module variable (injectedCSS). Chrome stops idle MV3 service workers after about 30 seconds, and that variable is lost when it does. The next update then inserts the new stylesheet but never removes the old one. So a stylesheet with the slider values ('opsz' 18, 'wght' 300, …) stays in the page after switching to Inherit, and the explicit 'opsz' overrides automatic optical sizing. Restarting Chrome clears it, which made the bug look intermittent.

  • Track the injected CSS in chrome.storage.session, which survives worker restarts.
  • Put CSS updates in a queue so quick successive changes can't orphan a stylesheet.
  • Remove a tab's entry when the tab closes.
  • If writing to session storage fails (10 MB quota, and font files are inlined), log it at debug level. The worst case is the current behavior.

2. No way to leave optical size on auto while using the sliders

Once any slider was touched, cssVariationSettings() wrote every axis, including opsz. The only way back to automatic optical size was "[Inherit page styles]", which also drops your other axis choices. The workaround was a hand-written font-variation-settings in the CSS box that left opsz out.

  • The Optical size value now doubles as a toggle, styled like the upload button. It reads AUTO in the accent color, or shows the number when it's off. While it's on, opsz is left out of font-variation-settings, so the browser matches it to the font size.
  • Auto is on by default for new fonts. Moving the slider turns it off, and clicking the toggle turns it back on. It's keyboard accessible (role="button", Enter/Space, aria-pressed).
  • New field Font.autoOpsz. Fonts saved before this change read it as true. Decision for you: that means anyone who had deliberately set opsz with a slider gets auto after updating. If you'd rather keep their setting, change the default in Font.fromObject to false.

Testing

I tested headlessly in Chromium with the built extension, using Cal Sans VF (opsz 8–45) on a <p> at 44px.

Scenario computed font-variation-settings
main: sliders at opsz 8 → worker stopped → Inherit "opsz" 8, "wght" 400 (stale)
this PR: same steps normal
without the worker restart, both builds normal
sliders, Auto on "GEOM" 25, "wght" 400 (no opsz)
sliders, Auto off "GEOM" 25, "opsz" 8, "wght" 400
font saved before this change (no autoOpsz) "GEOM" 25, "wght" 400

Popup: the toggle reads "auto" on open. Moving the slider to 30 shows "30" and stores autoOpsz: false. Clicking the toggle brings back "auto" and true, and the state survives reopening the popup. Only the opsz row gets the toggle.

🤖 Generated with Claude Code

MarkFonts and others added 2 commits October 13, 2026 17:39
The CSS injected into each tab was tracked in a module variable, which is
lost whenever Chrome stops the idle MV3 service worker (~30 seconds). The
next update then inserted new CSS without removing the old stylesheet, so
slider values kept applying after switching to "[Inherit page styles]",
and an explicit 'opsz' kept font-optical-sizing: auto from working.

Track it in chrome.storage.session instead, serialize CSS updates so quick
successive changes can't leave a stylesheet behind, and clean up when a
tab closes.

Fixes arrowtype#159

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moving any slider wrote every axis into font-variation-settings, including
'opsz', so there was no way to keep font-optical-sizing: auto while
adjusting other axes. The Optical size value now doubles as a toggle that
reads "auto" while it's on: 'opsz' is then left out and the browser matches
it to the font size. Auto is on by default, including for fonts saved
before this change; moving the slider turns it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MarkFonts MarkFonts changed the title Fix slider values overriding “Inherit page styles” (opsz: auto) Make optical size auto work: fix stale slider CSS, add an Auto toggle Oct 14, 2026
MarkFonts and others added 2 commits October 13, 2026 20:11
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Show "auto" as the value's text instead of hiding the number with CSS,
so it gets the same size, line height and position as the numbers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opsz and other font inheritance issues

1 participant