Repository navigation
fix: apply updated host fonts in applyHostFonts - #874
Open
aishwary-dongre wants to merge 1 commit into
Open
aishwary-dongre wants to merge 1 commit into
aishwary-dongre wants to merge 1 commit into
Conversation
applyHostFonts returned early once its style tag existed, so fonts sent in a later host-context-changed notification were dropped. Reuse the tag and replace its contents when the CSS differs.
This branch has not been deployed
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.
Fixes #873
Problem
applyHostFontsreturned early whenever its<style id="__mcp-host-fonts">tag already existed. A host that sends differentstyles.css.fontsinui/notifications/host-context-changedhad no effect after the first call, even thoughuseHostFontsanduseHostStylescallapplyHostFontson every context change and document that updated fonts are applied.Change
src/styles.ts: reuse the existing style tag and replace itstextContentwhen the CSS differs. There's still only one tag, and repeated calls with the same CSS don't touch the DOM.applyHostFontsdoc comment to describe the new behavior.src/styles.test.ts(new): unit tests with a minimaldocumentstub, following thewindowstub pattern inmessage-transport.test.ts.Testing
npx bun test src/styles.test.ts: 3 pass. Onmain,replaces the font CSS when the host sends different fontsfails withExpected "...B..." / Received "...A...".npm test: 454 pass, 0 fail.npm run build,npx tsc --noEmit, andnpm exec typedoc -- --treatValidationWarningsAsErrors --emit none: all pass.build:allfor every example, thenprettier:fix) passed.Not tested: a real host sending a font change (I don't have a host that does), and the E2E suite (
npm run test:e2e).AI assistance
I used an AI coding assistant (Claude, in the Kiro IDE) to find the bug, write the fix and tests, and run the checks above. I reviewed the diff and results myself.