-
Notifications
You must be signed in to change notification settings - Fork 2
fix(desktop): fix renderer freeze while streaming workspace logs #609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
433e369
fix(desktop): guard terminal ResizeObserver against feedback loop
skevetter 4daf17d
fix(desktop): coalesce streamed log lines and memoize parser
skevetter 32618d4
fix(desktop): cap LogTable rendered rows to bound DOM size
skevetter 914ff3b
perf(desktop): virtualize LogTable for smooth large-log rendering
skevetter ad8bddf
test(desktop): polyfill ResizeObserver in jsdom setup
skevetter b81bae1
refactor(desktop): address LogTable review feedback
skevetter 77be37e
fix(desktop): merge LogTable classes with twMerge so overrides win
skevetter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
131 changes: 103 additions & 28 deletions
131
desktop/src/renderer/src/lib/components/log/LogTable.svelte
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,124 @@ | ||
| <script lang="ts"> | ||
| import { badgeVariants } from "$lib/components/ui/badge/index.js" | ||
| import * as Table from "$lib/components/ui/table/index.js" | ||
| import { parseLogLine } from "$lib/utils/log-parser.js" | ||
| import { cn } from "$lib/utils.js" | ||
|
|
||
| let { lines, class: className = "" }: { lines: string[]; class?: string } = | ||
| $props() | ||
| let { | ||
| lines, | ||
| class: className = "", | ||
| maxHeightClass = "max-h-96", | ||
| rowHeight = 28, | ||
| overscan = 12, | ||
| follow = false, | ||
| }: { | ||
| lines: string[] | ||
| class?: string | ||
| maxHeightClass?: string | ||
| rowHeight?: number | ||
| overscan?: number | ||
| follow?: boolean | ||
| } = $props() | ||
|
|
||
| let parsed = $derived(lines.map(parseLogLine)) | ||
| let viewport = $state<HTMLDivElement | null>(null) | ||
| let scrollTop = $state(0) | ||
| let viewportHeight = $state(0) | ||
| let pinnedToBottom = $state(true) | ||
|
|
||
| let total = $derived(lines.length) | ||
| let totalHeight = $derived(total * rowHeight) | ||
|
|
||
| let startIndex = $derived( | ||
| Math.max(0, Math.floor(scrollTop / rowHeight) - overscan), | ||
| ) | ||
| let endIndex = $derived( | ||
| Math.min( | ||
| total, | ||
| Math.ceil((scrollTop + viewportHeight) / rowHeight) + overscan, | ||
| ), | ||
| ) | ||
|
|
||
| let visible = $derived( | ||
| lines.slice(startIndex, endIndex).map((raw, i) => ({ | ||
| index: startIndex + i, | ||
| line: parseLogLine(raw), | ||
| })), | ||
| ) | ||
|
|
||
| function onScroll() { | ||
| if (!viewport) return | ||
| scrollTop = viewport.scrollTop | ||
| const distanceFromBottom = | ||
| viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight | ||
| pinnedToBottom = distanceFromBottom <= rowHeight | ||
| } | ||
|
|
||
| $effect(() => { | ||
| if (!viewport) return | ||
| const observer = new ResizeObserver(() => { | ||
| if (viewport) viewportHeight = viewport.clientHeight | ||
| }) | ||
| observer.observe(viewport) | ||
| viewportHeight = viewport.clientHeight | ||
| return () => observer.disconnect() | ||
| }) | ||
|
|
||
| $effect(() => { | ||
| // Follow the tail as new lines arrive, but only while the user is at the bottom. | ||
| void total | ||
| if (follow && pinnedToBottom && viewport) { | ||
| viewport.scrollTop = viewport.scrollHeight | ||
| } | ||
| }) | ||
| </script> | ||
|
|
||
| <Table.Root class="w-full table-fixed {className}"> | ||
| <Table.Header class="sticky top-0 z-10 bg-background"> | ||
| <Table.Row> | ||
| <Table.Head class="w-20">Time</Table.Head> | ||
| <Table.Head class="w-24">Level</Table.Head> | ||
| <Table.Head class="max-w-0">Message</Table.Head> | ||
| </Table.Row> | ||
| </Table.Header> | ||
| <Table.Body> | ||
| {#each parsed as line, i (i)} | ||
| <Table.Row | ||
| <div | ||
| bind:this={viewport} | ||
| onscroll={onScroll} | ||
| role="table" | ||
| aria-rowcount={total} | ||
| class={cn("relative overflow-auto rounded-md border", maxHeightClass, className)} | ||
| > | ||
| <div | ||
| role="row" | ||
| class="sticky top-0 z-10 grid grid-cols-[5rem_6rem_1fr] border-b bg-background text-start font-medium" | ||
| style="height: {rowHeight}px" | ||
| > | ||
| <div role="columnheader" class="flex items-center px-2">Time</div> | ||
| <div role="columnheader" class="flex items-center px-2">Level</div> | ||
| <div role="columnheader" class="flex items-center px-2">Message</div> | ||
| </div> | ||
|
|
||
| <div role="rowgroup" class="relative" style="height: {totalHeight}px"> | ||
| {#each visible as row (row.index)} | ||
| <div | ||
| role="row" | ||
| aria-rowindex={row.index + 1} | ||
| class={[ | ||
| line.level === "fatal" || line.level === "error" ? "bg-destructive/5" : "", | ||
| line.level === "warn" ? "bg-amber-500/5" : "", | ||
| "absolute grid w-full grid-cols-[5rem_6rem_1fr] items-center border-b", | ||
| row.line.level === "fatal" || row.line.level === "error" ? "bg-destructive/5" : "", | ||
| row.line.level === "warn" ? "bg-amber-500/5" : "", | ||
| ].filter(Boolean).join(" ")} | ||
| style="top: {row.index * rowHeight}px; height: {rowHeight}px" | ||
| > | ||
| <Table.Cell class="font-mono text-xs text-muted-foreground">{line.time}</Table.Cell> | ||
| <Table.Cell> | ||
| {#if line.level} | ||
| <div role="cell" class="truncate px-2 font-mono text-xs text-muted-foreground">{row.line.time}</div> | ||
| <div role="cell" class="px-2"> | ||
| {#if row.line.level} | ||
| <span | ||
| class={badgeVariants({ | ||
| variant: | ||
| line.level === "fatal" || line.level === "error" | ||
| row.line.level === "fatal" || row.line.level === "error" | ||
| ? "destructive" | ||
| : line.level === "warn" | ||
| : row.line.level === "warn" | ||
| ? "outline" | ||
| : "secondary", | ||
| })} | ||
| > | ||
| {line.level} | ||
| {row.line.level} | ||
| </span> | ||
| {/if} | ||
| </Table.Cell> | ||
| <Table.Cell class="text-sm max-w-0 whitespace-normal break-words" title={line.message}>{line.message}</Table.Cell> | ||
| </Table.Row> | ||
| </div> | ||
| <div role="cell" class="truncate px-2 text-sm" title={row.line.message}>{row.line.message}</div> | ||
| </div> | ||
| {/each} | ||
| </Table.Body> | ||
| </Table.Root> | ||
| </div> | ||
| </div> | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.