Skip to content

refactor(router-core): avoid creating promises when not necessary#7582

Merged
Sheraff merged 1 commit into
mainfrom
refactor-router-core-promise-resolve-into-queue-microtask
Jun 7, 2026
Merged

refactor(router-core): avoid creating promises when not necessary#7582
Sheraff merged 1 commit into
mainfrom
refactor-router-core-promise-resolve-into-queue-microtask

Conversation

@Sheraff
Copy link
Copy Markdown
Collaborator

@Sheraff Sheraff commented Jun 7, 2026

Summary by CodeRabbit

Refactor

  • Optimized microtask scheduling mechanisms in browser history throttling and router navigation cleanup for improved internal performance.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 7, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2ea8d173-872e-4886-8335-93c348bd3487

📥 Commits

Reviewing files that changed from the base of the PR and between 689d88e and 098e764.

📒 Files selected for processing (2)
  • packages/history/src/index.ts
  • packages/router-core/src/router.ts

📝 Walkthrough

Walkthrough

History and router modules optimize microtask scheduling by replacing Promise.resolve().then() with queueMicrotask() for deferred operations, and router navigation early-exit branches now return undefined instead of resolved promises, eliminating unnecessary promise allocation for non-navigating paths.

Changes

Microtask Scheduling and Navigation Optimization

Layer / File(s) Summary
History throttling mechanism
packages/history/src/index.ts
scheduled variable changes from Promise<void> to boolean flag; the deferred flush trigger switches from Promise.resolve().then(() => flush()) to queueMicrotask(() => flush()), with reset logic updated accordingly.
Router microtask scheduling and navigation exits
packages/router-core/src/router.ts
buildAndCommitLocation cleanup uses queueMicrotask() instead of Promise.resolve().then(); navigate early-exit branches for dangerous protocols, external blockers, and reload operations now return undefined instead of Promise.resolve().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Microtasks now queue up fast,
No more promises in the past,
With boolean flags so lean and true,
History and router dance anew—
Scheduling optimized through and through! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the changeset: replacing Promise-based microtask scheduling with more direct mechanisms (queueMicrotask and returning undefined instead of Promise.resolve()).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ 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 refactor-router-core-promise-resolve-into-queue-microtask

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 7, 2026

View your CI Pipeline Execution ↗ for commit 098e764

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 10m 3s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 2m 20s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-07 20:11:58 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 7, 2026

🚀 Changeset Version Preview

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

🟩 Patch bumps

Package Version Reason
@tanstack/react-router 1.170.15 → 1.170.16 Changeset
@tanstack/react-start 1.168.25 → 1.168.26 Dependent
@tanstack/react-start-client 1.168.13 → 1.168.14 Dependent
@tanstack/react-start-rsc 0.1.24 → 0.1.25 Dependent
@tanstack/react-start-server 1.167.19 → 1.167.20 Dependent

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 7, 2026

Bundle Size Benchmarks

  • Commit: 330f51583111
  • Measured at: 2026-06-07T20:02:57.498Z
  • Baseline source: history:689d88e04c48
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend
react-router.minimal 87.25 KiB +3 B (+0.00%) 87.11 KiB 273.59 KiB 75.96 KiB ▁███▃▃▃▃▃▃▃▄
react-router.full 90.98 KiB +2 B (+0.00%) 90.84 KiB 285.48 KiB 79.13 KiB ▄███▇▇▇▇▇▇▁▁
solid-router.minimal 35.49 KiB +3 B (+0.01%) 35.37 KiB 105.89 KiB 32.05 KiB ▁▆▆▆▇▇▇▇▇▇▇█
solid-router.full 40.54 KiB +2 B (+0.00%) 40.42 KiB 121.11 KiB 36.48 KiB ▁███▆▆▆▆▆▆▆▇
vue-router.minimal 52.97 KiB -2 B (-0.00%) 52.84 KiB 149.90 KiB 47.62 KiB ▁██████████▇
vue-router.full 58.96 KiB +2 B (+0.00%) 58.83 KiB 168.66 KiB 52.87 KiB ▁███▇▇▇▇▇▇▇█
react-start.minimal 101.88 KiB +7 B (+0.01%) 101.75 KiB 321.90 KiB 88.14 KiB ▁▇▇▇▆▆▆▆▆▆▆█
react-start.deferred-hydration 102.62 KiB +1 B (+0.00%) 101.77 KiB 323.28 KiB 88.85 KiB ▁███▅▅▅▅▅▅██
react-start.full 105.27 KiB +1 B (+0.00%) 105.13 KiB 331.84 KiB 91.03 KiB ▁▅▅▅▅▅████▃▃
react-start.rsbuild.minimal 99.59 KiB +9 B (+0.01%) 99.42 KiB 316.35 KiB 85.75 KiB ▁▆▆▆██████▄▆
react-start.rsbuild.minimal-iife 99.99 KiB +10 B (+0.01%) 99.83 KiB 317.29 KiB 86.07 KiB ▁▆▆▆██████▅▇
react-start.rsbuild.full 102.81 KiB 0 B (0.00%) 102.64 KiB 326.41 KiB 88.40 KiB ▃▄▄▄▅▅████▁
solid-start.minimal 49.61 KiB +2 B (+0.00%) 49.48 KiB 151.96 KiB 43.77 KiB ▁▆▆▆████████
solid-start.deferred-hydration 52.87 KiB +3 B (+0.01%) 49.53 KiB 159.99 KiB 46.69 KiB ▁▆▆▆▇▇▇▇▇▇▇█
solid-start.full 55.41 KiB +6 B (+0.01%) 55.28 KiB 169.00 KiB 48.89 KiB ▁▃▃▃▂▂▇▇▇▇▇█
vue-start.minimal 71.02 KiB +5 B (+0.01%) 70.89 KiB 207.04 KiB 62.93 KiB ▁▇▇▇▇▇▇▇▇▇▇█
vue-start.full 75.01 KiB +6 B (+0.01%) 74.88 KiB 219.68 KiB 66.40 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 7, 2026

More templates

@tanstack/arktype-adapter

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

@tanstack/eslint-plugin-router

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

@tanstack/eslint-plugin-start

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-rsc

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: 098e764

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jun 7, 2026

Merging this PR will not alter performance

✅ 6 untouched benchmarks


Comparing refactor-router-core-promise-resolve-into-queue-microtask (098e764) with main (689d88e)

Open in CodSpeed

@Sheraff Sheraff merged commit 5127d86 into main Jun 7, 2026
20 checks passed
@Sheraff Sheraff deleted the refactor-router-core-promise-resolve-into-queue-microtask branch June 7, 2026 20:37
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