fix(router): core trim whitespace from SSR dehydrated script output#7081
fix(router): core trim whitespace from SSR dehydrated script output#7081canmi21 wants to merge 1 commit intoTanStack:mainfrom
Conversation
📝 WalkthroughWalkthroughUpdated the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsTimed out fetching pipeline failures after 30000ms Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
View your CI Pipeline Execution ↗ for commit b31163d
☁️ Nx Cloud last updated this comment at |
Bundle Size Benchmarks
Trend sparkline is historical gzip bytes ending with this PR measurement; lower is better. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/router-core/src/ssr/ssr-server.ts (1)
77-83: Harden concatenation boundaries after trimming script chunks.Line 78 and Line 83 remove trailing newlines; combined with
takeAll()using';'separators, a chunk ending in// ...can comment out the next fragment. Keep trimming, but make concatenation newline-safe (and skip empty trimmed chunks).Proposed patch
enqueue(script: string) { if (this._cleanedUp) return - this._queue.push(script.trim()) + const trimmed = script.trim() + if (!trimmed) return + this._queue.push(trimmed) // If barrier is lifted, schedule injection (if not already scheduled) if (this._scriptBarrierLifted && !this._pendingMicrotask) { this._pendingMicrotask = true queueMicrotask(() => { this._pendingMicrotask = false this.injectBufferedScripts() }) } } takeAll() { const bufferedScripts = this._queue this._queue = [] if (bufferedScripts.length === 0) { return undefined } // Optimization: if only one script, avoid join if (bufferedScripts.length === 1) { - return bufferedScripts[0] + ';document.currentScript.remove()' + return bufferedScripts[0] + '\n;document.currentScript.remove()' } // Append cleanup script and join - avoid push() to not mutate then iterate - return bufferedScripts.join(';') + ';document.currentScript.remove()' + return bufferedScripts.join(';\n') + '\n;document.currentScript.remove()' }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/router-core/src/ssr/ssr-server.ts` around lines 77 - 83, Trimmed script chunks currently get concatenated with a bare ';' in takeAll, which lets a trailing '//' comment in one chunk swallow the next; update enqueue/INITIAL_SCRIPTS handling to skip empty trimmed chunks (don't push ''), and change the concatenation in takeAll to join using a newline-safe boundary (e.g., ';\n' or '\n') so fragments can't comment out following code; reference _queue, enqueue, INITIAL_SCRIPTS and takeAll when making these changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/router-core/src/ssr/ssr-server.ts`:
- Around line 77-83: Trimmed script chunks currently get concatenated with a
bare ';' in takeAll, which lets a trailing '//' comment in one chunk swallow the
next; update enqueue/INITIAL_SCRIPTS handling to skip empty trimmed chunks
(don't push ''), and change the concatenation in takeAll to join using a
newline-safe boundary (e.g., ';\n' or '\n') so fragments can't comment out
following code; reference _queue, enqueue, INITIAL_SCRIPTS and takeAll when
making these changes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b895588b-afbe-4ed4-9fd7-c0ff5a259211
📒 Files selected for processing (1)
packages/router-core/src/ssr/ssr-server.ts
Fix: #6947
Summary by CodeRabbit