feat: add redirect() helper for loaders - #43
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 2 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Loaders can now call redirect(url, status?) to send the browser to a different URL. On cold loads the server responds with the redirect status + Location header directly. On client-side fragment navigation the runtime receives an x-brandy-redirect response header and calls location.assign() so the full page is replaced at the destination URL. RedirectError bypasses error and not-found boundaries — it always propagates out of loaders without invoking error.tsx or not-found.tsx. The README documents the canonical loader-based auth pattern (redirect in a layout loader) and explicitly notes that a middleware system was deliberately not added. Fixes #15 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
cbe1ebc to
4247138
Compare
Summary
redirect(url, status?)helper that can be called from anyload()function (layout or page) to redirect the browser to another URLLocationheader directly; the browser follows it before any HTML is renderedx-brandy-redirectresponse header and the client runtime callslocation.assign(), replacing the current page at the destination URLredirect()throws aRedirectErrorthat bypasses error and not-found boundaries — it always propagates out without invoking anyerror.tsxornot-found.tsxRedirectRenderedRoutevariant (kind: "redirect") to theRenderedRouteunion typeWhat this enables
The idiomatic auth pattern for protected subtrees is a redirect in the nearest layout loader:
This covers every route under
dashboard/without repeating the guard in each page — the same scope that middleware would cover, with no separate execution context.Test plan
redirect()in a layout loader returns{ kind: "redirect" }fromrenderFullMatch(cold load)redirect()in a page loader returns{ kind: "redirect" }with the correct status coderedirect()in a layout loader returns{ kind: "redirect" }fromrenderFragmentMatch(soft nav)redirect()bypassesrenderErrorerror boundariesLocationheaderx-brandy-redirectheaderFixes #15
🤖 Generated with Claude Code