Repository navigation
fix(ssr): avoid pipeThrough(new TextEncoderStream()) in inline script to prevent Chrome iOS crash (#15486) - #15728
Closed
DoctorGuidance wants to merge 1 commit into
Conversation
…vent Chrome iOS crash (remix-run#15486)
Contributor
|
closing for the same reason #15487 was closed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #15486
Problem
In React Router 8's
<Scripts />component, the initial inline SSR script sets up the streaming handoff via:In Chrome Mobile iOS (and other WKWebView-based apps like Google Search), Chrome injects JavaScript via
WKUserScriptsatdocumentStartthat intercepts or wrapsReadableStream.prototype.pipeThroughandTextEncoderStream. This causes mutual recursion between injected handlers (Tk↔Rk), which overflows WKWebView's restricted JS call stack and throwsRangeError: Maximum call stack size exceeded.Because this error occurs in the first inline script of the page:
window.__reactRouterContext.streamandstreamControllerare never initialized.<script>tags from<StreamTransfer>fail withTypeError: Cannot read properties of undefined (reading 'enqueue').Solution
Replace
pipeThrough(new TextEncoderStream())with a manualTextEncoderwrapper directly inside theReadableStreamstart handler. This eliminates bothpipeThroughandTextEncoderStreamfrom the inline script while preserving the exact sameReadableStream<Uint8Array>output andenqueue/close/errorcontroller contract for single fetch streaming:Testing
packages/react-router/__tests__/dom/ssr/components-test.tsxverifying the inline SSR script renders withoutpipeThroughorTextEncoderStream.components-test.tsxand verified all 25 SSR and hydration tests pass.tsc --noEmit) passes with zero errors.