Skip to content

refactor(router-core): redirect doesn't need to create an empty object for headers init#5076

Merged
Sheraff merged 1 commit intomainfrom
refactor-router-core-redirect-empty-headers
Sep 3, 2025
Merged

refactor(router-core): redirect doesn't need to create an empty object for headers init#5076
Sheraff merged 1 commit intomainfrom
refactor-router-core-redirect-empty-headers

Conversation

@Sheraff
Copy link
Contributor

@Sheraff Sheraff commented Sep 3, 2025

Summary by CodeRabbit

  • Refactor

    • Streamlined header initialization in redirect handling to rely on default behavior when no headers are provided.
    • Improves consistency and reduces implicit assumptions in header processing without altering existing behavior.
  • Chores

    • Minor internal cleanup to align with standard header handling patterns.

No functional changes are expected for end-users; redirects and related headers continue to behave as before.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 3, 2025

Walkthrough

Adjusted header initialization in redirect logic to call new Headers(opts.headers) instead of providing an empty object fallback. No public API signatures or control flow were changed.

Changes

Cohort / File(s) Summary
Router redirect header initialization
packages/router-core/src/redirect.ts
Changed Headers construction from new Headers(opts.headers

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

package: router-core

Poem

A hop to Headers, light and neat,
No empty basket at my feet—
If none are passed, I won’t insist,
I’ll sniff the breeze of undefined mist.
With Location set, I’m on my way,
A redirect rabbit—swift getaway! 🐇➡️

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-router-core-redirect-empty-headers

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nx-cloud
Copy link

nx-cloud bot commented Sep 3, 2025

View your CI Pipeline Execution ↗ for commit a989703

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

☁️ Nx Cloud last updated this comment at 2025-09-03 10:46:37 UTC

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: 0

🧹 Nitpick comments (2)
packages/router-core/src/redirect.ts (2)

75-75: Guard against accidental null with nullish coalescing

Using ?? preserves the “no extra allocation” goal while safely handling unexpected null values that might slip in from parseRedirect(obj) or external JS callers.

-  const headers = new Headers(opts.headers)
+  const headers = new Headers(opts.headers ?? undefined)

76-78: Use has for clarity when checking Location header

headers.has('Location') is more idiomatic than comparing get(...) === null.

-  if (opts.href && headers.get('Location') === null) {
+  if (opts.href && !headers.has('Location')) {
     headers.set('Location', opts.href)
   }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bc5e78f and a989703.

📒 Files selected for processing (1)
  • packages/router-core/src/redirect.ts (1 hunks)
⏰ 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 (1)
packages/router-core/src/redirect.ts (1)

75-83: Approve: passing undefined for headers is safe

Ripgrep search found no occurrences of headers: null, confirming no callers rely on null. The ?? undefined guard preserves behavior and avoids an extra allocation.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 3, 2025

More templates

@tanstack/arktype-adapter

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

@tanstack/directive-functions-plugin

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

@tanstack/eslint-plugin-router

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

@tanstack/history

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-plugin

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/server-functions-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-plugin

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-server-functions-client

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

@tanstack/start-server-functions-fetcher

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

@tanstack/start-server-functions-server

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/zod-adapter

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

commit: a989703

@Sheraff Sheraff merged commit 777e152 into main Sep 3, 2025
6 checks passed
@Sheraff Sheraff deleted the refactor-router-core-redirect-empty-headers branch September 3, 2025 19:48
naoya7076 pushed a commit to naoya7076/router that referenced this pull request Feb 15, 2026
…t for headers init (TanStack#5076)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Refactor**
* Streamlined header initialization in redirect handling to rely on
default behavior when no headers are provided.
* Improves consistency and reduces implicit assumptions in header
processing without altering existing behavior.

* **Chores**
* Minor internal cleanup to align with standard header handling
patterns.

No functional changes are expected for end-users; redirects and related
headers continue to behave as before.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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