fix(tables): SSR crash from tableKeys in a 'use client' module + drop redundant flushChunks#5204
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview Workflow chat streaming: failed SSE reader: Reviewed by Cursor Bugbot for commit dc1cf47. Configure here. |
Greptile SummaryThis PR fixes two independent regressions introduced in #5196: an SSR crash caused by importing
Confidence Score: 5/5Safe to merge — both fixes are narrowly scoped, mechanically correct, and backed by new tests. The table-keys.ts extraction is a pure refactor with no logic changes; TypeScript enforces that all consumers updated correctly. The readSSELines change is a targeted loop-order fix with two purpose-built tests that directly exercise the previously broken path. The chat error deferral eliminates a double-flush with no observable behavior change. No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "fix(sse): process the final unterminated..." | Re-trigger Greptile |
…h works
The tables list page crashed at SSR ('tableKeys.list is not a function') because
tables/prefetch.ts (a server component) imported tableKeys from
hooks/queries/tables.ts — a 'use client' module whose exports resolve to
client-reference stubs on the server. Extract the key factory into
hooks/queries/utils/table-keys.ts (no 'use client'), mirroring folder-keys.ts,
and import it from there in the prefetch, hook, trigger, and consumers.
On an error 'final' event the reader stops via return true, so the post-loop flush is the single flush point. Defer the error append to after that flush (single flush, correct ordering) instead of flushing inside onEvent and again post-loop. No behavior change.
0d0d641 to
66dbf4e
Compare
readSSELines broke out of the read loop on 'done' without flushing the TextDecoder or processing the trailing buffer, so a final 'data:' line not terminated by a newline (and any buffered multi-byte character) was dropped. Flush the decoder on end-of-stream and process the remaining buffer. Addresses a Cursor Medium finding on the consolidated SSE reader.
|
@greptile review |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit dc1cf47. Configure here.
Summary
Two fixes, both off
staging:1. Tables list crash at SSR (regression from #5196)
The tables list page failed to load in staging with:
Cause:
tables/prefetch.tsis a server component, but it importedtableKeysfromhooks/queries/tables.ts, which carries'use client'. When a server module imports from a'use client'module, Next.js replaces the export with a client-reference stub in the server bundle — sotableKeys.listisundefinedat SSR. (The other three prefetch pages were fine because their key factories live in non-'use client'modules, e.g.folder-keys.ts.)Fix: Extract the key factory into
hooks/queries/utils/table-keys.ts(no'use client'), mirroring the existingfolder-keys.tspattern, and import it from there in the prefetch, the hook, the table trigger/poller, and the two consumers.tables.tsnow imports the factory instead of defining it.2. Redundant
flushChunks()on the SSE error path (chat.tsx)Addresses a Greptile P2 from the release PR. On an error
finalevent the reader stops (return true), so the post-loop flush is the single flush point. Defer the error append to after that flush — single flush, correct ordering — instead of flushing insideonEventand again post-loop. No behavior change.Type of Change
Testing
prefetch.test.ts(9 tests) green;tsc0 errors; Biome clean;check:react-querypasses.folder-keys.tspattern (pure non-'use client'module); CI's "Test and Build" exercises the realnext build/SSR path.Checklist