fix(app): use resolved Shiki theme for code blocks#2467
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@taneja-garvit is attempting to deploy a commit to the Different AI Team on Vercel. A member of the Team first needs to authorize it. |
Pablosinyores
left a comment
There was a problem hiding this comment.
Read through this and the approach is right. useSyncExternalStore(subscribeToTheme, getResolvedShikiTheme) is the correct primitive for pulling theme into render without a hand-rolled listener, and adding shikiTheme to the highlight effect deps in both MarkdownBlockInner and CodeBlockCode is what actually makes blocks re-highlight on toggle. The theme ?? resolvedTheme fallback in CodeBlockCode keeps explicit-theme callers working while defaulting everything else to the resolved app theme — clean.
One minor thing in markdown.tsx: the cached-HTML shortcut
const html = !streaming && highlightedHtml?.text === text ? highlightedHtml.html : syncHtml;
is keyed on text only, not on theme. On a light/dark toggle where the text is unchanged, highlightedHtml.text === text stays true, so the previously highlighted (old-theme) HTML shows until the effect's async re-highlight resolves and replaces highlightedHtml. It self-corrects because the effect now depends on shikiTheme, so it is a brief flash rather than a stuck state — just flagging in case you want to also gate that memo on theme to kill the transient. Not a blocker.
Mapping resolved light/dark to github-light/github-dark is exactly the right scope for #2440. Nice fix.
|
Good catch - makes sense, the memo should be theme-aware too so we don't even get the transient. Pushing a fix now to also gate highlightedHtml on shikiTheme |
|
@Pablosinyores Pushed a small follow-up for this. I made the cached highlighted HTML theme-aware as well, so we don’t briefly reuse old-theme Shiki output during a light/dark toggle. |
Fixes #2440
Summary
github-lightFixes #2440
Test plan
pnpm typecheckpnpm --filter @openwork/app exec bun test tests/theme.test.ts