Skip to content

fix(router-core): defer $_TSR teardown until DOMContentLoaded#7524

Merged
birkskyum merged 2 commits into
mainfrom
tsr-cleanup
Jun 2, 2026
Merged

fix(router-core): defer $_TSR teardown until DOMContentLoaded#7524
birkskyum merged 2 commits into
mainfrom
tsr-cleanup

Conversation

@birkskyum
Copy link
Copy Markdown
Member

@birkskyum birkskyum commented Jun 2, 2026

I'm experience an issue where the $_TSR is deleted too early, and ends up undefined. This is a small defensive change to hold it until the streaming has ended.

Summary by CodeRabbit

  • Bug Fixes
    • Improved server-side rendering stability by deferring cleanup until the DOM is fully loaded, ensuring hydration and streaming complete before teardown.
  • Chores
    • Bumped router-core with a patch release.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Defers removal of the _TSR global and self.$R['tsr'] until DOM is ready and both hydrated and streamEnded are true; adds a Changeset documenting a patch bump for @tanstack/router-core.

Changes

TSR Cleanup Deferment

Layer / File(s) Summary
TSR cleanup deferment and conditional state removal
packages/router-core/src/ssr/tsrScript.ts, .changeset/witty-tires-flow.md
Replaces immediate deletion of self.$_TSR and self.$R['tsr'] with a cleanup helper that deletes them only when self.$_TSR?.hydrated and self.$_TSR?.streamEnded are true; if document.readyState === 'loading', cleanup is registered on DOMContentLoaded with { once: true }. A Changeset entry records a patch bump and the teardown deferral.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I wait beneath the DOM's bright dome,
Till hydration greets the streaming home,
No hurried delete or reckless sweep,
I guard the state till both flags sleep,
Then hop and tidy — soft and neat.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(router-core): defer $_TSR teardown until DOMContentLoaded' directly and precisely describes the main change in the pull request, which is deferring the deletion of $_TSR until after the DOM is ready.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tsr-cleanup

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Jun 2, 2026

View your CI Pipeline Execution ↗ for commit 03e8e03

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 9m 25s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 58s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-02 12:09:36 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

🚀 Changeset Version Preview

1 package(s) bumped directly, 22 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/router-core 1.171.8 → 1.171.9 Changeset
@tanstack/react-router 1.170.10 → 1.170.11 Dependent
@tanstack/react-start 1.168.18 → 1.168.19 Dependent
@tanstack/react-start-client 1.168.7 → 1.168.8 Dependent
@tanstack/react-start-rsc 0.1.17 → 0.1.18 Dependent
@tanstack/react-start-server 1.167.13 → 1.167.14 Dependent
@tanstack/router-cli 1.167.12 → 1.167.13 Dependent
@tanstack/router-generator 1.167.12 → 1.167.13 Dependent
@tanstack/router-plugin 1.168.13 → 1.168.14 Dependent
@tanstack/router-vite-plugin 1.167.13 → 1.167.14 Dependent
@tanstack/solid-router 1.170.10 → 1.170.11 Dependent
@tanstack/solid-start 1.168.18 → 1.168.19 Dependent
@tanstack/solid-start-client 1.168.7 → 1.168.8 Dependent
@tanstack/solid-start-server 1.167.13 → 1.167.14 Dependent
@tanstack/start-client-core 1.170.6 → 1.170.7 Dependent
@tanstack/start-plugin-core 1.171.10 → 1.171.11 Dependent
@tanstack/start-server-core 1.169.8 → 1.169.9 Dependent
@tanstack/start-static-server-functions 1.167.11 → 1.167.12 Dependent
@tanstack/start-storage-context 1.167.10 → 1.167.11 Dependent
@tanstack/vue-router 1.170.10 → 1.170.11 Dependent
@tanstack/vue-start 1.168.17 → 1.168.18 Dependent
@tanstack/vue-start-client 1.167.11 → 1.167.12 Dependent
@tanstack/vue-start-server 1.167.13 → 1.167.14 Dependent

