Replace superjson with vendored Flight protocol encoder#45
Conversation
Removes the `superjson` dependency and replaces it with a ~230-line Flight-protocol data encoder/decoder (`flight-data.ts`) that produces the same wire format as React's `renderToReadableStream`. The typed client (`createSpiceflowClient` / `createSpiceflowFetch`) now receives `text/x-flight` responses instead of superjson-wrapped JSON when the `x-spiceflow-agent: spiceflow-client` header is present. Regular HTTP consumers still get plain `application/json`. Wire format prefixes: $D<iso> Date $Q<id> Map (entries at chunk id) $W<id> Set (items at chunk id) $n<digits> BigInt $undefined undefined $NaN, $Infinity, $-Infinity, $-0 special numbers $R<regex> RegExp $S<key> Symbol.for() $Z<json> Error $l<href> URL Changes: - new `spiceflow/src/flight-data.ts` — encoder + decoder, zero deps - new `spiceflow/src/flight-data.test.ts` — 18 tests covering all types - `spiceflow.tsx` — `superjsonSerialize` → `serializeResponse`, uses `flightEncode` for RPC requests, `JSON.stringify` for plain requests. Renamed `disableSuperJsonUnlessRpc` → `useFlightEncoding` (deprecated alias kept for backward compat) - `client/shared.ts` — `superjsonDeserialize` → `flightDecode`, added `text/x-flight` content-type handling in `parseResponseData` - `client/index.ts` — same content-type switch - `vite.tsx` — removed `spiceflow > superjson` from optimizeDeps - `package.json` — removed superjson dependency - Added `Vary: x-spiceflow-agent` header to prevent CDN cache mixing - check-entry passes (263KB bundle, no superjson) - All 554 tests pass Session: ses_2562f1c11ffeDC9ypyA2F116GL
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 20cf4dab26
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| 'event: message\ndata: ' + | ||
| self.superjsonSerialize(chunk, false, request) + | ||
| self.serializeResponse(chunk, false, request) + | ||
| '\n\n', |
There was a problem hiding this comment.
Prefix every Flight row as SSE data lines
When serializeResponse returns Flight payloads with multiple rows (for example values containing Map/Set), this concatenation writes only the first row after data: and leaves subsequent rows as bare SSE lines. EventSource parsers ignore non-data fields, so streamed chunks are truncated/corrupted before flightDecode runs. This breaks streamed server action/subscribe payloads that include chunked Flight types.
Useful? React with 👍 / 👎.
| case 'text/event-stream': | ||
| data = streamSSEResponse({ | ||
| response, | ||
| map: (x) => tryParsingSSEJson(x.data), | ||
| map: (x) => tryParsingSSEJson(x.data, true), | ||
| executeRequest, |
There was a problem hiding this comment.
Preserve JSON fallback for non-Flight SSE events
This path now forces SSE message parsing to Flight mode, but many custom text/event-stream handlers emit plain JSON strings. In that case flightDecode fails and the client returns the raw string instead of parsed JSON, which is a behavioral regression from the previous parser. Please keep a JSON fallback when Flight decoding fails (or gate Flight mode explicitly) so existing JSON SSE endpoints still work.
Useful? React with 👍 / 👎.
Summary
superjsondependency entirelyspiceflow/src/flight-data.ts— a ~230-line Flight-protocol data encoder/decoder written from scratch based on the wire format spectext/x-flightresponses (same wire format as React'srenderToReadableStream) instead of superjson-wrapped JSONapplication/jsonVary: x-spiceflow-agentheader prevents CDN cache mixing between the two formatsSupported types: Date, Map, Set, BigInt, undefined, NaN, ±Infinity, -0, RegExp, Symbol.for(), Error, URL
Verification:
pnpm tsc✅,pnpm check-entry✅ (263KB), 554 tests pass