Repository navigation
fix(react-router): avoid unhandled rejections in turbo-stream decode on stream error - #15765
Conversation
|
Pushed a follow-up in 0de8461 to simplify completion handling and cover an adjacent error path. The original patch handles the reported unhandled completion rejections. The decoder also had a pre-existing problem when a deferred line was malformed or referenced an unknown ID: the catch handler rejected the private The follow-up removes that redundant private completion promise and uses the I replaced the timing-based rejection tests with eight isolated subprocess regressions covering network errors, aborts, unknown deferred IDs, and malformed JSON, with completion both ignored and observed. All eight failed against the original main decoder and pass with this fix; the relevant vendor, Authored by an AI agent on behalf of @brophdawg11 |
brophdawg11
left a comment
There was a problem hiding this comment.
Reviewed the decoder completion change and the updated main integration. Decoder failures remain visible to callers awaiting done or deferred values, while ignored completion is handled. The isolated regressions cover network, abort, unknown deferred ID, and malformed JSON failures. All 308 relevant tests, package build, and typecheck passed locally on the updated branch.
Authored by an AI agent on behalf of @brophdawg11
Fixes #15764
Root Cause
In
packages/react-router/vendor/turbo-stream-v2/turbo-stream.ts, whendecode()encountered a stream error after the initial chunk:done.reject(reason)rejecteddone.promise, which had no rejection handler attached on theelsebranch becausedonePromisewas reassigned to the.catch(...)chain.donePromise.then(() => reader.closed)was returned directly asdone, so callers that only readdecoded.valuewithout awaitingdecoded.done(such as single fetch) triggered a second unhandled rejection whenreader.closedrejected.Changes
.catch(() => {})handlers todone.promiseand the returnedfinishedpromise indecode()so stream errors do not trigger unhandled rejections whendecoded.doneis not awaited, while callers that awaitdecoded.donestill receive the rejection.packages/react-router/__tests__/vendor/turbo-stream-test.ts.Verification
pnpm test packages/react-router/__tests__/vendor/turbo-stream-test.ts(240/240 passed)pnpm exec eslint packages/react-router/vendor/turbo-stream-v2/turbo-stream.ts packages/react-router/__tests__/vendor/turbo-stream-test.ts(0 errors)pnpm exec prettier --check packages/react-router/vendor/turbo-stream-v2/turbo-stream.ts packages/react-router/__tests__/vendor/turbo-stream-test.ts(passed)pnpm --filter react-router typecheck(passed)