Skip to content

Conversation

GameRoMan
Copy link

@GameRoMan GameRoMan commented Aug 30, 2025

Summary by CodeRabbit

  • Refactor
    • Streamlined internal action binding logic for improved reliability and type safety.
    • Ensures handlers are consistently registered, reducing potential edge cases.
    • No changes to existing behavior or user-facing functionality.

@netlify
Copy link

netlify bot commented Aug 30, 2025

👷 Deploy request for appcut pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit d2996c6

@vercel
Copy link

vercel bot commented Aug 30, 2025

@GameRoMan 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
Contributor

coderabbitai bot commented Aug 30, 2025

Walkthrough

Refactors bindAction in apps/web/src/constants/actions.ts to always initialize boundActions[action] as an array when undefined and then push the handler, removing conditional branching and inline type casts. No exported signatures change. updateActiveActions behavior is unchanged.

Changes

Cohort / File(s) Summary
Action binding refactor
apps/web/src/constants/actions.ts
Simplified bindAction: ensure array initialization (default to []), then unconditionally push handler; removed branch and inline type cast. No API changes; updateActiveActions unaffected.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

I hop through code with tidy paws,
Arrays now bloom without a pause—
Push we do, no cast in sight,
Branches trimmed to keep it light.
With whiskers twitching, I declare:
Actions bound, clean and fair. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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
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

Caution

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

⚠️ Outside diff range comments (4)
apps/web/src/constants/actions.ts (4)

151-157: Remove remaining as any and prefer for...of over forEach.

This keeps the invocation fully typed and aligns with our guidelines.

 export const invokeAction: InvokeActionFunc = <A extends Action>(
   action: A,
   args?: ArgOfHoppAction<A>,
   trigger?: InvocationTriggers
 ) => {
-  boundActions[action]?.forEach((handler) => (handler as any)(args, trigger));
+  const handlers = boundActions[action] as Array<ActionFunc<A>> | undefined;
+  if (!handlers) return;
+  for (const handler of handlers) {
+    handler(args as ArgOfHoppAction<A>, trigger);
+  }
 };

163-173: Type-safe unbind without as any; keep updateActiveActions behavior.

Avoids any and optional chaining on mutation; logic unchanged.

 export function unbindAction<A extends Action>(
   action: A,
   handler: ActionFunc<A>
 ) {
-  // 'any' assertion because TypeScript doesn't seem to be able to figure out the links.
-  boundActions[action] = boundActions[action]?.filter(
-    (x) => x !== handler
-  ) as any;
-
-  if (boundActions[action]?.length === 0) {
-    delete boundActions[action];
-  }
+  const list = boundActions[action];
+  if (list) {
+    const next = list.filter((x): x is ActionFunc<A> => x !== handler);
+    if (next.length > 0) {
+      boundActions[action] = next;
+    } else {
+      delete boundActions[action];
+    }
+  }
 
   updateActiveActions();
 }

206-211: Eliminate any in stableHandler; keep types via Parameters<>.

This keeps the wrapper fully typed and generic-safe.

-  const stableHandler = useCallback(
-    (args: any, trigger?: InvocationTriggers) => {
-      (handlerRef.current as any)(args, trigger);
-    },
-    []
-  ) as ActionFunc<A>;
+  const stableHandler = useCallback(
+    ((...params: Parameters<ActionFunc<A>>) => {
+      (handlerRef.current as ActionFunc<A>)(...params);
+    }) as ActionFunc<A>,
+    []
+  );

151-157: Remove all remaining as any casts in apps/web/src/constants/actions.ts

The following casts were found and must be replaced with properly typed handlers:

  • Line 156: (handler as any)(args, trigger)
  • Line 166: ) as any;
  • Line 208: (handlerRef.current as any)(args, trigger)

Ensure each handler is typed (e.g. via InvokeActionFunc and ArgOfHoppAction<A>) so these as any casts can be eliminated.

🧹 Nitpick comments (3)
apps/web/src/constants/actions.ts (3)

124-129: Good removal of unnecessary branching; initialize-then-push is clean.

This achieves the PR goal for bindAction without using as any. Consider the nullish assignment idiom for brevity:

  • const list = (boundActions[action] ??= []); list.push(handler);

5-11: Use import type for type-only import (MutableRefObject).

Matches our TS import style guideline.

-import {
-  useEffect,
-  useRef,
-  useState,
-  useCallback,
-  MutableRefObject,
-} from "react";
+import { useEffect, useRef, useState, useCallback } from "react";
+import type { MutableRefObject } from "react";

