Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions apps/src/app/logs/request-detail-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,9 @@ export function RequestDetailModal({
setFieldLimit(DETAIL_FIELD_PREVIEW_BYTES);
}, [traceId, open]);

const { data: detail, isLoading } = useQuery({
queryKey: ["logs", "detail", serviceAddr, traceId, stage, itemLimit, fieldLimit],
const captureKey = ["logs", "detail", serviceAddr, traceId, stage] as const;
const { data: detail, isLoading, isPlaceholderData } = useQuery({
queryKey: [...captureKey, itemLimit, fieldLimit],
queryFn: ({ signal }) =>
serviceClient.requestLogDetail(
{
Expand All @@ -409,6 +410,11 @@ export function RequestDetailModal({
{ signal }
),
enabled: open && traceId.length > 0,
// Keep the existing rows mounted only while widening this capture's window.
placeholderData: (previous, previousQuery) =>
captureKey.every((part, index) => part === previousQuery?.queryKey[index])
? previous
: undefined,
staleTime: 30_000,
retry: 1,
gcTime: 60_000,
Expand Down Expand Up @@ -583,6 +589,7 @@ export function RequestDetailModal({
variant="outline"
size="sm"
className="h-7 text-[11px]"
disabled={isPlaceholderData}
onClick={() => setItemLimit((prev) => prev + DETAIL_ITEM_PAGE_SIZE)}
>
{t("加载更多条目")}
Expand All @@ -597,6 +604,7 @@ export function RequestDetailModal({
variant="outline"
size="sm"
className="h-7 text-[11px]"
disabled={isPlaceholderData}
onClick={() => setFieldLimit(0)}
>
{t("展开全部字段")}
Expand Down
19 changes: 17 additions & 2 deletions apps/tests/request-logs-duration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ test("paged payloads load on demand and copy the full captured stage", async ({
const note = "x".repeat(65_537);
const field = JSON.stringify(note);
const requests: Record<string, unknown>[] = [];
const nextWindow = Promise.withResolvers<void>();
let copied = "";
await page.exposeFunction("captureRequestCopy", (text: string) => { copied = text; });
await page.addInitScript(() => {
Expand All @@ -201,6 +202,7 @@ test("paged payloads load on demand and copy the full captured stage", async ({
const { id, method, params } = route.request().postDataJSON();
if (method !== "requestlog/detail") return route.fallback();
requests.push(params);
if (params.itemLimit === 400) await nextWindow.promise;
const shown = items.slice(0, params.itemLimit || items.length);
const value = field.slice(0, params.fieldLimit || field.length);
return route.fulfill({ json: { id, result: {
Expand All @@ -221,8 +223,21 @@ test("paged payloads load on demand and copy the full captured stage", async ({
await expect.poll(() => copied.length).toBeGreaterThan(0);
expect(JSON.parse(copied)).toEqual({ note, input: items });
expect(requests[1].stage).toBe("client");
await dialog.getByRole("button", { name: "加载更多条目" }).click();
await expect(dialog.getByRole("button", { name: "加载更多条目" })).toHaveCount(0);
await dialog.getByRole("button", { name: /^#1\b/ }).click();
const expandedFirstItem = dialog.locator("pre code").filter({ hasText: /^0$/ });
await expect(expandedFirstItem).toBeVisible();

const loadMore = dialog.getByRole("button", { name: "加载更多条目" });
await loadMore.click();
try {
await expect.poll(() => requests.at(-1)?.itemLimit).toBe(400);
await expect(expandedFirstItem).toBeVisible();
await expect(loadMore).toBeDisabled();
} finally {
nextWindow.resolve();
}
await expect(loadMore).toHaveCount(0);
await expect(expandedFirstItem).toBeVisible();
await dialog.getByRole("button", { name: "展开全部字段" }).click();
await expect.poll(() => requests.at(-1)?.fieldLimit).toBe(0);
await expect(dialog.getByRole("button", { name: "展开全部字段" })).toHaveCount(0);
Expand Down
Loading