Skip to content

Commit

Permalink
feat(console): use http batch streams (#7051)
Browse files Browse the repository at this point in the history
The HTTP batch stream links in TRPC can resolve individually as soon as their responses finished streaming, making the batch stream faster than a normal batch.
  • Loading branch information
skyrpex authored Aug 26, 2024
1 parent 058b88c commit d11a8a0
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions apps/wing-console/console/ui/src/Console.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import {
httpBatchLink,
wsLink,
splitLink,
createWSClient,
httpLink,
unstable_httpBatchStreamLink,
} from "@trpc/client";
import type { Mode } from "@wingconsole/design-system";
import type { Trace } from "@wingconsole/server";
Expand Down Expand Up @@ -61,34 +60,15 @@ export const Console = ({
const [trpcClient] = useState(() =>
trpc.createClient({
links: [
// For subscriptions, use WebSocket.
splitLink({
condition(op) {
return op.type === "subscription";
},
true: wsLink({
client: wsClient,
}),
// For the `test.*` operations, use a single HTTP link. This is necessary
// to avoid a bug where the Console would not display the data until
// the app starts correctly. For example, starting a new application
// with compilation errors, the Console will be stuck.
//
// For the rest of the operations, use the batch HTTP link.
//
// We should be able to use batch HTTP links everywhere if we refactor
// the `test.*` operations so they don't wait until the Simulator
// instance is ready.
false: splitLink({
condition(op) {
return op.path.startsWith("test.");
},
true: httpLink({
url: trpcUrl,
}),
false: httpBatchLink({
url: trpcUrl,
}),
false: unstable_httpBatchStreamLink({
url: trpcUrl,
}),
}),
],
Expand Down

0 comments on commit d11a8a0

Please sign in to comment.