@birkskyum birkskyum changed the title fix: defer $_TSR teardown until DOMContentLoaded fix(router-core): defer $_TSR teardown until DOMContentLoaded Jun 2, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/witty-tires-flow.md:
- Line 5: The changeset text currently includes the identifier $_TSR which may
render poorly; update the string "defer $_TSR teardown until DOMContentLoaded"
to format the identifier as inline code by wrapping $_TSR in backticks (i.e. use
`$_TSR`) so the dollar sign and backslash display correctly in release notes and
avoid parsing issues.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 564f58e5-d76a-4d8f-bcaf-22485525fcc6

📥 Commits

Reviewing files that changed from the base of the PR and between 54b0d9a and 03e8e03.

📒 Files selected for processing (2)
  • .changeset/witty-tires-flow.md
  • packages/router-core/src/ssr/tsrScript.ts

Comment thread .changeset/witty-tires-flow.md Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

Bundle Size Benchmarks

  • Commit: c19ff644dcf7
  • Measured at: 2026-06-02T12:01:08.826Z
  • Baseline source: history:9a6c12596ff6
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend
react-router.minimal 87.25 KiB 0 B (0.00%) 87.12 KiB 273.94 KiB 75.84 KiB ███████▁▁▁▁
react-router.full 90.69 KiB 0 B (0.00%) 90.55 KiB 285.30 KiB 78.83 KiB ███████▁▁▁▁
solid-router.minimal 35.47 KiB 0 B (0.00%) 35.35 KiB 106.24 KiB 32.00 KiB ███████▁▁▁▁
solid-router.full 40.18 KiB 0 B (0.00%) 40.05 KiB 120.43 KiB 36.18 KiB ███████▁▁▁▁
vue-router.minimal 52.97 KiB 0 B (0.00%) 52.84 KiB 150.26 KiB 47.66 KiB ███████▁▁▁▁
vue-router.full 58.60 KiB 0 B (0.00%) 58.47 KiB 167.99 KiB 52.51 KiB ███████▁▁▁▁
react-start.minimal 101.88 KiB 0 B (0.00%) 101.74 KiB 322.26 KiB 88.15 KiB ███████▁▁▁▁
react-start.deferred-hydration 102.61 KiB 0 B (0.00%) 101.76 KiB 323.63 KiB 88.82 KiB ███████▁▁▁▁
react-start.full 105.26 KiB 0 B (0.00%) 105.12 KiB 332.57 KiB 91.09 KiB ███████▁▁▁▁
react-start.rsbuild.minimal 99.58 KiB 0 B (0.00%) 99.41 KiB 316.74 KiB 85.74 KiB ███████▁▁▄▄
react-start.rsbuild.full 102.85 KiB 0 B (0.00%) 102.68 KiB 327.13 KiB 88.45 KiB ███████▁▁▄▄
solid-start.minimal 49.58 KiB 0 B (0.00%) 49.45 KiB 152.31 KiB 43.78 KiB ███████▁▁▁▁
solid-start.deferred-hydration 52.84 KiB 0 B (0.00%) 49.51 KiB 160.35 KiB 46.76 KiB ███████▁▁▁▁
solid-start.full 55.37 KiB 0 B (0.00%) 55.24 KiB 169.24 KiB 48.76 KiB ███████▁▁▁▁

Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 2, 2026

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@7524

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@7524

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@7524

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@7524

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@7524

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@7524

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@7524

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@7524

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@7524

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@7524

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@7524

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@7524

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@7524

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@7524

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@7524

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@7524

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@7524

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@7524

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@7524

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@7524

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@7524

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@7524

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@7524

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@7524

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@7524

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@7524

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@7524

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@7524

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@7524

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@7524

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@7524

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@7524

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@7524

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@7524

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@7524

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@7524

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@7524

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@7524

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@7524

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@7524

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@7524

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@7524

commit: da9cd84

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jun 2, 2026

Merging this PR will not alter performance

✅ 5 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing tsr-cleanup (da9cd84) with main (9a6c125)2

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

  2. No successful run was found on main (54b0d9a) during the generation of this report, so 9a6c125 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@birkskyum birkskyum requested a review from schiller-manuel June 2, 2026 12:21
@birkskyum birkskyum merged commit b4cd5af into main Jun 2, 2026
20 checks passed
@birkskyum birkskyum deleted the tsr-cleanup branch June 2, 2026 20:29
schiller-manuel pushed a commit that referenced this pull request Jun 4, 2026
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant