Skip to content

Conversation

@schiller-manuel
Copy link
Contributor

@schiller-manuel schiller-manuel commented Oct 30, 2025

Summary by CodeRabbit

  • Refactor
    • Improved compilation robustness by making middleware handling optional and client-only, adding guards to skip undefined entries, and consolidating identifier processing to avoid runtime errors and prevent middleware-related code from running on server builds.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 30, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Reworked the compiler plugin to accept a Partial, add client-only middleware initialization (env === 'client'), and introduce defensive guards and local identifier handling across import resolution, call-expression collection, namespace resolution, and final transformation phases.

Changes

Cohort / File(s) Change Summary
Compiler middleware conditional logic
packages/start-plugin-core/src/start-compiler-plugin/compilers.ts
Switched from a concrete Identifiers object to Partial<Identifiers>; initialize createMiddleware and its identifier only when env === 'client'; added guards to skip undefined identifier entries; use local identifier vars instead of direct map access; update name/binding checks and push call paths to identifier.paths; iterate identifiers with null checks and call identifier.handleCallExpression in final transform.

Sequence Diagram(s)

sequenceDiagram
    participant Compiler
    participant Plugin
    participant Identifiers

    Compiler->>Plugin: compileStartOutputFactory(partialIdentifiers, env)
    alt env == 'client'
        Plugin->>Identifiers: createMiddleware()
        Identifiers-->>Plugin: add middleware identifier (identifier.paths)
    else env != 'client'
        Note over Plugin: middleware identifier not created
    end

    Plugin->>Plugin: import resolution (guard undefined identifiers)
    Plugin->>Plugin: collect call-expression paths -> push to identifier.paths
    Plugin->>Plugin: namespace/member resolution -> compare identifier.name, push paths
    Plugin->>Plugin: final transform -> for each identifier (skip undefined) call handleCallExpression
    Plugin-->>Compiler: transformed AST
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Attention areas:
    • Verify all null/undefined guards are correctly placed and exhaustive
    • Confirm middleware initialization is strictly client-only and doesn't leak into server builds
    • Ensure all uses of identifier.name, identifier.paths, and identifier.handleCallExpression follow the new local-variable pattern

Possibly related PRs

Poem

🐰 I hopped through ASTs with care,

client-side only, light as air,
guards in place, no server fright,
paths collected, names set right.
A little hop — the plugin's bright! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "fix: only run middleware compiler in client env" directly aligns with the primary changes described in the raw summary. The summary confirms that the main modification is adding conditional inclusion of createMiddleware only when env is 'client', along with supporting infrastructure changes like partial identifiers and null/undefined checks. The title is concise, specific, and clearly conveys the key fix without vague terms or unnecessary details.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0432e12 and c7cfa35.

📒 Files selected for processing (1)
  • packages/start-plugin-core/src/start-compiler-plugin/compilers.ts (6 hunks)

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

@nx-cloud
Copy link

nx-cloud bot commented Oct 30, 2025

View your CI Pipeline Execution ↗ for commit c7cfa35

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

☁️ Nx Cloud last updated this comment at 2025-10-30 21:52:38 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 30, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5703

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5703

@tanstack/eslint-plugin-router

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

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5703

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5703

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5703

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5703

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5703

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5703

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5703

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5703

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5703

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5703

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5703

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5703

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5703

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5703

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5703

commit: 0432e12

Copy link
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

🧹 Nitpick comments (1)
packages/start-plugin-core/src/start-compiler-plugin/compilers.ts (1)

116-116: Consider simplifying the return statement.

The return statement here returns the new array length from push(), which is unused. This works correctly but is slightly confusing.

Apply this diff for clarity:

-                  return identifier.paths.push(path)
+                  identifier.paths.push(path)
+                  return
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a62499 and 0432e12.

📒 Files selected for processing (1)
  • packages/start-plugin-core/src/start-compiler-plugin/compilers.ts (6 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript in strict mode with extensive type safety across the codebase

Files:

  • packages/start-plugin-core/src/start-compiler-plugin/compilers.ts
packages/{*-start,start-*}/**

📄 CodeRabbit inference engine (AGENTS.md)

Name and place Start framework packages under packages/-start/ or packages/start-/

Files:

  • packages/start-plugin-core/src/start-compiler-plugin/compilers.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Preview
  • GitHub Check: Test
🔇 Additional comments (3)
packages/start-plugin-core/src/start-compiler-plugin/compilers.ts (3)

26-42: LGTM! Correct use of Partial<Identifiers> for conditional inclusion.

The type change to Partial<Identifiers> correctly supports the conditional inclusion of createMiddleware, ensuring type safety when not all identifiers are present.


73-75: LGTM! Proper guards for optional identifiers.

The null/undefined checks at all three locations (import resolution, call expression handling, and transformation phase) correctly guard against missing identifiers when createMiddleware is excluded in server builds.

Also applies to: 95-97, 144-146


147-152: LGTM! Safe transformation with proper guards.

The transformation phase correctly accesses identifier.paths and identifier.handleCallExpression only after confirming the identifier exists, maintaining type safety throughout.

@schiller-manuel schiller-manuel force-pushed the start-compile-middleware branch from 0432e12 to c7cfa35 Compare October 30, 2025 21:45
@schiller-manuel schiller-manuel merged commit 0677c29 into main Oct 30, 2025
4 of 5 checks passed
@schiller-manuel schiller-manuel deleted the start-compile-middleware branch October 30, 2025 21:46
roduyemi pushed a commit to roduyemi/oss-router that referenced this pull request Nov 19, 2025
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