Skip to content

Commit

Permalink
Refactor ViewerStreams internals to allow a single list ot tabs
Browse files Browse the repository at this point in the history
The way that `ViewerStreams` was set up made it hard to mix components that depending on `RSC_CHUNK` together with those that may instead need `RSC_REQUEST` and `RSC_RESPONSE`. The `FlightResponse` component was sort of dictating a split between them.

It needed to change because I wanted to put "Headers" in the same row as everything else, like the parsed chunks and the network graph.

I ended up changing a few other things as well, like removing a bunch of `useMemo` (to make the code simpler, and because the compiler is going to help).
  • Loading branch information
alvarlagerlof committed Jun 9, 2024
1 parent 3f22306 commit 9e70239
Show file tree
Hide file tree
Showing 25 changed files with 659 additions and 792 deletions.
69 changes: 67 additions & 2 deletions packages/core/src/components/EndTimeContext.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,68 @@
import { createContext } from "react";
import {
ReactNode,
createContext,
useContext,
useEffect,
useState,
useTransition,
} from "react";

export const EndTimeContext = createContext<number>(Infinity);
const EndTimeContext = createContext<{
endTime: number;
visibleEndTime: number;
changeEndTime: (value: number) => void;
isPending: boolean;
}>({
endTime: Infinity,
visibleEndTime: Infinity,
changeEndTime: () => {},
isPending: false,
});

export function EndTimeProvider({
maxEndTime,
children,
}: {
maxEndTime: number;
children: ReactNode;
}) {
const [endTime, setEndTime] = useState(Infinity);
const [visibleEndTime, setVisibleEndTime] = useState(endTime);
const [isPending, startTransition] = useTransition();

const changeEndTime = (value: number) => {
setVisibleEndTime(value);
startTransition(() => {
setEndTime(value);
});
};

useEffect(() => {
if (endTime !== maxEndTime) {
changeEndTime(maxEndTime);
}
}, [maxEndTime]);

return (
<EndTimeContext.Provider
value={{
endTime,
visibleEndTime,
changeEndTime,
isPending,
}}
>
<div>{children}</div>
</EndTimeContext.Provider>
);
}

export function useEndTime() {
const context = useContext(EndTimeContext);

if (context === undefined) {
throw new Error("useEndTime must be used within a EndTimeContext.Provider");
}

return context;
}
64 changes: 0 additions & 64 deletions packages/core/src/components/FlightResponse.stories.tsx

This file was deleted.

78 changes: 0 additions & 78 deletions packages/core/src/components/FlightResponse.tsx

This file was deleted.

62 changes: 0 additions & 62 deletions packages/core/src/components/FlightResponseSelector.stories.tsx

This file was deleted.

Loading

0 comments on commit 9e70239

Please sign in to comment.