Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/router-core/src/ssr/ssr-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ class ScriptBuffer {

constructor(router: AnyRouter) {
this.router = router
// Copy INITIAL_SCRIPTS to avoid mutating the shared array
this._queue = INITIAL_SCRIPTS.slice()
// Copy INITIAL_SCRIPTS and trim to avoid unnecessary whitespace in HTML output
this._queue = INITIAL_SCRIPTS.map((s) => s.trim())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will not remove whitespace in between. we need proper minification. you can get this today if you minify your server build

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about .trim() not handling internal whitespace.

That said, the official docs recommend minify: false for the SSR build (for easier debugging), so relying on server-side minification to fix this feels like a workaround rather than a proper solution.

Since these scripts are machine-generated serialization injected into client-facing HTML (not server-executed code), would it make sense to do a lightweight regex-based cleanup directly in ScriptBuffer instead? Something like:

script.replace(/\n\s*\n/g, '\n').trim()

This keeps server builds debuggable while still producing clean HTML output. Happy to update the PR if you think this direction works.

}

enqueue(script: string) {
if (this._cleanedUp) return
this._queue.push(script)
this._queue.push(script.trim())
// If barrier is lifted, schedule injection (if not already scheduled)
if (this._scriptBarrierLifted && !this._pendingMicrotask) {
this._pendingMicrotask = true
Expand Down
Loading