Skip to content
Source
Sign inSign up
TanStack/router

Child route's head affects the `document.title` after parent's `beforeLoad` throws #7635

Closedalex35mil(GitHub profile, opens in a new tab) opened this issue 0 comments

Which project does this relate to?

Router

Describe the bug

Scenario

Route tree:

__root
  _app        // parent route with beforeLoad + head
    child     // child route with head

The parent _app route throws from beforeLoad when ?fail=true.

From router source, when a parent beforeLoad throws:

  • descendant beforeLoads are skipped
  • descendant loaders are skipped
  • headMaxIndex is capped to the throwing route
  • only heads up to the throwing route should execute

So the child route's head should not affect the document after _app.beforeLoad throws.

On server, the title is correct. But on client, the document.title is set by the child component.

Complete minimal reproducer

https://github.com/alex35mil/tanstack-stale-child-head-after-beforeLoad-error

Steps to Reproduce the Bug

pnpm install
pnpm dev

Open:

http://127.0.0.1:3000/child?fail=false

The document title should be:

Child success title

Then navigate to:

http://127.0.0.1:3000/child?fail=true

The title should be App error title, but it's Child success title on the client.

Expected behavior

The title should be App error title when parent beforeLoad throws.

Screenshots or Videos

No response

Platform

  • Router / Start Version:
    "@tanstack/react-router": "1.170.15",
    "@tanstack/react-start": "1.168.25",
  • OS: macOS
  • Browser: Arc
  • Browser Version: 1.146.0
  • Bundler: vite
  • Bundler Version:
    "vite": "8.0.16",

Additional context

No response

Sign in to join this conversation.