Skip to content

fix: critical bug fixes — invoke params, download flow, stale closures#8

Merged
Szymon0C merged 1 commit intomainfrom
claude/gifted-satoshi
Apr 3, 2026
Merged

fix: critical bug fixes — invoke params, download flow, stale closures#8
Szymon0C merged 1 commit intomainfrom
claude/gifted-satoshi

Conversation

@Szymon0C
Copy link
Copy Markdown
Owner

@Szymon0C Szymon0C commented Apr 3, 2026

Summary

Fixes 8 bugs found during code review:

  • CRITICAL: Tauri invoke passes system_prompt/max_tokens in snake_case but Tauri expects camelCase from JS. AI was receiving no system prompt — all generation was broken.
  • HIGH: Model download when file already exists caused isDownloading stuck true forever, sidecar never auto-starts
  • HIGH: deploy_config typed as object but DB returns JSON string. Store never updated after deploy, causing duplicate site creation on redeploy
  • HIGH: PreviewFrame WYSIWYG handler used stale currentProject closure — rapid edits overwrote each other
  • MEDIUM: Shared unlistenRef in useAiStream leaked on concurrent generate/generateSection calls
  • MEDIUM: initialPromptSent ref never reset on project navigation, blocking auto-prompt for subsequent template projects
  • MEDIUM: Chat messages and editor selection persisted when navigating between projects
  • MEDIUM: loadProjectById had no try/catch — exceptions left loading: true permanently

Test plan

  • TypeScript compiles clean (npx tsc --noEmit)
  • Vite build succeeds (npm run build)
  • AI generation produces valid HTML (system prompt now correctly passed)
  • Re-downloading existing model doesn't get stuck
  • Deploy then redeploy updates same site (not creating a new one)
  • Navigating between projects clears old chat messages
  • Template auto-prompt fires for each new template project

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed deploy configuration to properly persist when updating deployment settings
    • Project switching now correctly clears chat and editor state to prevent overlap between projects
    • Improved handling of AI model downloads when models already exist locally

…, stale closures

- Fix Tauri invoke parameter names: system_prompt→systemPrompt, max_tokens→maxTokens
  (CRITICAL: without this fix, AI receives no system prompt and generates garbage)
- Fix model download already-exists path: invoke resolves without download-complete
  event, causing isDownloading stuck true forever and sidecar never starting
- Fix deploy_config type: DB stores JSON string, not object. Added updateDeployConfig
  store action so subsequent deploys reuse existing site instead of creating new one
- Fix PreviewFrame WYSIWYG stale closure: use ref for currentProject so rapid edits
  don't overwrite each other
- Fix shared unlistenRef leak in useAiStream: each call uses its own cleanup reference
- Reset initialPromptSent, chat messages, and editor selection on project navigation
- Add try/catch to loadProjectById to prevent permanent loading state on errors

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Szymon0C Szymon0C merged commit 3ff12fc into main Apr 3, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 3, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f6a74815-03c9-4248-b37e-c9e9715dae63

📥 Commits

Reviewing files that changed from the base of the PR and between af20785 and 62f5d65.

📒 Files selected for processing (7)
  • src/components/deploy/DeployModal.tsx
  • src/components/preview/PreviewFrame.tsx
  • src/hooks/useAiStream.ts
  • src/pages/ProjectPage.tsx
  • src/stores/aiStore.ts
  • src/stores/projectStore.ts
  • src/types/project.ts

Walkthrough

This PR refactors deployment configuration handling to store deploy_config as a JSON string instead of a structured object, adds a new store method to persist configurations, improves event listener cleanup in streaming functions, adds defensive guards for incomplete model downloads, and ensures proper state cleanup when switching projects.

Changes

Cohort / File(s) Summary
Deployment Config Storage
src/types/project.ts, src/components/deploy/DeployModal.tsx, src/stores/projectStore.ts
Changed deploy_config type from DeployConfig object to string, added updateDeployConfig method to persist configurations, and simplified JSON parsing with better error handling for invalid JSON.
Event Listener Cleanup
src/hooks/useAiStream.ts
Improved listener cleanup logic to avoid clearing newer listeners, and renamed Tauri invoke parameters from snake\_case to camelCase (system_promptsystemPrompt, max_tokensmaxTokens).
Download State Fallback
src/stores/aiStore.ts
Added completeFired guard to handle cases where download-complete event doesn't trigger, ensuring downloading state is cleared and sidecar auto-starts if invoke resolves without the event.
Component State Management
src/components/preview/PreviewFrame.tsx, src/pages/ProjectPage.tsx
Added projectRef to preserve latest project state in PreviewFrame message handler, and implemented chat/editor state cleanup when route project changes in ProjectPage with prompt control flow reset.
Error Handling
src/stores/projectStore.ts
Wrapped project loading in try/catch with error logging to gracefully handle database failures.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Configs now as strings we keep,
Listeners clean, no leaks so deep,
State resets when projects change,
Guards protect from downloads strange—
Refactored paths in new arrange! ✨

✨ 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 claude/gifted-satoshi

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.

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