Skip to content

perf(start-client-core): avoid unused middleware array - #8353

Open
LadyBluenotes wants to merge 3 commits into
mainfrom
perf/server-function-middleware-iteration
Open

perf(start-client-core): avoid unused middleware array#8353
LadyBluenotes wants to merge 3 commits into
mainfrom
perf/server-function-middleware-iteration

Conversation

@LadyBluenotes

@LadyBluenotes LadyBluenotes commented Sep 11, 2026

Copy link
Copy Markdown
Member

🎯 Changes

Use an indexed loop instead of map when registering server-function middleware. This avoids the unused result array and the iteration callback. Composition order, factory expansion, and sparse-array handling stay unchanged. The loop captures the initial array length, so entries appended during registration are not visited. Request execution is untouched.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes

    • Improved server-function middleware registration for consistent ordering and reliable handling of nested, frozen, empty, and sparse middleware lists.
    • Middleware added during registration is no longer unexpectedly included.
  • Tests

    • Added coverage for middleware concatenation, input preservation, and edge-case array behavior.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: c5a76a5c-2426-4207-87bd-3a2eb318c158

📥 Commits

Reviewing files that changed from the base of the PR and between ec6bd76 and 81414d8.

📒 Files selected for processing (1)
  • packages/start-client-core/src/createServerFn.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The middleware builder now uses forEach to flatten middleware arrays without retaining an unused array. Tests cover ordering, input preservation, frozen arrays, empty arrays, sparse arrays, and middleware appended during iteration. A patch changeset records the update.

Changes

Middleware registration

Layer / File(s) Summary
Middleware flattening and validation
packages/start-client-core/src/createServerFn.ts, packages/start-client-core/tests/createServerFn.test.ts, .changeset/start-middleware-registration.md
The builder uses forEach, skips sparse-array holes, ignores items appended during iteration, and preserves middleware flattening behavior. Tests cover array handling and input preservation. A patch changeset records the update.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to 81414

This is a localized performance cleanup with no remaining actionable merge risk.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the performance change: avoiding the unused middleware array in start-client-core.
Description check ✅ Passed The description includes all required sections, completed checklist items, testing information, and changeset information. It inaccurately says the implementation uses an indexed loop; the change uses…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
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.
✨ 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 perf/server-function-middleware-iteration

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.

@nx-cloud

nx-cloud Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 81414d8

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

☁️ Nx Cloud last updated this comment at 2026-09-12 00:53:25 UTC

@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

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

🟩 Patch bumps

Package Version Reason
@tanstack/history 1.162.3 → 1.162.4 Changeset
@tanstack/router-core 1.171.29 → 1.171.30 Changeset
@tanstack/start-client-core 1.170.29 → 1.170.30 Changeset
@tanstack/start-server-core 1.169.34 → 1.169.35 Changeset
@tanstack/react-router 1.170.35 → 1.170.36 Dependent
@tanstack/react-start 1.168.52 → 1.168.53 Dependent
@tanstack/react-start-client 1.168.33 → 1.168.34 Dependent
@tanstack/react-start-rsc 0.1.51 → 0.1.52 Dependent
@tanstack/react-start-server 1.167.40 → 1.167.41 Dependent
@tanstack/router-cli 1.167.35 → 1.167.36 Dependent
@tanstack/router-generator 1.167.35 → 1.167.36 Dependent
@tanstack/router-plugin 1.168.37 → 1.168.38 Dependent
@tanstack/router-vite-plugin 1.167.37 → 1.167.38 Dependent
@tanstack/solid-router 1.170.33 → 1.170.34 Dependent
@tanstack/solid-start 1.168.50 → 1.168.51 Dependent
@tanstack/solid-start-client 1.168.32 → 1.168.33 Dependent
@tanstack/solid-start-server 1.167.39 → 1.167.40 Dependent
@tanstack/start-plugin-core 1.171.42 → 1.171.43 Dependent
@tanstack/start-static-server-functions 1.167.34 → 1.167.35 Dependent
@tanstack/start-storage-context 1.167.31 → 1.167.32 Dependent
@tanstack/vue-router 1.170.32 → 1.170.33 Dependent
@tanstack/vue-start 1.168.49 → 1.168.50 Dependent
@tanstack/vue-start-client 1.167.35 → 1.167.36 Dependent
@tanstack/vue-start-server 1.167.39 → 1.167.40 Dependent

@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: 52cb70f718f1
  • Measured at: 2026-09-12T00:52:54.399Z
  • Baseline source: history:f021f6d1c6dc
  • Dashboard: bundle-size history

The following scenarios have bundle-size changes compared with the baseline:

Scenario Current (gzip) Initial (gzip) Raw Brotli Trend
react-start.full 100.0 KiB
0 B
99.9 KiB
-2 B
314.3 KiB
+4 B
86.7 KiB
+36 B
███████▁▁▁▁
react-start.rsbuild.full 103.4 KiB
0 B
103.2 KiB
0 B
324.9 KiB
+4 B
89.2 KiB
+31 B
███████▁▁▁▁
solid-start.full 51.4 KiB
+4 B
51.3 KiB
+2 B
153.3 KiB
+4 B
45.6 KiB
+40 B
▆▆▅▁▁▁▁▁▁▁▁█
vue-start.full 69.6 KiB
-1 B
69.5 KiB
+1 B
201.5 KiB
+4 B
61.8 KiB
+27 B
███████▁▁▁▁▁

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

pkg-pr-new Bot commented Sep 11, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

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

@tanstack/eslint-plugin-router

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

@tanstack/eslint-plugin-start

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-rsc

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: 81414d8

@codspeed-hq

codspeed-hq Bot commented Sep 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 180 untouched benchmarks


Comparing perf/server-function-middleware-iteration (ec6bd76) with main (dbf0bd9)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (05422da) during the generation of this report, so dbf0bd9 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@nx-cloud nx-cloud Bot left a comment

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.

Nx Cloud has identified a flaky task in your failed CI:

🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.

Nx Cloud View detailed reasoning in Nx Cloud ↗


🎓 Learn more about Self-Healing CI on nx.dev

@Sheraff

Sheraff commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

would a for loop be even better than using array methods?

@LadyBluenotes

Copy link
Copy Markdown
Member Author

would a for loop be even better than using array methods?

yeah youre right. ill update

@LadyBluenotes
LadyBluenotes force-pushed the perf/server-function-middleware-iteration branch 2 times, most recently from ce7bb7b to 50a4560 Compare September 11, 2026 20:38
@LadyBluenotes
LadyBluenotes force-pushed the perf/server-function-middleware-iteration branch from 50a4560 to ec6bd76 Compare September 11, 2026 23:46
forEach keeps the hole-skipping and length-snapshot semantics the tests
cover without the extra `in` check and length hoist, and it avoids the
result array that map allocated.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.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.

2 participants