Skip to content

qchore: Guard Blueprint.canUpdate and fully reset create wizard state …#284

Open
wryonik wants to merge 1 commit into
stagingfrom
shubham/reg-580-fe-fix-application-crash-on-regex-definition-page
Open

qchore: Guard Blueprint.canUpdate and fully reset create wizard state …#284
wryonik wants to merge 1 commit into
stagingfrom
shubham/reg-580-fe-fix-application-crash-on-regex-definition-page

Conversation

@wryonik

@wryonik wryonik commented Dec 24, 2025

Copy link
Copy Markdown
Collaborator

…between blueprints

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling and resilience when clearing blueprint creation state
    • Enhanced blueprint update logic with fallback mechanisms to prevent data loss
    • Added graceful error handling for draft-saving operations
  • Improvements

    • Refined blueprint versioning behavior to better determine when to create new versions versus updating existing blueprints

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 24, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Changes refactor blueprint creation and update logic in the store to check blueprint instance existence directly, integrate a canUpdate method for conditional updates with version fallback, and migrate persistence clearing in Navbar from localStorage to IndexedDB using idb-keyval with error handling.

Changes

Cohort / File(s) Summary
IndexedDB Persistence Migration
src/app/components/Navbar.tsx
Replaced localStorage clearing with IndexedDB clearing via idb-keyval; added error-tolerant, fire-and-forget clearing of 'create-blueprint' store and in-memory state reset via useCreateBlueprintStore.getState().reset() with error handling.
Blueprint Creation & Update Logic
src/app/create/[id]/store.ts
Refactored creation logic from state.id heuristic to direct blueprint instance check; modified update path to use canUpdate() method when available, with fallback to submitNewVersionDraft() for version creation; applied same conditional logic to draft-saving flow; updated blueprintId derivation to prioritize state.blueprint?.props.id.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested reviewers

  • BornPsych

Poem

🐰 A blueprint takes shape, persistence flows free,
From localStorage's grasp to IndexedDB,
Creation now wise, with fallbacks in place,
The store finds its rhythm, a well-ordered space!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: guarding Blueprint.canUpdate method and resetting create wizard state between blueprints, which align with the detailed modifications in both Navbar.tsx and store.ts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

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.

@wryonik wryonik requested review from BornPsych and rutefig December 24, 2025 08:24
@rutefig

rutefig commented Jan 2, 2026

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 2, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/app/create/[id]/store.ts (1)

199-239: Remove unreachable code at line 239.

The throw new Error('Unknown error saving blueprint') statement on line 239 is unreachable dead code. All execution paths now return before reaching it:

  • Line 214 returns when no blueprint exists
  • Lines 225/231 return when canUpdate is available
  • Line 237 returns in the fallback path
🔎 Proposed fix
           // Fallback: if canUpdate is not available (or not a function), always create a new version
           console.warn('Blueprint.canUpdate is not available, submitting new version draft instead');
           await blueprint.submitNewVersionDraft(data);
           return blueprint.props.id!;
-
-          throw new Error('Unknown error saving blueprint');
         } catch (err) {
🧹 Nitpick comments (2)
src/app/create/[id]/store.ts (1)

219-219: Consider typing canUpdate properly when SDK types are updated.

The as any cast is a reasonable workaround if canUpdate isn't yet in the SDK's type definitions. The runtime typeof check at line 222 provides adequate safety. Once the SDK types include canUpdate, this cast can be removed.

src/app/components/Navbar.tsx (1)

44-62: Consider awaiting the IndexedDB clear to avoid race with persist middleware.

The fire-and-forget pattern works for error resilience, but there's a subtle race condition: calling reset() triggers state changes that the persist middleware may immediately serialize back to IndexedDB (under the same 'create-blueprint' key), potentially racing with or overwriting the setIdb('create-blueprint', null) call.

Consider awaiting the IndexedDB clear before resetting, or making handleCreateBlueprint async:

🔎 Proposed fix
-  const handleCreateBlueprint = () => {
-    // Clear persisted create-blueprint store in IndexedDB
-    try {
-      // Fire and forget – if this fails we still reset in-memory state below
-      setIdb('create-blueprint', null).catch((err) => {
-        console.error('Failed to clear persisted create-blueprint store', err);
-      });
-    } catch (err) {
-      console.error('Error while scheduling create-blueprint store clear', err);
-    }
-
-    // Reset in-memory create blueprint store so we always start from a clean slate
-    try {
-      useCreateBlueprintStore.getState().reset();
-    } catch (err) {
-      console.error('Failed to reset create blueprint store', err);
-    }
-
-    router.push('/create');
+  const handleCreateBlueprint = async () => {
+    // Clear persisted create-blueprint store in IndexedDB first
+    try {
+      await setIdb('create-blueprint', null);
+    } catch (err) {
+      console.error('Failed to clear persisted create-blueprint store', err);
+    }
+
+    // Reset in-memory create blueprint store so we always start from a clean slate
+    try {
+      useCreateBlueprintStore.getState().reset();
+    } catch (err) {
+      console.error('Failed to reset create blueprint store', err);
+    }
+
+    router.push('/create');
   };
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 961e20a and 5691240.

📒 Files selected for processing (2)
  • src/app/components/Navbar.tsx
  • src/app/create/[id]/store.ts
🧰 Additional context used
🧬 Code graph analysis (1)
src/app/components/Navbar.tsx (1)
src/app/create/[id]/store.ts (1)
  • useCreateBlueprintStore (71-364)
🔇 Additional comments (2)
src/app/create/[id]/store.ts (1)

186-187: LGTM!

Good improvement to derive blueprintId from the blueprint instance first, which ensures consistency when the blueprint has been created but state.id might be stale.

src/app/components/Navbar.tsx (1)

10-11: LGTM!

Good aliasing of set as setIdb to avoid naming conflicts and improve clarity about the source of the function.

Base automatically changed from dev to staging April 8, 2026 15:56
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