-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
RequestDetailTabRawPayload
show actual raw data (#1060)
* 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
1 parent
57c8a9b
commit 4096674
Showing
3 changed files
with
34 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
47 changes: 23 additions & 24 deletions
47
packages/core/src/components/RequestDetailTabRawPayload.tsx
This file contains 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,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> | ||
); | ||
} |