Skip to content

fix: use Response.redirect in redirectToPreviewURL#134

Closed
angeloashmore wants to merge 1 commit intomainfrom
fix/redirect-to-preview-url
Closed

fix: use Response.redirect in redirectToPreviewURL#134
angeloashmore wants to merge 1 commit intomainfrom
fix/redirect-to-preview-url

Conversation

@angeloashmore
Copy link
Copy Markdown
Member

@angeloashmore angeloashmore commented Mar 31, 2026

Resolves:

Description

redirectToPreviewURL was using Next.js's redirect() from next/navigation, which throws internally to signal a redirect. This is incompatible with Route Handlers that need to return a Response. Switching to Response.redirect() makes the function return a proper response object and removes the dependency on Next.js internals.

Checklist

  • A comprehensive Linear ticket, providing sufficient context and details to facilitate the review of the PR, is linked to the PR.
  • If my changes require tests, I added them.
  • If my changes affect backward compatibility, it has been discussed.
  • If my changes require an update to the CONTRIBUTING.md guide, I updated it.

Preview

How to QA 1


Note

Medium Risk
Changes the exported function’s return type and redirect mechanism, which may affect consumers relying on Next.js redirect() semantics or expecting a never-returning helper.

Overview
redirectToPreviewURL now returns a Response using Response.redirect(...) (307) rather than calling Next.js redirect() from next/navigation.

This updates the function signature from Promise<never> to Promise<Response> and constructs an absolute redirect target via new URL(previewURL, request.url) to be compatible with Route Handlers.

Written by Cursor Bugbot for commit 9441cc3. This will update automatically on new commits. Configure here.

Footnotes

  1. Please use these labels when submitting a review:
    ❓ #ask: Ask a question.
    💡 #idea: Suggest an idea.
    ⚠️ #issue: Strongly suggest a change.
    🎉 #nice: Share a compliment.

…irectToPreviewURL

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

(await draftMode()).enable();

redirect(previewURL);
return Response.redirect(new URL(previewURL, request.url), 307);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Base path redirect handling regressed

Medium Severity

Response.redirect(new URL(previewURL, request.url), 307) builds a raw URL and bypasses Next.js redirect normalization. When the app uses a basePath, redirects based on previewURL can resolve outside that prefix, sending users to the wrong path and causing preview routes to fail.

Fix in Cursor Fix in Web

@angeloashmore angeloashmore marked this pull request as draft April 1, 2026 01:47
@angeloashmore
Copy link
Copy Markdown
Member Author

This PR is no longer needed. The underlying fix was done in #133.

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.

1 participant