Skip to content

fix(web): #268 multiple new projects bug#287

Merged
mazeincoding merged 5 commits into
OpenCut-app:stagingfrom
simonorzel26:fix/268_multiple-new-projects
Jul 16, 2025
Merged

fix(web): #268 multiple new projects bug#287
mazeincoding merged 5 commits into
OpenCut-app:stagingfrom
simonorzel26:fix/268_multiple-new-projects

Conversation

@simonorzel26
Copy link
Copy Markdown
Contributor

@simonorzel26 simonorzel26 commented Jul 15, 2025

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Fixes # (issue)
The useEffect was looping and creating many projects due to unhandled cases.

I fix this bug by dissecting the ternerary and guard clause each case seperately. Then try to load the project, when project is non existant, create new project and redirect there.

Type of change

Please delete options that are not relevant.

  • [ x] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Performance improvement
  • Code refactoring
  • Tests

How Has This Been Tested?

Tested every way to make and load a new project

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A
  • Test B

Test Configuration:

  • Node version:
  • Browser (if applicable):
  • Operating System:

Screenshots (if applicable)

Add screenshots to help explain your changes.

Checklist:

  • [x ] My code follows the style guidelines of this project
  • [ x] I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • [ x] My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Additional context

Add any other context about the pull request here.

Summary by CodeRabbit

  • Bug Fixes
    • Improved project loading logic to prevent repeated or redundant handling of the same project.
    • Automatically redirects to a new "Untitled Project" editor page if loading a project fails.

@netlify
Copy link
Copy Markdown

netlify Bot commented Jul 15, 2025

👷 Deploy request for appcut pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 6df492b

@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 15, 2025

@simonorzel26 is attempting to deploy a commit to the OpenCut OSS Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 15, 2025

Walkthrough

The code refactors the project initialization logic within the Editor React component. It introduces a useRef to track handled project IDs, preventing redundant processing. The effect now avoids reloading the same or failed projects and redirects to a new project editor page if loading fails. The effect's dependency array is also updated.

Changes

File(s) Change Summary
apps/web/src/app/editor/[project_id]/page.tsx Refactored project initialization logic: added handled project IDs tracking, improved control flow, and updated effect dependencies.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant EditorComponent
    participant ProjectLoader
    participant Router

    User->>EditorComponent: Navigates to /editor/[project_id]
    EditorComponent->>EditorComponent: Check if projectId is handled or active
    alt projectId not handled and not active
        EditorComponent->>ProjectLoader: Attempt to load project
        alt Load succeeds
            ProjectLoader-->>EditorComponent: Project loaded
        else Load fails
            EditorComponent->>EditorComponent: Mark projectId as handled
            EditorComponent->>ProjectLoader: Create new "Untitled Project"
            ProjectLoader-->>EditorComponent: New project created
            EditorComponent->>Router: Replace route with new project's editor URL
        end
    else
        EditorComponent->>EditorComponent: Do nothing
    end
Loading

Poem

In the editor’s warren, IDs abound,
Now each is tracked—no loops around!
If loading fails, a new path’s spun,
“Untitled Project”—a fresh new one.
With smarter flow, the code’s refined,
A rabbit’s hop ahead in mind!
🐇✨

✨ 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

🧹 Nitpick comments (1)
apps/web/src/app/editor/[project_id]/page.tsx (1)

38-38: Consider memory management for the handledProjectIds ref.

The ref effectively prevents redundant project loading attempts, which addresses the multiple new projects bug. However, the Set could grow indefinitely in long-running sessions.

Consider adding a cleanup mechanism or size limit:

-const handledProjectIds = useRef<Set<string>>(new Set());
+const handledProjectIds = useRef<Set<string>>(new Set());
+
+// Optional: Add cleanup effect to prevent memory leaks
+useEffect(() => {
+  return () => {
+    handledProjectIds.current.clear();
+  };
+}, []);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1f95bb9 and 6df492b.

📒 Files selected for processing (1)
  • apps/web/src/app/editor/[project_id]/page.tsx (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/web/src/app/editor/[project_id]/page.tsx (2)
apps/web/src/hooks/use-playback-controls.ts (1)
  • usePlaybackControls (6-173)
apps/web/src/lib/storage/storage-service.ts (1)
  • loadProject (71-87)
🔇 Additional comments (4)
apps/web/src/app/editor/[project_id]/page.tsx (4)

3-4: LGTM: Necessary imports added for the bug fix.

The addition of useRef and useRouter imports are correctly added to support the new project initialization logic.


36-36: LGTM: Router initialization for error handling.

The router instance is correctly initialized to handle navigation when project loading fails.


43-66: LGTM: Solid implementation of the bug fix with proper error handling.

The refactored initialization logic effectively addresses the multiple new projects bug by:

  • Implementing early returns to prevent redundant processing
  • Tracking handled project IDs to avoid infinite loops
  • Gracefully handling load failures by creating a new project and redirecting

The error handling flow is particularly well-designed: when a project fails to load, it marks the ID as handled, creates a new "Untitled Project", and redirects to prevent further attempts.


67-67: LGTM: Dependency array correctly updated.

The dependency array properly includes activeProject?.id and router to ensure the effect runs when the active project changes or when the router instance changes.

@simonorzel26
Copy link
Copy Markdown
Contributor Author

@izadoesdev @mazeincoding

@mazeincoding mazeincoding changed the base branch from main to staging July 16, 2025 09:58
@mazeincoding mazeincoding merged commit 2982293 into OpenCut-app:staging Jul 16, 2025
1 of 2 checks passed
zstar1003 pushed a commit to zstar1003/FlashCut that referenced this pull request Jan 28, 2026
…-new-projects

fix(web): OpenCut-app#268 multiple new projects bug
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.

3 participants