fix(dashboard): open each new log result at its newest line

The console keeps a query's previous data as placeholder while the next
one loads, so the log list was never remounted between queries. After
a reader scrolled up, a new filter or range opened at the old scroll
offset instead of the newest lines. The list is now keyed on the query
and range as well.

Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
ZverGuy committed 2026-11-05 00:18:38 +07:00
1 parent ef7312579d
commit 7d43c3bcd6
2 files changed
+23 -5

No files matched your search

@@ -86,13 +86,13 @@ describe("LogsView", () => {
endpoint.endsWith("query") ? new Response("") : defaultHandler(endpoint, params),
)
renderWithK8sProvider(<LogsView scope={app} />, { client })
const frame = screen.getByRole("region", { name: "Log lines" })
expect(await within(frame).findByText("Try a longer range or a broader filter.")).toBeInTheDocument()
const frame = () => screen.getByRole("region", { name: "Log lines" })
expect(await within(frame()).findByText("Try a longer range or a broader filter.")).toBeInTheDocument()
await userEvent.click(screen.getByRole("button", { name: "24h" }))
expect(await within(frame).findByText("Try a broader filter.")).toBeInTheDocument()
expect(within(frame).queryByText(/longer range/)).toBeNull()
await waitFor(() => expect(within(frame()).getByText("Try a broader filter.")).toBeInTheDocument())
expect(within(frame()).queryByText(/longer range/)).toBeNull()
})
it("shows loading inside the log console", () => {
@@ -237,6 +237,23 @@ describe("LogsView", () => {
expect(screen.queryByRole("button", { name: "Retry" })).toBeNull()
})
it("opens a new history result at its newest line, not the old scroll position", async () => {
const { client } = clientWith((endpoint, params) =>
endpoint.endsWith("query")
? new Response(`${line("2026-11-04T10:00:01Z", `result for ${params.get("query")}`)}\n`)
: defaultHandler(endpoint, params),
)
const { queryClient } = renderWithK8sProvider(<LogsView scope={app} />, { client })
queryClient.setDefaultOptions({ queries: { ...queryClient.getDefaultOptions().queries, placeholderData: (prev: unknown) => prev } })
await screen.findByText("result for *")
const before = screen.getByRole("list")
await userEvent.type(screen.getByLabelText("LogsQL filter"), "error{Enter}")
await screen.findByText("result for error")
expect(screen.getByRole("list")).not.toBe(before)
})
it("names the source pod and container of each line", async () => {
const { client } = clientWith(defaultHandler)
@@ -160,7 +160,8 @@ export function LogsView({ scope }: { scope: ObservabilityScope }) {
)}
{error ? <ProxyNotice what="Logs" error={error} /> : null}
<LogLines
key={followRun ?? "history"}
// Previous results stay as placeholder data while a new query loads, so only a new key resets the scroll pin.
key={followRun ?? `history\n${query}\n${range}`}
entries={entries}
placeholder={placeholderFor({ follow, stopped: tail.state === "stopped", loading: history.isLoading, failed: Boolean(error), longestRange: range === LONGEST_RANGE, retry: () => void history.refetch() })}
/>