Skip to content

fix default redirect method#1253

Open
BilalG1 wants to merge 6 commits intodevfrom
fix-default-redirect-method
Open

fix default redirect method#1253
BilalG1 wants to merge 6 commits intodevfrom
fix-default-redirect-method

Conversation

@BilalG1
Copy link
Copy Markdown
Collaborator

@BilalG1 BilalG1 commented Mar 13, 2026

Summary by CodeRabbit

  • Refactor
    • Adjusted internal default selection for redirect handling to improve consistency; no change to user-facing behavior or settings.
  • Tests
    • Updated end-to-end tests and helpers to explicitly set redirect behavior so test runs remain deterministic.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stack-auth-hosted-components Ready Ready Preview, Comment Mar 23, 2026 6:04pm
stack-backend Ready Ready Preview, Comment Mar 23, 2026 6:04pm
stack-dashboard Ready Ready Preview, Comment Mar 23, 2026 6:04pm
stack-demo Ready Ready Preview, Comment Mar 23, 2026 6:04pm
stack-docs Ready Ready Preview, Comment Mar 23, 2026 6:04pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 33e74ea1-0364-4866-b8d4-8c881b48cf78

📥 Commits

Reviewing files that changed from the base of the PR and between c0148dc and 4285cab.

📒 Files selected for processing (3)
  • apps/e2e/tests/general/cli.test.ts
  • apps/e2e/tests/js/inheritance.test.ts
  • apps/e2e/tests/js/js-helpers.ts
✅ Files skipped from review due to trivial changes (2)
  • apps/e2e/tests/general/cli.test.ts
  • apps/e2e/tests/js/js-helpers.ts

📝 Walkthrough

Walkthrough

Adjusted an intermediate default for this._redirectMethod in client-app-impl.ts from "none" to "window", and updated multiple e2e test helpers and tests to pass redirectMethod: "none" when constructing app instances; final behavior still yields "nextjs" for the Next platform when unset.

Changes

Cohort / File(s) Summary
Constructor Default Adjustment
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts
Changed the intermediate fallback for this._redirectMethod in the constructor from "none" to "window". Final assignment to "nextjs" remains when resolvedOptions.redirectMethod is falsy for the Next platform.
E2E Test updates
apps/e2e/tests/general/cli.test.ts, apps/e2e/tests/js/inheritance.test.ts, apps/e2e/tests/js/js-helpers.ts
Passed redirectMethod: "none" into StackAdminApp, StackClientApp, and StackServerApp constructor options across tests and test helpers; no other test logic or assertions changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit nudged a default with a grin,
"none" to "window" — a tiny spin,
Tests now whisper "none" on create,
Still "nextjs" waits at the final gate,
Hops of code, a soft drumbeat within. 🐇✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description contains only the repository template comment with no substantive content about the changes, objectives, or rationale for the fix. Add a detailed description explaining what the default redirect method issue was, why it needed to be fixed, and how the changes address it.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically identifies the main change: fixing the default redirect method behavior as shown in the code modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-default-redirect-method

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 13, 2026

Greptile Summary

