Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/browser/components/Messages/InitMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect, useRef } from "react";
import { cn } from "@/common/lib/utils";
import type { DisplayedMessage } from "@/common/types/message";
import { Loader2, Wrench, CheckCircle2, AlertCircle } from "lucide-react";
Expand All @@ -22,6 +22,14 @@ export const InitMessage = React.memo<InitMessageProps>(({ message, className })
const isError = message.status === "error";
const isRunning = message.status === "running";
const isSuccess = message.status === "success";
const preRef = useRef<HTMLPreElement>(null);

// Auto-scroll to bottom while running
useEffect(() => {
if (isRunning && preRef.current) {
preRef.current.scrollTop = preRef.current.scrollHeight;
}
}, [isRunning, message.lines.length]);

const durationText =
message.durationMs !== null ? ` in ${formatDuration(message.durationMs)}` : "";
Expand Down Expand Up @@ -65,20 +73,16 @@ export const InitMessage = React.memo<InitMessageProps>(({ message, className })
</div>
<div className="text-muted mt-1 truncate font-mono text-[11px]">{message.hookPath}</div>
{message.lines.length > 0 && (
<div
<pre
ref={preRef}
className={cn(
"m-0 mt-2.5 flex max-h-[120px] flex-col-reverse overflow-auto rounded-sm",
"bg-black/30 px-2 py-1.5 font-mono text-[11px] leading-relaxed",
"m-0 mt-2.5 max-h-[120px] overflow-auto rounded-sm",
"bg-black/30 px-2 py-1.5 font-mono text-[11px] leading-relaxed whitespace-pre-wrap",
isError ? "text-danger-soft" : "text-light"
)}
>
{/* flex-col-reverse with reversed array auto-scrolls to bottom */}
{message.lines.toReversed().map((line, i) => (
<div key={i} className="whitespace-pre-wrap">
{line}
</div>
))}
</div>
{message.lines.join("\n")}
</pre>
)}
</div>
);
Expand Down