Skip to content

Rejections set document title#743

Merged
stackoverfloweth merged 6 commits intomainfrom
rejection-setTitle
Mar 23, 2026
Merged

Rejections set document title#743
stackoverfloweth merged 6 commits intomainfrom
rejection-setTitle

Conversation

@stackoverfloweth
Copy link
Copy Markdown
Contributor

this PR adds the setTitle paradigm to rejections that mostly mirrors how routes can set document.title.

const rejection = createRejection(...)

rejection.setTitle(() => 'My Title')

unlike route, rejection doesn't have title: Promise<string | undefined> because there's no good point to convert that from getRoute() to an executed promise. Route does this when it gets translated from Route to ResolvedRoute, but we don't have the concept of ResolvedRejection.

the arguments are also different. Rejection setTitle callback is given only SetRejectionTitleContext , which looks like

export type SetRejectionTitleContext = {
  to: ResolvedRoute | null,
  from: ResolvedRoute | null,
}

Note that to and from are only populated when the rejection happens as part of navigation. If the rejection is the result of router.reject(...), then both to and from will be null.

@stackoverfloweth stackoverfloweth self-assigned this Mar 20, 2026
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 20, 2026

Deploy Preview for kitbag-router ready!

Name Link
🔨 Latest commit 6eed9ab
🔍 Latest deploy log https://app.netlify.com/projects/kitbag-router/deploys/69c1470814a8ca000724d12b
😎 Deploy Preview https://deploy-preview-743--kitbag-router.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

rejection?: Rejection | null,
}

export function setDocumentTitle({ to = null, from = null, rejection = null }: SetDocumentTitleContext): void {
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.

I'm surprised to see from being passed here but not used for the route version. IMO we might want to standardize this around calling getTitle on both rather than using to.title and rejection.getTitle. just for consistency.

Also I think we should separate out the logic for determining what the title should be and setting the document title. This utility is doing double duty.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pivoted this PR quite a bit, I don't think this still applies but I'll leave it open for you to make that call

@stackoverfloweth stackoverfloweth merged commit 6882c30 into main Mar 23, 2026
6 checks passed
@stackoverfloweth stackoverfloweth deleted the rejection-setTitle branch March 23, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants