Skip to content

fix: reduce loading latency on create-collection page#153

Merged
yash-pouranik merged 4 commits into
mainfrom
v0/dashboard-loading-slow-4a22ea74
May 7, 2026
Merged

fix: reduce loading latency on create-collection page#153
yash-pouranik merged 4 commits into
mainfrom
v0/dashboard-loading-slow-4a22ea74

Conversation

@yash-pouranik
Copy link
Copy Markdown
Collaborator

@yash-pouranik yash-pouranik commented May 5, 2026

Problem

The /create-collection page was slow to appear for two compounding reasons:

  1. CSRF token lazy-fetch added a hidden round-trip on first submitcsrfToken started as null, so the request interceptor in api.js fired a blocking GET /api/auth/csrf-token before every first mutating request.
  2. No loading state on the Ref-picker collections fetch — the useEffect in CreateCollection fetched project collections silently, leaving Ref dropdown in an empty/broken state until the request completed with no user feedback.

Changes

src/utils/api.js

  • Eagerly prefetch the CSRF token when the module loads by starting fetchCsrfToken() immediately and storing the Promise.
  • The request interceptor now awaits the in-flight promise instead of spawning a new fetch, eliminating the extra round-trip on first form submit.

src/pages/CreateCollection.jsx

  • Added collectionsLoading state that starts true and becomes false when the project fetch resolves.
  • Both Ref picker <select> elements (direct field refs and array item refs) are now disabled while loading and show "Loading collections…" as the placeholder option.
  • collectionsLoading is threaded through all recursive FieldRow renders so nested pickers also reflect the loading state.

Summary by CodeRabbit

  • Improvements
    • Collection pickers now show explicit loading and error states ("Loading collections…", "Failed to load"), disable selection while unavailable, and apply this behavior to nested/ref fields.
    • Request handling improved to eagerly obtain CSRF tokens and better coordinate token fetching for mutating requests, improving reliability.

Parallelize project data fetch and eager CSRF token prefetch.

Co-authored-by: Yash Pouranik <172860064+yash-pouranik@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to reduce perceived latency on the web dashboard’s /create-collection page by (1) removing a hidden “first-submit” CSRF-token round-trip and (2) adding an explicit loading state for the Ref collection pickers while project collections are fetched.

Changes:

  • Web dashboard: eagerly prefetch CSRF token on module load and reuse the in-flight promise in the request interceptor.
  • Web dashboard: introduce collectionsLoading state and disable/show “Loading collections…” for Ref pickers (including nested rows) until collections load.
  • Monorepo root: adds several frontend dependencies to the root package.json and updates package-lock.json accordingly.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
