Skip to content

fix: apply updated host fonts in applyHostFonts - #874

Open
aishwary-dongre wants to merge 1 commit into
modelcontextprotocol:mainfrom
aishwary-dongre:fix/apply-host-fonts-updates
Open

aishwary-dongre wants to merge 1 commit into
modelcontextprotocol:mainfrom
aishwary-dongre:fix/apply-host-fonts-updates

Conversation

@aishwary-dongre

Copy link
Copy Markdown

Fixes #873

Problem

applyHostFonts returned early whenever its <style id="__mcp-host-fonts"> tag already existed. A host that sends different styles.css.fonts in ui/notifications/host-context-changed had no effect after the first call, even though useHostFonts and useHostStyles call applyHostFonts on every context change and document that updated fonts are applied.

Change

  • src/styles.ts: reuse the existing style tag and replace its textContent when the CSS differs. There's still only one tag, and repeated calls with the same CSS don't touch the DOM.
  • Updated the applyHostFonts doc comment to describe the new behavior.
  • src/styles.test.ts (new): unit tests with a minimal document stub, following the window stub pattern in message-transport.test.ts.

Testing

  • npx bun test src/styles.test.ts: 3 pass. On main, replaces the font CSS when the host sends different fonts fails with Expected "...B..." / Received "...A...".
  • npm test: 454 pass, 0 fail.
  • npm run build, npx tsc --noEmit, and npm exec typedoc -- --treatValidationWarningsAsErrors --emit none: all pass.
  • The pre-commit hook (build:all for every example, then prettier: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.

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

No deployments
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.

applyHostFonts ignores updated fonts from host-context-changed

2 participants