Repository navigation
fix(ENG-4204): inline malachite fonts in the web component instead of loading files beside the script - #248
Open
joeStackOne wants to merge 1 commit into
Open
joeStackOne wants to merge 1 commit into
joeStackOne wants to merge 1 commit into
Conversation
…side the script
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 the IIFE that URL resolves next to webcomponent.js, where no font
exists, so each face the page uses 404s before malachite falls back to
its inlined copy.
The web component build now resolves each malachite font wrapper to its
.inline.js copy, and fails if a wrapper that loads a file has none.
verify:build fails if webcomponent.js names a font file. The plugin is
tested against a fixture, since the lockfile (malachite 2.79.0) never
reaches the swap.
No change on the current lockfile: the bundle is byte-identical.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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). Inwebcomponent.js, Rollup rewritesimport.meta.urlto 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 besidewebcomponent.jsand 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.jsbuilds 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.jswith 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.
Chrome: before, 2 font 404s and 2 console errors on every load, then the fallback recovers. After, no font requests.
The change
scripts/inline-malachite-fonts.mjs: a Rollup plugin, used only by the web component build, that resolves each malachite*.woff2.jswrapper to its*.woff2.inline.jssibling (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 ifwebcomponent.jsnames a font file in any form, or usesimport.meta.urlat 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.webcomponent.jsverify:buildLocal:
npm test52 passed,npm run lintandverify:buildpass. With the swap removed, the plugin's main test fails.Review
Four
/code-reviewpasses; the last found no correctness issue. Left as they are:npm link) resolves outside@stackone/malachite/, so the plugin skips it.verify:buildstill fails on the result, and a published build never links.rollup.config.mjsis not covered by the plugin's own test. Moving it afterresolve()stops the swap, andverify:buildfails on the first malachite bump.*.woff2.inline.jsbeside 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.npm testnow also runs this plugin's tests.Post-merge validation
@stackone/hub. Customers pick upwebcomponent.json their next upgrade.webcomponent.json its own and renders<stackone-hub>.*.woff2requests besidewebcomponent.js, and the picker renders in Inter in Safari and Chrome.verify:buildfailing on the bump PR; 404s on*.woff2next to the script; text in the system font.🤖 Generated with Claude Code
Summary by cubic
Fixes the
webcomponent.jsbuild so fonts stay inlined once hub bumps@stackone/malachitepast 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 serveswebcomponent.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..woff2.inline.jscopy 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:buildnow fails ifwebcomponent.jsnames any font file or usesimport.meta.url.Written for commit 7a2cf24. Summary will update on new commits.