This PR fixes the default redirectMethod for non-Next.js builds of the Stack SDK template, and bumps the sandbox iframe's ESM fallback version.

  • client-app-impl.ts: The default redirect method for non-Next.js platform builds was "none", which silently swallowed all redirect calls (returning early without navigating). This PR changes the default to "window", which correctly uses window.location.assign/replace for browser-based navigation. The change exploits the existing THIS_LINE_PLATFORM next build-time transformation: line 527 (with the // THIS_LINE_PLATFORM next marker) is stripped from non-Next.js builds, leaving line 526 as the sole assignment. On Next.js builds, both lines execute, but line 527 always overwrites line 526, so the Next.js default of "nextjs" is unaffected. The fix is correct and isolated to non-Next.js consumers.

  • dashboard-sandbox-host.tsx: The hardcoded esmFallbackVersion string (used as a CDN fallback URL when the primary esmVersion fails to load in the sandbox iframe) is bumped from "2.8.71" to "2.8.76", matching the current package version. This is routine maintenance.

Confidence Score: 5/5

  • This PR is safe to merge — it's a targeted bug fix with correct behavior across all platforms.
  • The redirectMethod change correctly leverages the existing THIS_LINE_PLATFORM build-time transformation to set the right defaults per platform ("window" for React/non-Next.js, "nextjs" for Next.js). Both values exist in the RedirectMethod type. No callers are affected and the behavior is additive (redirects now work instead of silently failing). The version bump is a straightforward maintenance update.
  • No files require special attention.

Important Files Changed

Filename Overview
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts Changes the default redirectMethod from "none" (silently ignores all redirects) to "window" (uses window.location) for non-Next.js platform builds. The THIS_LINE_PLATFORM next marker on line 527 causes that line to be stripped in non-Next.js builds, so line 526 is the effective default for those builds. Line 526 is dead code on Next.js (overwritten immediately by line 527) but correctly sets the fallback for React/non-Next.js builds.
apps/dashboard/src/components/commands/create-dashboard/dashboard-sandbox-host.tsx Bumps the hardcoded esmFallbackVersion from "2.8.71" to "2.8.76" to match the current package version, used as a CDN fallback URL when the primary version fails to load in the sandbox iframe.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Build template package"] --> B{Platform?}
    B -->|Next.js| C["Line 526: this._redirectMethod = redirectMethod || 'window'\nLine 527: this._redirectMethod = redirectMethod || 'nextjs'  ← kept"]
    B -->|React / non-Next.js| D["Line 526: this._redirectMethod = redirectMethod || 'window'\nLine 527 stripped by THIS_LINE_PLATFORM next"]
    C --> E["Final default: 'nextjs'"]
    D --> F["Final default: 'window' ← Fixed from 'none'"]
    E --> G["_redirectTo: uses Next.js router"]
    F --> H["_redirectTo: uses window.location.assign / replace"]
    style F fill:#22c55e,color:#fff
    style E fill:#3b82f6,color:#fff
Loading

Last reviewed commit: 7af1e8d

Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts (1)

526-527: Use nullish coalescing operator (??) instead of logical OR (||).

Both assignments use the || operator, which will apply the default value for any falsy input (including 0, false, "", etc.), not just null or undefined. While this may not cause issues in practice given the expected types, it violates the project's coding guideline and could mask bugs if unexpected falsy values are passed.

♻️ Refactor to use `??` operator
-    this._redirectMethod = resolvedOptions.redirectMethod || "window";
+    this._redirectMethod = resolvedOptions.redirectMethod ?? "window";
     this._redirectMethod = resolvedOptions.redirectMethod || "nextjs"; // THIS_LINE_PLATFORM next

Note: Line 527 should also be updated similarly, though it's not part of this PR's changes:

     this._redirectMethod = resolvedOptions.redirectMethod ?? "window";
-    this._redirectMethod = resolvedOptions.redirectMethod || "nextjs"; // THIS_LINE_PLATFORM next
+    this._redirectMethod = resolvedOptions.redirectMethod ?? "nextjs"; // THIS_LINE_PLATFORM next

As per coding guidelines: "Unless very clearly equivalent from types, prefer explicit null/undefinedness checks over boolean checks, e.g., foo == null instead of !foo."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts`
around lines 526 - 527, The two assignments setting this._redirectMethod
currently use the logical OR operator with resolvedOptions.redirectMethod (e.g.,
this._redirectMethod = resolvedOptions.redirectMethod || "window" and the
duplicate line setting "nextjs"); change them to use the nullish coalescing
operator so the default is only applied when resolvedOptions.redirectMethod is
null or undefined (i.e., replace the `||` usage with `??` for the occurrence
referencing resolvedOptions.redirectMethod and update the second occurrence as
well), ensuring references to the _redirectMethod field and
resolvedOptions.redirectMethod remain unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts`:
- Around line 526-527: The two assignments setting this._redirectMethod
currently use the logical OR operator with resolvedOptions.redirectMethod (e.g.,
this._redirectMethod = resolvedOptions.redirectMethod || "window" and the
duplicate line setting "nextjs"); change them to use the nullish coalescing
operator so the default is only applied when resolvedOptions.redirectMethod is
null or undefined (i.e., replace the `||` usage with `??` for the occurrence
referencing resolvedOptions.redirectMethod and update the second occurrence as
well), ensuring references to the _redirectMethod field and
resolvedOptions.redirectMethod remain unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e3cc8975-de0b-4735-aec4-2cf0bb74649e

📥 Commits

Reviewing files that changed from the base of the PR and between 46cacd4 and 7af1e8d.

📒 Files selected for processing (1)
  • packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts

Copy link
Copy Markdown
Contributor

@N2D4 N2D4 left a comment

Choose a reason for hiding this comment

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

what does this do? why is this useful?

@github-actions github-actions bot assigned BilalG1 and unassigned N2D4 Mar 21, 2026
@BilalG1
Copy link
Copy Markdown
Collaborator Author

BilalG1 commented Mar 23, 2026

what does this do? why is this useful?

this is for non next.js frameworks where if developer doesn't specify a redirectMethod then redirects currently do nothing by default.

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.

2 participants