fix(ENG-4204): inline malachite fonts in the web component instead of loading files beside the script

JO
3d ago
+128-0

From 2.134.1 (malachite#814) malachite ships each font as a woff2 file beside a wrapper that exports new URL("./<font>.woff2", import.meta.url). In webcomponent.js, Rollup rewrites import.meta.url to the script's own URL, and hub's IIFE build copies no font files. So once hub bumps malachite, every customer page that embeds the web component requests the fonts beside webcomponent.js and gets 404s. Chrome then falls back to malachite's inlined copies. Safari never does (fixed separately in malachite#822), so there the picker renders in the system font.

Ticket: ENG-4204.

This PR does not bump malachite. The lockfile stays on 2.79.0, where webcomponent.js builds byte-identical (1,284,708 bytes). It makes the web component safe for the bump.

Before and after

Hub's real <stackone-hub>, built against malachite 2.134.1 and served from /cdn/hub/webcomponent.js with a mocked hub API. Every response is delayed 250 ms. Each image shows the screenshot, a 3× zoom of the same rows, and the requests and console errors the browser recorded.

Safari (WebKit): before, 2 font 404s and Inter never loads. After, no font requests and Inter loads.

WebKit before and after

Chrome: before, 2 font 404s and 2 console errors on every load, then the fallback recovers. After, no font requests.

Chrome before and after

The change

  • scripts/inline-malachite-fonts.mjs: a Rollup plugin, used only by the web component build, that resolves each malachite *.woff2.js wrapper to its *.woff2.inline.js sibling (the same data URL malachite falls back to). The IIFE already carries those base64 copies, so nothing grows. A wrapper that loads a file with no inlined copy fails the build. A pre-2.134.1 wrapper, which is already a data URL, is left alone.
  • scripts/verify-build.mjs (already in CI) fails if webcomponent.js names a font file in any form, or uses import.meta.url at all, which in the IIFE points at the script itself.
  • scripts/inline-malachite-fonts.test.mjs: the lockfile never reaches the swap, so the plugin is tested by bundling a fake malachite package with Rollup.
Buildwebcomponent.jsverify:build
lockfile (malachite 2.79.0)byte-identicalpass
malachite 2.134.1, this PR0 font URLs, 11 fonts inlined oncepass
malachite 2.134.1, plugin removed11 font URLsfails, names both problems

Local: npm test 52 passed, npm run lint and verify:build pass. With the swap removed, the plugin's main test fails.

Review

Four /code-review passes; the last found no correctness issue. Left as they are:

  • A linked local malachite (npm link) resolves outside @stackone/malachite/, so the plugin skips it. verify:build still fails on the result, and a published build never links.
  • Plugin order in rollup.config.mjs is not covered by the plugin's own test. Moving it after resolve() stops the swap, and verify:build fails on the first malachite bump.
  • The plugin depends on malachite's dist layout (*.woff2.inline.js beside each wrapper). If malachite renames those, the plugin fails the build rather than shipping 404s. A supported inline-fonts entry in malachite would be the deeper fix.
  • The CI step is still named "Test (format-vector conformance)" though npm test now also runs this plugin's tests.

Post-merge validation

  • Path: library. release-please publishes @stackone/hub. Customers pick up webcomponent.js on their next upgrade.
  • Scenario: after hub bumps malachite to 2.134.1 or later, load a page that serves webcomponent.js on its own and renders <stackone-hub>.
  • Signal it worked: no *.woff2 requests beside webcomponent.js, and the picker renders in Inter in Safari and Chrome.
  • Regression signals: verify:build failing on the bump PR; 404s on *.woff2 next to the script; text in the system font.

🤖 Generated with Claude Code


Summary by cubic

Fixes the webcomponent.js build so fonts stay inlined once hub bumps @stackone/malachite past 2.134.1, when malachite starts shipping each font as a woff2 file beside the script. In the IIFE those file URLs resolve next to wherever the customer serves webcomponent.js, where no font exists, so every font face 404s; Chrome then falls back to malachite's inlined copies, but Safari renders the picker in the system font. Relates to ENG-4204.

  • Adds a Rollup plugin that resolves each malachite font wrapper to its inlined .woff2.inline.js copy in the web component build only, failing the build when a wrapper has no inline copy. Wrappers that are already data URLs are left alone.
  • verify:build now fails if webcomponent.js names any font file or uses import.meta.url.
  • This PR bumps no dependencies; on the current lockfile (malachite 2.79.0) the bundle is byte-identical.