24-26: Prefer for...of over Array.forEach in emitter.

Small perf/readability win and aligns with our style guide.

-  emit(actions: Action[]) {
-    this.listeners.forEach((listener) => listener(actions));
-  }
+  emit(actions: Action[]) {
+    for (const listener of this.listeners) {
+      listener(actions);
+    }
+  }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e98e400 and 41315f3.

📒 Files selected for processing (1)
  • apps/web/src/constants/actions.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Don't use TypeScript enums.
Don't export imported variables.
Don't add type annotations to variables, parameters, and class properties that are initialized with literal expressions.
Don't use TypeScript namespaces.
Don't use non-null assertions with the ! postfix operator.
Don't use parameter properties in class constructors.
Don't use user-defined types.
Use as const instead of literal types and type annotations.
Use either T[] or Array<T> consistently.
Initialize each enum member value explicitly.
Use export type for types.
Use import type for types.
Make sure all enum members are literal values.
Don't use TypeScript const enum.
Don't declare empty interfaces.
Don't let variables evolve into any type through reassignments.
Don't use the any type.
Don't misuse the non-null assertion operator (!) in TypeScript files.
Don't use implicit any type on variable declarations.
Don't merge interfaces and classes unsafely.
Don't use overload signatures that aren't next to each other.
Use the namespace keyword instead of the module keyword to declare TypeScript namespaces.
Don't use empty type parameters in type aliases and interfaces.
Don't use any or unknown as type constraints.
Don't use the TypeScript directive @ts-ignore.
Use consistent accessibility modifiers on class properties and methods.
Use function types instead of object types with call signatures.
Don't use void type outside of generic or return types.

**/*.{ts,tsx}: Don't use primitive type aliases or misleading types
Don't use the TypeScript directive @ts-ignore
Don't use TypeScript enums
Use either T[] or Array consistently
Don't use the any type

Files:

  • apps/web/src/constants/actions.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{js,jsx,ts,tsx}: Don't use the return value of React.render.
Don't use consecutive spaces in regular expression literals.
Don't use the arguments object.
Don't use primitive type aliases or misleading types.
Don't use the comma operator.
Don't write functions that exceed a given Cognitive Complexity score.
Don't use unnecessary boolean casts.
Don't use unnecessary callbacks with flatMap.
Use for...of statements instead of Array.forEach.
Don't create classes that only have static members (like a static namespace).
Don't use this and super in static contexts.
Don't use unnecessary catch clauses.
Don't use unnecessary constructors.
Don't use unnecessary continue statements.
Don't export empty modules that don't change anything.
Don't use unnecessary escape sequences in regular expression literals.
Don't use unnecessary labels.
Don't use unnecessary nested block statements.
Don't rename imports, exports, and destructured assignments to the same name.
Don't use unnecessary string or template literal concatenation.
Don't use String.raw in template literals when there are no escape sequences.
Don't use useless case statements in switch statements.
Don't use ternary operators when simpler alternatives exist.
Don't use useless this aliasing.
Don't initialize variables to undefined.
Don't use the void operators (they're not familiar).
Use arrow functions instead of function expressions.
Use Date.now() to get milliseconds since the Unix Epoch.
Use .flatMap() instead of map().flat() when possible.
Use literal property access instead of computed property access.
Don't use parseInt() or Number.parseInt() when binary, octal, or hexadecimal literals work.
Use concise optional chaining instead of chained logical expressions.
Use regular expression literals instead of the RegExp constructor when possible.
Don't use number literal object member names that aren't base 10 or use underscore separators.
Remove redundant terms from logical expressions.
Use while loops instead of...

Files:

  • apps/web/src/constants/actions.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)

**/*.{ts,tsx,js,jsx}: Don't use the comma operator
Use for...of statements instead of Array.forEach
Don't initialize variables to undefined
Use .flatMap() instead of map().flat() when possible
Don't assign a value to itself
Avoid unused imports and variables
Don't use await inside loops
Don't hardcode sensitive data like API keys and tokens
Don't use the delete operator
Don't use global eval()
Use String.slice() instead of String.substr() and String.substring()
Don't use else blocks when the if block breaks early
Put default function parameters and optional function parameters last
Use new when throwing an error
Use String.trimStart() and String.trimEnd() over String.trimLeft() and String.trimRight()

Files:

  • apps/web/src/constants/actions.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Vade Review

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