Repository navigation
Studio: viewport-gated highlight for the executed Python script (follow-up to #7240) - #7363
Conversation
|
@codex review |
|
pre-commit.ci run |
…d + viewport-gated highlight Always show the executed Python script under the tool card (not only inside the collapsible run/output section, which is unmounted from history), with Copy and a client-side .py Download button, so the script stays visible on reopen (#7165). The script is rendered eagerly, but shiki syntax-highlighting only runs once the block scrolls near the viewport (IntersectionObserver, 200px margin); until then a plain monospace placeholder shows the same source with matching padding, so there is no layout jump. This bounds highlighting to the cards actually on screen instead of tokenizing every script up front. Measured shiki cost is ~8 ms per typical 2 KB script, so eager highlighting of a long agentic transcript (20-50+ Python calls) would add ~170-420 ms of main-thread work on load; viewport-gating keeps it to the few visible cards (~15-35 ms) regardless of transcript length. Falls back to immediate highlight when IntersectionObserver is unavailable (SSR / tests).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b6ae307645
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ) : ( | ||
| // Same p-3 padding as the highlighted code block so there is no layout | ||
| // jump when shiki swaps in. | ||
| <pre className="m-0 whitespace-pre-wrap break-words p-3 font-mono text-xs text-muted-foreground"> |
There was a problem hiding this comment.
Preserve the placeholder's padding before highlighting
When IntersectionObserver is available, the initial placeholder does not actually keep the promised p-3 padding: the parent at line 157 applies [&_pre]:!p-0, whose !important overrides this <pre>'s p-3. The highlighted Streamdown variant instead receives !p-3 on its code-block wrapper, so every lazily highlighted script shifts by the missing padding when it enters the viewport, defeating the no-layout-jump behavior in normal browsers.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch, fixed. The placeholder is now a div (not a pre), so the container's [&_pre]:!p-0 no longer strips its padding, and it keeps the same p-3 the highlighted code block gets. The content no longer shifts when shiki swaps in.
b6ae307 to
f3bfd7e
Compare
|
@codex review |
|
pre-commit.ci run |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
… doesn't strip its p-3 The placeholder shares the highlighted block's p-3 padding to avoid a layout jump, but as a <pre> it was caught by the container's [&_pre]:!p-0 !important rule and rendered with no padding, so the script shifted by p-3 when shiki swapped in. A plain div keeps the padding.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2a911f6a0b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // A div, not a <pre>: the container's [&_pre]:!p-0 would override a | ||
| // <pre>'s padding and shift the content by p-3 when shiki swaps in. This | ||
| // keeps the same p-3 the highlighted code block gets, so there is no jump. | ||
| <div className="whitespace-pre-wrap break-words p-3 font-mono text-xs text-muted-foreground"> |
There was a problem hiding this comment.
Keep placeholder layout consistent with highlighted code
When a script contains a long line, this placeholder wraps and forcibly breaks that line, while the subsequent Streamdown <pre> preserves it and uses the container's horizontal overflow. As soon as the observer fires, a placeholder that may be at the max-h-48 limit can collapse to a single unwrapped line (or otherwise change height), shifting the transcript under the reader; this defeats the stated no-layout-jump behavior for common generated code containing long literals or serialized data.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed. The placeholder now uses whitespace-pre (not pre-wrap), so a long line scrolls in the container's overflow-auto exactly like the highlighted <pre> instead of wrapping taller and then collapsing when shiki swaps in. The block height stays stable across the swap.
…t pre-wrap) The placeholder wrapped long lines while the highlighted Streamdown <pre> keeps them on one line and scrolls in the container's overflow-auto, so a script with a long line changed height when shiki swapped in. Use whitespace-pre so the placeholder scrolls the same way and the height stays stable.
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
What
Keep the executed Python script visible in the chat tool card, with Copy and a Download button, and highlight it lazily so long transcripts stay fast.
.pyDownload button next to Copy (builds a Blob and clicks an anchor, the same pattern the image / audio / attachment / chat-export buttons use).IntersectionObserver, 200px margin). Until then a plain monospace placeholder shows the same source with matching padding, so there is no layout jump. Falls back to immediate highlight whenIntersectionObserveris unavailable (SSR / tests).Why the viewport gating
Rendering the script always (rather than only on expand) means its highlighting would otherwise run for every Python tool call on load. Measured with the bundled shiki (3.23.0, dual github themes, python):
Eager highlighting of a long agentic transcript would add ~170 ms (20 calls) to ~420 ms (50 calls) of main-thread work on load. Viewport-gating bounds it to the handful of cards actually on screen (~15-35 ms) regardless of transcript length. Live/streaming chat is unchanged (the running card is already open).
Notes
tsc -btypecheck passes; the executed-script placeholder keeps the source visible and copyable at all times.