package.json Adds multiple frontend dependencies at the monorepo root.
package-lock.json Updates resolved dependency graph; introduces duplicate lucide-react installs.
apps/web-dashboard/src/utils/api.js Eager CSRF prefetch + interceptor waits on shared promise.
apps/web-dashboard/src/pages/CreateCollection.jsx Adds collections loading state; disables Ref pickers while loading and propagates state to nested FieldRows.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 32 to 35
if (!csrfToken) {
csrfToken = await fetchCsrfToken();
// Wait for the in-flight eager fetch instead of spawning a new one.
csrfToken = await (csrfTokenPromise ?? fetchCsrfToken());
}
// Fetch existing collections for Ref picker — runs immediately on mount
// so it fires in parallel with any other in-flight requests.
useEffect(() => {
let isMounted = true;
Comment thread package.json Outdated
Comment on lines +19 to +23
"dependencies": {
"path": "^0.12.7"
"axios": "^1.16.0",
"lucide-react": "^1.14.0",
"path": "^0.12.7",
"react": "^19.2.5",
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 52829138-4b29-4b63-9789-9b1f445b7a0c

📥 Commits

Reviewing files that changed from the base of the PR and between 89e3554 and 54f0a25.

📒 Files selected for processing (1)
  • apps/web-dashboard/src/pages/CreateCollection.jsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web-dashboard/src/pages/CreateCollection.jsx

📝 Walkthrough

Walkthrough

Adds collectionsLoading/collectionsError state in CreateCollection and threads them through FieldRow so Ref pickers disable and show loading/error placeholders; concurrently, api.js starts an eager module-level csrfTokenPromise and makes the request interceptor await or recreate that promise for mutating requests.

Changes

Collections Loading State & CSRF Fetch

Layer / File(s) Summary
FieldRow prop contract
apps/web-dashboard/src/pages/CreateCollection.jsx
FieldRow signature extended to accept collectionsLoading and collectionsError props.
CreateCollection loading state & effect
apps/web-dashboard/src/pages/CreateCollection.jsx
Adds collectionsLoading (initially true) and collectionsError; fetch effect clears prior state, sets loading false in finally, and passes state to top-level FieldRow.
Nested Ref picker threading
apps/web-dashboard/src/pages/CreateCollection.jsx
Recursive FieldRow calls for Object sub-fields and Array item Object sub-fields forward collectionsLoading/collectionsError.
Ref picker UI states
apps/web-dashboard/src/pages/CreateCollection.jsx
Top-level and Array-item Ref <select>s disable when loading/error and show conditional placeholder text ("Loading collections…", "Failed to load", or "Select collection...").
CSRF token eager fetch & reset
apps/web-dashboard/src/utils/api.js
Adds csrfTokenPromise, starts fetchCsrfToken() at module init, and clears the promise on fetch failure so subsequent requests can retry.
Request interceptor CSRF await
apps/web-dashboard/src/utils/api.js
Mutating requests await csrfTokenPromise when csrfToken is missing; if the promise was cleared, the interceptor creates a fresh fetch promise before awaiting.
Response interceptor (unchanged)
apps/web-dashboard/src/utils/api.js
No changes to 401 refresh flow or 403 upgrade modal handling.

Sequence Diagram

sequenceDiagram
  participant Client
  participant Interceptor
  participant csrfModule
  participant Server
  Client->>Interceptor: send mutating request
  alt csrfToken available
    Interceptor->>Server: inject X-CSRF-Token and forward
  else csrfToken missing
    Interceptor->>csrfModule: await csrfTokenPromise (start new if null)
    csrfModule-->>Interceptor: returns token
    Interceptor->>Server: inject X-CSRF-Token and forward
  end
  Server-->>Client: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through props to quiet each select,
Patience in placeholders when collections aren't set,
A token promise raced at module dawn,
Requests now wait till CSRF is drawn,
Nesting and promises stitched up neat.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: addressing slow initial load on the create-collection page through CSRF token prefetching and collections loading state.
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 v0/dashboard-loading-slow-4a22ea74

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web-dashboard/src/utils/api.js`:
- Around line 25-35: The request interceptor can get stuck using a settled
promise that resolved to null and also calls config.method.toLowerCase() without
guarding for undefined; update api.interceptors.request.use to first safely
derive method (e.g., const method = (config.method || 'get').toLowerCase()) and
change the CSRF logic so a failed eager fetch is retried: when using
csrfTokenPromise, detect if it has already resolved to a null/invalid token (or
catch its rejection) and in that case set csrfTokenPromise = undefined (or call
fetchCsrfToken() directly) before awaiting; ensure fetchCsrfToken() reassigns
csrfTokenPromise while in-flight and that failures clear/reset csrfTokenPromise
so subsequent mutation requests will attempt a fresh fetch instead of awaiting a
settled null promise.
🪄 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: 63a7a018-9b84-4eb3-bd6e-48f99bf502bc

📥 Commits

Reviewing files that changed from the base of the PR and between 0acd3fa and 0a608a6.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • apps/web-dashboard/src/pages/CreateCollection.jsx
  • apps/web-dashboard/src/utils/api.js
  • package.json

Comment thread apps/web-dashboard/src/utils/api.js
Prevent stuck promises and undefined method checks in interceptor.

Co-authored-by: Yash Pouranik <172860064+yash-pouranik@users.noreply.github.com>
@yash-pouranik
Copy link
Copy Markdown
Collaborator Author

@coderabbitai is everything good??

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Fetch existing review comments and PR status
gh pr view 153 --repo geturbackend/urBackend --json reviews,comments,statusCheckRollup,mergeable,reviewDecision

# Also get review comments (inline)
gh api repos/geturbackend/urBackend/pulls/153/reviews

Length of output: 33166


@yash-pouranik Almost there! Here's the current status of PR #153:

✅ What's looking good

Check Status
frontend-lint ✅ Passed
dashboard-api-tests ✅ Passed
public-api-tests ✅ Passed
sdk-tests ✅ Passed
python-sdk-tests ✅ Passed
CodeQL ✅ Passed
Merge conflicts ✅ None

⚠️ Items still to address

  1. Open inline comment (from my initial review on apps/web-dashboard/src/utils/api.js, ~lines 25–35):
    The request interceptor has two edge-case risks:

    • If the eager CSRF fetch fails and csrfTokenPromise has already settled to null, subsequent mutating requests will await the same dead promise instead of retrying.
    • config.method.toLowerCase() is called without guarding for a potentially undefined method, which can throw.

    Suggested fix:

    // Safe method derivation
    const method = (config.method || 'get').toLowerCase();
    
    // In the CSRF block — retry if the promise already settled to null
    if (!csrfToken) {
      if (!csrfTokenPromise) csrfTokenPromise = fetchCsrfToken();
      try {
        await csrfTokenPromise;
      } catch (_) {
        csrfTokenPromise = fetchCsrfToken(); // reset and retry
        await csrfTokenPromise;
      }
    }
  2. Pre-merge warning — Docstring coverage is 66.67% but the required threshold is 80%. Adding JSDoc comments to the functions added/modified in this PR should bring it up.

Once these two are addressed, the PR should be good to merge! 🚀

@yash-pouranik
Copy link
Copy Markdown
Collaborator Author

@coderabbitai
ok now??

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check PR status, checks, and review comments
gh pr view 153 --repo geturbackend/urBackend --json reviews,statusCheckRollup,mergeable,reviewDecision,commits

# Get the latest inline review comments
gh api repos/geturbackend/urBackend/pulls/153/comments --jq '[.[] | {path: .path, line: .line, body: .body, created_at: .created_at}]'

Length of output: 17045


🏁 Script executed:

#!/bin/bash
# Check current state of api.js after the latest fix commit
cat -n apps/web-dashboard/src/utils/api.js | head -60

# Also check docstring coverage status from CI (look for any coverage check)
gh api repos/geturbackend/urBackend/pulls/153/comments --jq '[.[] | select(.path == "apps/web-dashboard/src/utils/api.js") | {body: .body, line: .line, created_at: .created_at}]'

Length of output: 9656


@yash-pouranik Yes, the fix looks great! 🎉 Here's the full picture:

✅ My previously flagged issue — Resolved

The latest commit (ddb7c3a) correctly addresses both concerns:

Fix How it's handled
Dead promise not retried fetchCsrfToken() now sets csrfTokenPromise = null inside the catch block (line 22); the interceptor re-creates it on the next mutation request (lines 37–39)
config.method undefined guard Line 32: (config.method || 'get').toLowerCase()

✅ All CI checks passing

frontend-lint · dashboard-api-tests · public-api-tests · sdk-tests · python-sdk-tests · CodeQL · CodeRabbit — all green on the latest commit.


⚠️ Two open Copilot comments worth a look (not blocking from my side)

  1. CreateCollection.jsx line 466collectionsLoading is never reset to true when projectId changes while the component stays mounted, so Ref pickers can show stale state during re-fetches. Easy fix: add setCollectionsLoading(true) at the top of the useEffect.

  2. package.json line 23 — Frontend-only deps (react, axios, lucide-react, etc.) were added to the monorepo root instead of the apps/web-dashboard workspace, causing version divergence (e.g., lucide-react ^0.554.0 vs ^1.14.0). Worth scoping them back to apps/web-dashboard/package.json.

From my end the PR is ready to merge once you decide how to handle those two items! 🚀


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

@yash-pouranik
Copy link
Copy Markdown
Collaborator Author

@copilot Last review.

Copy link
Copy Markdown
Contributor

Copilot AI commented May 7, 2026

@copilot Last review.

Final review updates are in commit 89e3554: I fixed the project-switch loading-state reset in CreateCollection and removed unintended root web-dashboard dependencies from the monorepo manifests. UI reference: Ref dropdowns now show Loading collections… and stay disabled during project collection fetches.

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web-dashboard/src/pages/CreateCollection.jsx`:
- Around line 475-477: The catch block currently swallows errors when fetching
collections (leaving users with empty Ref options); change the catch to capture
the error, set a new error state (e.g., collectionsError) and surface minimal
user feedback (call the app's toast/notification helper or render an inline
error message) so failures are visible; keep the finally block behavior
(isMounted check and setCollectionsLoading(false)) but ensure the catch logs the
error (console/error logger) and updates UI state so users can retry or see the
failure.
🪄 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: 61f4da6f-34e2-470b-bb7c-a9792430ebc2

📥 Commits

Reviewing files that changed from the base of the PR and between ddb7c3a and 89e3554.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • apps/web-dashboard/src/pages/CreateCollection.jsx

Comment thread apps/web-dashboard/src/pages/CreateCollection.jsx Outdated
Introduce error state and user feedback for collections fetch errors.

Co-authored-by: Yash Pouranik <172860064+yash-pouranik@users.noreply.github.com>
@yash-pouranik yash-pouranik temporarily deployed to v0/dashboard-loading-slow-4a22ea74 - urBackend-frankfrut PR #153 May 7, 2026 18:10 — with Render Destroyed
@yash-pouranik
Copy link
Copy Markdown
Collaborator Author

@coderabbitai
now can i merge this
also what does this pr fixes??

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Tip

For best results, initiate chat on the files or code changes.

@yash-pouranik Yes, you're good to merge! 🚀 Here's the full picture:


✅ Merge status

Area Status
frontend-lint ✅ Passed
dashboard-api-tests ✅ Passed
public-api-tests ✅ Passed
sdk-tests ✅ Passed
python-sdk-tests ✅ Passed
CodeQL ✅ Passed
Merge conflicts ✅ None
Previously flagged blocking issues ✅ Fixed in ddb7c3a

The two remaining items (resetting collectionsLoading on projectId change, and moving frontend deps from root package.json to apps/web-dashboard/package.json) are non-blocking suggestions — they won't break anything, but are worth a follow-up cleanup PR.


🔧 What this PR fixes

Problem: Slow initial load on the /create-collection page, caused by two separate issues:

  1. Blocking CSRF token fetchcsrfToken started as null, so the first mutating request (e.g. form submit) had to wait for a full /api/auth/csrf-token round-trip before it could proceed.

    • Fix (src/utils/api.js): The CSRF token is now fetched eagerly at module load time. The request interceptor awaits the already in-flight promise instead of starting a new fetch, eliminating that extra round-trip on the first submit.
  2. Silent/broken Ref pickers — The Ref-picker <select> elements on the page fetched project collections silently with no loading state, leaving the dropdowns empty or broken until the fetch resolved.

    • Fix (src/pages/CreateCollection.jsx): A collectionsLoading state (initialized to true) now disables the Ref picker <select> elements and shows a "Loading collections…" placeholder while the fetch is in progress. This state is threaded through recursive FieldRow renders so nested pickers behave consistently too.

@yash-pouranik
Copy link
Copy Markdown
Collaborator Author

for both the issues create a single issue
@coderabbitai

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@yash-pouranik, I've created a single GitHub issue combining both follow-up items. You can track the cleanup there. Here's a summary of what's captured:

  1. collectionsLoading not reset on projectId changeapps/web-dashboard/src/pages/CreateCollection.jsx — add setCollectionsLoading(true) at the top of the projectId useEffect.
  2. Frontend deps scoped to monorepo root — move react, axios, lucide-react, etc. from the root package.json to apps/web-dashboard/package.json.

🏁 Script executed:

#!/bin/bash
gh issue create \
  --repo geturbackend/urBackend \
  --title "chore: follow-up cleanups from PR `#153` (collectionsLoading reset + dep scoping)" \
  --body "## Follow-up items from PR `#153`

These two non-blocking issues were identified during the review of [PR `#153`](https://github.com/geturbackend/urBackend/pull/153) and deferred for a follow-up.

---

### 1. \`collectionsLoading\` not reset on \`projectId\` change — \`CreateCollection.jsx\`

**File:** \`apps/web-dashboard/src/pages/CreateCollection.jsx\` (around line 466)

When \`projectId\` changes while the \`CreateCollection\` component stays mounted, \`collectionsLoading\` is never reset to \`true\` before the new fetch begins. This means Ref pickers can briefly show stale data or remain in a non-loading state during the re-fetch.

**Suggested fix:** Add \`setCollectionsLoading(true)\` at the top of the \`useEffect\` that depends on \`projectId\`.

---

### 2. Frontend-only dependencies scoped to monorepo root — \`package.json\`

**File:** \`package.json\` (root, around line 23)

Frontend-only dependencies (\`react\`, \`axios\`, \`lucide-react\`, etc.) were added to the monorepo root \`package.json\` instead of the \`apps/web-dashboard\` workspace package. This can cause version divergence (e.g. \`lucide-react ^0.554.0\` at root vs \`^1.14.0\` in the workspace).

**Suggested fix:** Move these frontend-only deps to \`apps/web-dashboard/package.json\` to keep them scoped to the correct workspace.

---

Reported by `@coderabbitai` | Requested by `@yash-pouranik`
PR: https://github.com/geturbackend/urBackend/pull/153"

Length of output: 53


@yash-pouranik, the issue has been created successfully! 🎉

Issue #155: chore: follow-up cleanups from PR #153 (collectionsLoading reset + dep scoping)

It tracks both items:

  1. Reset collectionsLoading to true when projectId changes in CreateCollection.jsx
  2. Move frontend-only deps from the monorepo root package.json to apps/web-dashboard/package.json

You're clear to merge PR #153 now! 🚀

@yash-pouranik
Copy link
Copy Markdown
Collaborator Author

PLease check if it doesnot break current flow
like login
project creation, collection creation etc

@coderabbitai

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

Let me inspect the changed files and related flows to give you a thorough answer.


🏁 Script executed:

#!/bin/bash
# Read the full api.js file
echo "=== api.js ==="
cat -n apps/web-dashboard/src/utils/api.js

echo ""
echo "=== CreateCollection.jsx (relevant sections) ==="
cat -n apps/web-dashboard/src/pages/CreateCollection.jsx

echo ""
echo "=== Find login-related pages/components ==="
fd -e jsx -e js . apps/web-dashboard/src --exec grep -l -i "login\|signin\|auth" {}

echo ""
echo "=== Find project creation page ==="
fd -e jsx -e js . apps/web-dashboard/src --exec grep -l -i "createproject\|create.project\|project.*creat" {} 2>/dev/null

echo ""
echo "=== Check CSRF usage across codebase ==="
rg -n "csrf\|X-CSRF" apps/web-dashboard/src --type-add 'web:*.{js,jsx,ts,tsx}' -t web

echo ""
echo "=== Check where api (axios instance) is imported and used ==="
rg -n "from.*utils/api\|require.*utils/api" apps/web-dashboard/src --type-add 'web:*.{js,jsx,ts,tsx}' -t web

Length of output: 41075


Let me check the login and project creation pages to confirm their API usage.


🏁 Script executed:

#!/bin/bash
echo "=== Login.jsx ==="
cat -n apps/web-dashboard/src/pages/Login.jsx

echo ""
echo "=== CreateProject.jsx ==="
cat -n apps/web-dashboard/src/pages/CreateProject.jsx

echo ""
echo "=== AuthContext.jsx (key auth methods) ==="
grep -n "api\.\|axios\." apps/web-dashboard/src/context/AuthContext.jsx | head -40

echo ""
echo "=== All api import usages (method calls) ==="
rg -n "api\.(get|post|put|delete|patch)" apps/web-dashboard/src --include="*.jsx" --include="*.js" | grep -v "node_modules"

Length of output: 20731


@yash-pouranik Yes, everything looks good! ✅ Here's a breakdown of each flow you asked about:


🔐 Login

  • Login.jsx calls api.post('/api/auth/login', formData) — this goes through the CSRF interceptor
  • Since the CSRF token is eagerly fetched at module load, it will already be available by the time any user fills out the form and clicks submit — actually faster than before
  • GitHub login uses window.location.assign(...) directly, bypassing api entirely — unaffected
  • ✅ No breakage

📁 Project Creation

  • CreateProject.jsx calls api.post('/api/projects', { name, description })
  • Same as above — CSRF token is pre-fetched, interceptor attaches it cleanly
  • ✅ No breakage

🗂️ Collection Creation

  • CreateCollection.jsx calls api.post('/api/projects/${projectId}/collections', {...}) on submit
  • The new collectionsLoading state only disables the Ref picker <select> dropdowns — it does not gate the "Save" button (which is only disabled by the separate loading submit state)
  • Users can fill out field names, types, required/unique flags, and submit — all work exactly as before
  • ✅ No breakage

🔑 Auth / Session

  • AuthContext uses api.get('/api/auth/me') — GET requests completely bypass the CSRF interceptor (only POST/PUT/DELETE/PATCH get the header)
  • api.post('/api/auth/logout') — works fine with the eager CSRF token
  • The 401 auto-refresh and 403 upgrade modal logic in api.js are completely unchanged
  • ✅ No breakage

Summary

Flow API call Impact
Login POST /api/auth/login ✅ Faster (CSRF pre-fetched)
GitHub Login window.location.assign ✅ Unaffected
Session check GET /api/auth/me ✅ Unaffected (GET skips CSRF)
Logout POST /api/auth/logout ✅ Works fine
Project creation POST /api/projects ✅ Faster (CSRF pre-fetched)
Collection creation POST /api/projects/:id/collections ✅ Works fine
Ref picker loading state UI only ✅ Doesn't block form submit

PR #153 is safe to merge. 🚀

@yash-pouranik yash-pouranik merged commit a79dc10 into main May 7, 2026
9 checks passed
@yash-pouranik yash-pouranik deleted the v0/dashboard-loading-slow-4a22ea74 branch May 7, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants