Skip to content

fix(init-prompt): require StackProvider for all frameworks#1374

Merged
BilalG1 merged 4 commits into
devfrom
fix/init-prompt-stack-provider
Apr 24, 2026
Merged

fix(init-prompt): require StackProvider for all frameworks#1374
BilalG1 merged 4 commits into
devfrom
fix/init-prompt-stack-provider

Conversation

@BilalG1
Copy link
Copy Markdown
Collaborator

@BilalG1 BilalG1 commented Apr 23, 2026

Summary

  • The init prompt marked the StackProvider step as React only and placed it after the StackHandler step. Following it on a Next.js project produced a layout with no provider, so StackHandler crashed at runtime with useStackApp must be used within a StackProvider.
  • Make the provider step unconditional and move it ahead of the handler step so the dependency order matches the instruction order. Also quote the exact error message so the model won't skip it.

Test plan

  • Run npx @stackframe/stack-cli init (or the web flow) against a fresh Next.js app and confirm /handler/[...stack] renders without the useStackApp error.
  • Re-run against a Vite/React app to confirm the reordered instructions still produce a working setup.

Summary by CodeRabbit

  • Documentation
    • Added explicit global MCP config file path guidance for several coding agents.
    • Documented required provider configuration across supported frameworks.
    • Clarified where to place provider wrappers in root app layouts (including Next.js app/layout).
    • Reordered setup steps to surface the required "Wrap your app in a Stack provider" step and updated step numbering.

…React

The previous prompt marked the StackProvider step as 'React only' and
placed it after the StackHandler step. Following these instructions for
a Next.js project produced a layout without a provider, causing
StackHandler to crash at runtime with 'useStackApp must be used within a
StackProvider'.

Make the provider step unconditional, move it before the handler step so
the dependency order matches the instruction order, and call out the
exact error message so the model won't skip it.
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 23, 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 Apr 24, 2026 6:33pm
stack-backend Ready Ready Preview, Comment Apr 24, 2026 6:33pm
stack-dashboard Ready Ready Preview, Comment Apr 24, 2026 6:33pm
stack-demo Ready Ready Preview, Comment Apr 24, 2026 6:33pm
stack-docs Ready Ready Preview, Comment Apr 24, 2026 6:33pm
stack-preview-backend Ready Ready Preview, Comment Apr 24, 2026 6:33pm
stack-preview-dashboard Ready Ready Preview, Comment Apr 24, 2026 6:33pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 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: ea103e16-c7d8-4679-b59c-f2cf47fa14f3

📥 Commits

Reviewing files that changed from the base of the PR and between 0c668ba and 1841299.

📒 Files selected for processing (1)
  • packages/stack-shared/src/helpers/init-prompt.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/stack-shared/src/helpers/init-prompt.ts

📝 Walkthrough

Walkthrough

The init prompt in packages/stack-shared/src/helpers/init-prompt.ts was updated to include explicit global MCP config file paths for various coding agents and to reorganize provider guidance: adding a required "Wrap your app in a Stack provider" step (now step 3), removing the old React-only section, and renumbering subsequent steps (Suspense → 5, env var linking → 6).

Changes

Cohort / File(s) Summary
Init prompt (provider + MCP instructions)
packages/stack-shared/src/helpers/init-prompt.ts
Prompt text expanded with explicit global MCP configuration file paths for popular coding agents; provider guidance reorganized to require StackProvider/StackTheme wrapping across frameworks with Next.js app/layout.tsx and React/Vite root examples added; removed prior React-only provider section; step numbers adjusted (Suspense → 5, env var linking → 6).

Sequence Diagram(s)

(omitted — changes are prompt/text-only and do not introduce multi-component control flow)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • N2D4

Poem

🐰 I hopped through lines of guidance new,
Added paths and where providers go too.
Next layouts snug, roots wrapped tight,
Steps renumbered — all set right.
munches a carrot and scampers bright 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: making StackProvider required for all frameworks instead of React-only, which directly addresses the core issue fixed in this PR.
Description check ✅ Passed The description clearly explains the problem, solution, and includes a test plan with actionable steps. It adequately documents the fix despite the minimal template requirements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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/init-prompt-stack-provider

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 Apr 23, 2026

Greptile Summary

This PR fixes the init-prompt instructions that led to a runtime useStackApp must be used within a StackProvider error on Next.js by moving the StackProvider setup step ahead of the StackHandler step and removing the incorrect "React only" label so it applies to all frameworks. Step numbering is updated consistently throughout.

Confidence Score: 5/5

Safe to merge — the only remaining finding is a minor P2 import comment inconsistency that does not affect runtime behavior.

The fix is a targeted, correct reordering of prompt instructions with no logic changes. All remaining findings are P2 style suggestions.

No files require special attention.

Important Files Changed

Filename Overview
packages/stack-shared/src/helpers/init-prompt.ts Moves StackProvider step from last position ('React only') to step 3 (before StackHandler) and makes it unconditional for all frameworks, fixing a runtime crash on Next.js. Step numbers are updated consistently throughout.

Sequence Diagram

sequenceDiagram
    participant Dev as Developer
    participant Prompt as init-prompt instructions
    participant App as Next.js / React App

    Dev->>Prompt: Follow step 3 (StackProvider)
    Prompt->>App: Wrap root layout with StackProvider + StackTheme
    Dev->>Prompt: Follow step 4 (StackHandler)
    Prompt->>App: Add /handler/[...stack]/page.tsx using StackHandler
    Note over App: StackHandler finds StackProvider in tree ✓
    App-->>Dev: No "useStackApp must be used within a StackProvider" error
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: packages/stack-shared/src/helpers/init-prompt.ts
Line: 72-75

Comment:
**Import package not updated for all frameworks**

Step 3 now explicitly applies to all frameworks, but the import snippet still hard-codes `@stackframe/stack`. React/Vite users need `@stackframe/react` instead. Since step 1 already differentiates the package per framework, the provider import should mirror that or add a comment.

```suggestion
import { StackProvider, StackTheme } from "@stackframe/stack"; // or "@stackframe/react" for React/Vite
import { stackClientApp } from "../stack/client"; // adjust relative path
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(init-prompt): require StackProvider ..." | Re-trigger Greptile

Comment thread packages/stack-shared/src/helpers/init-prompt.ts
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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/stack-shared/src/helpers/init-prompt.ts`:
- Around line 68-87: Split the single Next.js-specific example into two short
examples: one for Next.js that imports StackProvider/StackTheme from
`@stackframe/stack` and shows passing stackServerApp (since layout.tsx is a server
component) and wrapping the <body>, and a separate React/Vite example that
imports from `@stackframe/react` and shows passing stackClientApp and wrapping the
root component (e.g., in main.tsx/App.tsx) rather than a <body>; update the text
to call out which package to install for each framework and ensure the symbols
StackProvider, StackTheme, stackServerApp, stackClientApp, and the React entry
points (main.tsx/App.tsx) are referenced so readers apply the correct import and
wrapper for their environment.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c65f1dc3-743e-4be3-b197-9cee2ce48619

📥 Commits

Reviewing files that changed from the base of the PR and between 94541c4 and b6a6802.

📒 Files selected for processing (1)
  • packages/stack-shared/src/helpers/init-prompt.ts

Comment thread packages/stack-shared/src/helpers/init-prompt.ts
Comment thread packages/stack-shared/src/helpers/init-prompt.ts
Comment thread packages/stack-shared/src/helpers/init-prompt.ts Outdated
@BilalG1 BilalG1 merged commit d1751a7 into dev Apr 24, 2026
32 checks passed
@BilalG1 BilalG1 deleted the fix/init-prompt-stack-provider branch April 24, 2026 19:27
@promptless
Copy link
Copy Markdown
Contributor

promptless Bot commented Apr 24, 2026

Promptless prepared a documentation update related to this change.

Triggered by PR #1374

Reordered the manual installation steps so "Add providers" (StackProvider) comes before "Set up authentication handlers" (StackHandler). Without this order, users following the docs would hit a runtime error: "useStackApp must be used within a StackProvider".

Review: Fix setup step ordering

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