Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/kind-ghosts-win.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/start-client-core': patch
---

compact private frame decoder result keys
6 changes: 3 additions & 3 deletions packages/start-client-core/src/client-rpc/frame-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const MAX_FRAMES = 100_000 // Limit total frames to prevent CPU DoS
*/
export interface FrameDecoderResult {
/** Gets or creates a raw stream by ID (for use by deserialize plugin) */
getOrCreateStream: (id: number) => ReadableStream<Uint8Array>
getStream: (id: number) => ReadableStream<Uint8Array>
/** Stream of JSON strings (NDJSON lines) */
jsonChunks: ReadableStream<string>
chunks: ReadableStream<string>
}

/**
Expand Down Expand Up @@ -404,5 +404,5 @@ export function createFrameDecoder(
}
})()

return { getOrCreateStream, jsonChunks }
return { getStream: getOrCreateStream, chunks: jsonChunks }
}
9 changes: 3 additions & 6 deletions packages/start-client-core/src/client-rpc/serverFnFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,15 @@ async function getResponse(fn: () => Promise<Response>) {
throw new Error('No response body for framed response')
}

const { getOrCreateStream, jsonChunks } = createFrameDecoder(
response.body,
)
const { getStream, chunks } = createFrameDecoder(response.body)

// Create deserialize plugin that wires up the raw streams
const rawStreamPlugin =
createRawStreamDeserializePlugin(getOrCreateStream)
const rawStreamPlugin = createRawStreamDeserializePlugin(getStream)
const plugins = [rawStreamPlugin, ...(serovalPlugins || [])]

const refs = new Map()
result = await processFramedResponse({
jsonStream: jsonChunks,
jsonStream: chunks,
onMessage: (msg: any) => fromCrossJSON(msg, { refs, plugins }),
onError(msg, error) {
console.error(msg, error)
Expand Down
44 changes: 25 additions & 19 deletions packages/start-client-core/tests/frame-decoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('frame-decoder', () => {
},
})

const { jsonChunks } = createFrameDecoder(input)
const { chunks: jsonChunks } = createFrameDecoder(input)
const reader = jsonChunks.getReader()

await expect(reader.read()).rejects.toThrow('Unknown frame type')
Expand All @@ -65,7 +65,7 @@ describe('frame-decoder', () => {
},
})

const { jsonChunks } = createFrameDecoder(input)
const { chunks: jsonChunks } = createFrameDecoder(input)
const reader = jsonChunks.getReader()

await expect(reader.read()).rejects.toThrow('Invalid raw frame streamId')
Expand All @@ -84,7 +84,7 @@ describe('frame-decoder', () => {
},
})

const { jsonChunks } = createFrameDecoder(input)
const { chunks: jsonChunks } = createFrameDecoder(input)
const reader = jsonChunks.getReader()

await expect(reader.read()).rejects.toThrow('Invalid JSON frame streamId')
Expand All @@ -105,7 +105,7 @@ describe('frame-decoder', () => {
},
})

const { jsonChunks } = createFrameDecoder(input)
const { chunks: jsonChunks } = createFrameDecoder(input)
const reader = jsonChunks.getReader()

await expect(reader.read()).rejects.toThrow('Frame payload too large')
Expand All @@ -125,7 +125,7 @@ describe('frame-decoder', () => {
},
})

const { jsonChunks } = createFrameDecoder(input)
const { chunks: jsonChunks } = createFrameDecoder(input)
const reader = jsonChunks.getReader()

await expect(reader.read()).rejects.toThrow('Incomplete frame')
Expand All @@ -140,7 +140,7 @@ describe('frame-decoder', () => {
},
})

const { jsonChunks } = createFrameDecoder(input)
const { chunks: jsonChunks } = createFrameDecoder(input)
const reader = jsonChunks.getReader()

await reader.cancel()
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('frame-decoder', () => {
},
})

const { jsonChunks } = createFrameDecoder(input)
const { chunks: jsonChunks } = createFrameDecoder(input)
const reader = jsonChunks.getReader()

await expect(reader.read()).rejects.toThrow('Too many raw streams')
Expand All @@ -186,7 +186,7 @@ describe('frame-decoder', () => {
},
})

const { jsonChunks } = createFrameDecoder(input)
const { chunks: jsonChunks } = createFrameDecoder(input)
const reader = jsonChunks.getReader()

await expect(reader.read()).rejects.toThrow('buffer exceeded')
Expand All @@ -207,7 +207,7 @@ describe('frame-decoder', () => {
},
})

const { jsonChunks } = createFrameDecoder(input)
const { chunks: jsonChunks } = createFrameDecoder(input)

const reader = jsonChunks.getReader()
const chunks: Array<string> = []
Expand Down Expand Up @@ -240,7 +240,8 @@ describe('frame-decoder', () => {
},
})

const { jsonChunks, getOrCreateStream } = createFrameDecoder(input)
const { chunks: jsonChunks, getStream: getOrCreateStream } =
createFrameDecoder(input)

// Pre-create the stream before consuming
const stream5 = getOrCreateStream(5)
Expand Down Expand Up @@ -276,7 +277,7 @@ describe('frame-decoder', () => {
},
})

const { jsonChunks } = createFrameDecoder(input)
const { chunks: jsonChunks } = createFrameDecoder(input)

const reader = jsonChunks.getReader()
const chunks: Array<string> = []
Expand All @@ -301,7 +302,7 @@ describe('frame-decoder', () => {
},
})

const { jsonChunks } = createFrameDecoder(input)
const { chunks: jsonChunks } = createFrameDecoder(input)
const reader = jsonChunks.getReader()
const { value } = await reader.read()

Expand All @@ -326,7 +327,7 @@ describe('frame-decoder', () => {
},
})

const { jsonChunks } = createFrameDecoder(input)
const { chunks: jsonChunks } = createFrameDecoder(input)
const reader = jsonChunks.getReader()
const { value } = await reader.read()

Expand All @@ -353,7 +354,7 @@ describe('frame-decoder', () => {
},
})

const { jsonChunks } = createFrameDecoder(input)
const { chunks: jsonChunks } = createFrameDecoder(input)
const reader = jsonChunks.getReader()
const { value } = await reader.read()

Expand Down Expand Up @@ -387,7 +388,8 @@ describe('frame-decoder', () => {
},
})

const { getOrCreateStream, jsonChunks } = createFrameDecoder(input)
const { getStream: getOrCreateStream, chunks: jsonChunks } =
createFrameDecoder(input)

// Pre-create streams before consuming
const stream1 = getOrCreateStream(1)
Expand Down Expand Up @@ -428,7 +430,8 @@ describe('frame-decoder', () => {
},
})

const { getOrCreateStream, jsonChunks } = createFrameDecoder(input)
const { getStream: getOrCreateStream, chunks: jsonChunks } =
createFrameDecoder(input)

// Pre-create stream 3
const stream3 = getOrCreateStream(3)
Expand Down Expand Up @@ -480,7 +483,8 @@ describe('frame-decoder', () => {
},
})

const { getOrCreateStream, jsonChunks } = createFrameDecoder(input)
const { getStream: getOrCreateStream, chunks: jsonChunks } =
createFrameDecoder(input)

// First, fully consume JSON stream (this processes all frames)
const jsonReader = jsonChunks.getReader()
Expand Down Expand Up @@ -536,7 +540,8 @@ describe('frame-decoder', () => {
},
})

const { getOrCreateStream, jsonChunks } = createFrameDecoder(input)
const { getStream: getOrCreateStream, chunks: jsonChunks } =
createFrameDecoder(input)

// Drain JSON (processes all frames)
const jsonReader = jsonChunks.getReader()
Expand Down Expand Up @@ -588,7 +593,8 @@ describe('frame-decoder', () => {
},
})

const { getOrCreateStream, jsonChunks } = createFrameDecoder(input)
const { getStream: getOrCreateStream, chunks: jsonChunks } =
createFrameDecoder(input)
const stream11 = getOrCreateStream(11)

const jsonReader = jsonChunks.getReader()
Expand Down
Loading