Skip to content

Commit

Permalink
Make RequestDetailTabRawPayload show actual raw data (#1060)
Browse files Browse the repository at this point in the history
* Make `RequestDetailTabRawPayload` show actual raw data

The `RequestDetailTabRawPayload` is currently rendering `FlightResponseChunkRaw`, which is in turn rendering `originalValue` from chunks. While this data does show some parts of the original response text, it has already gone through one level of parsing, so the row references at the beginning ot the lines are gone.

By directly using event data made accessible via #1058, we can show the real original text instead.

* Add a changeset
  • Loading branch information
alvarlagerlof committed Jun 9, 2024
1 parent 57c8a9b commit 4096674
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 36 deletions.
11 changes: 11 additions & 0 deletions .changeset/hip-gifts-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@rsc-parser/core": minor
"@rsc-parser/embedded-example": minor
"@rsc-parser/chrome-extension": minor
"@rsc-parser/embedded": minor
"@rsc-parser/react-client": minor
"@rsc-parser/storybook": minor
"@rsc-parser/website": minor
---

Improve the `Raw` tab
12 changes: 0 additions & 12 deletions packages/core/src/components/FlightResponseChunkRaw.tsx

This file was deleted.

47 changes: 23 additions & 24 deletions packages/core/src/components/RequestDetailTabRawPayload.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
import React from "react";
import { FlightResponseChunkRaw } from "./FlightResponseChunkRaw";
import { useEndTime } from "./EndTimeContext";
import { RscEvent, isRscChunkEvent } from "../events";
import {
createFlightResponse,
processBinaryChunk,
} from "@rsc-parser/react-client";
import { eventsFilterByMaxTimestamp } from "../eventArrayHelpers";
import { RequestDetailTabEmptyState } from "./RequestDetailTabEmptyState";

const textDecoder = new TextDecoder();

export function RequestDetailTabRawPayload({ events }: { events: RscEvent[] }) {
const { endTime } = useEndTime();

if (
eventsFilterByMaxTimestamp(events, endTime).filter(isRscChunkEvent)
.length === 0
) {
const filteredEvents = eventsFilterByMaxTimestamp(events, endTime).filter(
isRscChunkEvent,
);
if (filteredEvents.length === 0) {
return <RequestDetailTabEmptyState />;
}

const flightResponse = createFlightResponse();
for (const event of events.filter(isRscChunkEvent)) {
flightResponse._currentTimestamp = event.data.timestamp;
processBinaryChunk(flightResponse, Uint8Array.from(event.data.chunkValue));
}

const timeFilteredChunks = flightResponse._chunks.filter(
(chunk) => chunk.timestamp <= endTime,
);

return (
<ul className="flex flex-col gap-4 font-code">
{timeFilteredChunks.map((chunk) => (
<li key={chunk.id}>
<FlightResponseChunkRaw data={chunk} />
</li>
))}
{filteredEvents.map((event) => {
const text = textDecoder.decode(Uint8Array.from(event.data.chunkValue));

return (
<li
key={
event.data.requestId +
event.data.timestamp +
text.substring(0, 10)
}
>
<pre className="w-full whitespace-break-spaces break-all">
{text}
</pre>
</li>
);
})}
</ul>
);
}

0 comments on commit 4096674

Please sign in to comment.