Skip to content

[Grida Canvas] RC#365

Merged
softmarshmallow merged 8 commits intomainfrom
canary
May 30, 2025
Merged

[Grida Canvas] RC#365
softmarshmallow merged 8 commits intomainfrom
canary

Conversation

@softmarshmallow
Copy link
Copy Markdown
Member

@softmarshmallow softmarshmallow commented May 30, 2025

  • fixes document context hierachy - fixes sibling query, fixes 'sanp target' resolution

Summary by CodeRabbit

  • New Features

    • Added a new method to retrieve sibling node IDs in the editor.
    • Introduced type checking scripts for various packages and apps to streamline type validation.
  • Bug Fixes

    • Improved the initialization of node hierarchy context to ensure consistent parent-child relationships.
  • Refactor

    • Replaced deep equality checks with a faster alternative for improved performance across several modules.
    • Updated tangent vector transformation in the path editor for accurate rendering.
  • Style

    • Adjusted card padding in the file import modal for improved visual alignment.
  • Documentation

    • Enhanced documentation with updated instructions for type checking and troubleshooting build issues.
  • Chores

    • Updated dependencies and TypeScript configuration for better compatibility.
    • Renamed and standardized type checking tasks in build scripts and configuration files.

@codesandbox
Copy link
Copy Markdown

codesandbox Bot commented May 30, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
backgrounds ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2025 0:55am
blog ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2025 0:55am
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2025 0:55am
grida ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2025 0:55am
viewer ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2025 0:55am
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
code ⬜️ Ignored (Inspect) May 30, 2025 0:55am
legacy ⬜️ Ignored (Inspect) May 30, 2025 0:55am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2025

Walkthrough

This update introduces a unified typecheck script across multiple packages and apps, updates documentation with typechecking instructions and troubleshooting, and standardizes type checking to use tsc --noEmit. Several dependencies are switched from deep-equal to fast-deep-equal, and internal logic is refactored accordingly. Minor code improvements and a new public method are also included.

Changes

File(s) Change Summary
AGENTS.md Updated documentation with instructions and troubleshooting for running type checks.
package.json, apps/backgrounds/package.json, apps/blog/package.json, apps/viewer/package.json Added or updated typecheck npm scripts to standardize type checking with tsc --noEmit.
turbo.json Renamed the task from check-types to typecheck and updated dependencies accordingly.
editor/grida-canvas-react/provider.tsx, editor/grida-canvas-react/reducers/index.ts, packages/grida-mixed-properties/index.ts Switched deep equality checks from deep-equal to fast-deep-equal and updated usage.
packages/grida-mixed-properties/package.json Swapped dependency from deep-equal to fast-deep-equal and removed related type definitions.
packages/grida-mixed-properties/tsconfig.json Added "moduleResolution": "bundler" to TypeScript config.
editor/grida-canvas-react/viewport/ui/path-editor.tsx Added transformDelta helper to correctly transform tangent vectors before rendering.
editor/grida-canvas/editor.ts Added public method __get_node_siblings to the Editor class.
editor/grida-canvas/index.ts Added a comment describing a known limitation in the getSiblings function.
editor/scaffolds/playground-canvas/modals/import-from-grida-file.tsx Adjusted card styling by adding p-0 class to remove padding.
packages/grida-canvas-schema/grida.ts Refactored node hierarchy context initialization for clarity and correctness.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PackageScript
    participant Turbo
    participant TypeScript

    User->>PackageScript: Run "pnpm turbo typecheck"
    PackageScript->>Turbo: Execute "typecheck" task
    Turbo->>TypeScript: Run "tsc --noEmit" in each package/app
    TypeScript-->>Turbo: Report type errors (if any)
    Turbo-->>PackageScript: Aggregate results
    PackageScript-->>User: Show typecheck status
Loading

Possibly related PRs

  • [Ops] add AGENTS.md #337: Introduced the initial AGENTS.md documentation, which this PR extends with additional typecheck instructions and troubleshooting.

Poem

Hopping through code with a gentle sweep,
Typechecks unified, our standards to keep.
Deep-equal replaced with something more fleet,
Siblings discovered, transformations neat.
With scripts aligned and docs now bright,
This bunny’s code runs smooth and right!
🐇✨

✨ 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.

@vercel vercel Bot temporarily deployed to Preview – backgrounds May 30, 2025 11:53 Inactive
@vercel vercel Bot temporarily deployed to Preview – docs May 30, 2025 11:53 Inactive
@vercel vercel Bot temporarily deployed to Preview – viewer May 30, 2025 11:53 Inactive
@vercel vercel Bot temporarily deployed to Preview – blog May 30, 2025 11:53 Inactive
Copy link
Copy Markdown

@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: 4

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6174255 and 4a9961b.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (16)
  • AGENTS.md (1 hunks)
  • apps/backgrounds/package.json (1 hunks)
  • apps/blog/package.json (1 hunks)
  • apps/viewer/package.json (1 hunks)
  • editor/grida-canvas-react/provider.tsx (2 hunks)
  • editor/grida-canvas-react/viewport/ui/path-editor.tsx (5 hunks)
  • editor/grida-canvas/editor.ts (1 hunks)
  • editor/grida-canvas/index.ts (1 hunks)
  • editor/grida-canvas/reducers/index.ts (1 hunks)
  • editor/scaffolds/playground-canvas/modals/import-from-grida-file.tsx (1 hunks)
  • package.json (1 hunks)
  • packages/grida-canvas-schema/grida.ts (1 hunks)
  • packages/grida-mixed-properties/index.ts (2 hunks)
  • packages/grida-mixed-properties/package.json (1 hunks)
  • packages/grida-mixed-properties/tsconfig.json (1 hunks)
  • turbo.json (1 hunks)
🔇 Additional comments (16)
package.json (1)

11-11: LGTM! Clean addition of unified typecheck script.

The new typecheck script properly integrates with the monorepo's turbo configuration, providing a consistent way to run type checking across all packages.

editor/scaffolds/playground-canvas/modals/import-from-grida-file.tsx (1)

59-59: LGTM! Appropriate styling adjustment.

Adding p-0 to remove padding makes sense for allowing the button to fill the card area completely without extra spacing.

apps/blog/package.json (1)

15-15: LGTM! Standard typecheck script implementation.

The tsc --noEmit command is the correct approach for type checking without generating output files, consistent with the monorepo-wide standardization.

packages/grida-canvas-schema/grida.ts (1)

545-549: LGTM! Excellent defensive programming improvement.

The explicit initialization of parent and children mappings before processing relationships is a great enhancement. This ensures all nodes have defined entries in the context mappings, preventing potential undefined access issues and making the hierarchy building process more robust and predictable.

editor/grida-canvas-react/viewport/ui/path-editor.tsx (2)

14-19: LGTM! Well-implemented helper function for tangent vector transformation.

The transformDelta function correctly extracts the linear transformation part (top-left 2x2 submatrix) from a 3x3 transform matrix, which is the appropriate way to transform direction vectors like tangents without applying translation.


94-94: Proper usage of the transformDelta helper.

The application of transformDelta to tangent vectors (next_ta, ta, tb) ensures they are correctly scaled and rotated by the transformation matrix without being translated, which is the mathematically correct approach for direction vectors.

Also applies to: 103-104, 127-127, 142-142

packages/grida-mixed-properties/package.json (1)

30-30:

Details

✅ Verification successful

Good performance improvement by switching to fast-deep-equal.

The change from deep-equal to fast-deep-equal is a performance improvement, and removing @types/deep-equal is correct since fast-deep-equal includes its own TypeScript definitions.

Let's verify that all imports have been updated to use the new package:

Also applies to: 35-35


🏁 Script executed:

#!/bin/bash
# Description: Verify that all deep-equal imports have been updated to fast-deep-equal
# Expected: No remaining imports of "deep-equal"

# Search for any remaining deep-equal imports
rg -A 2 -B 2 'from ["\']deep-equal["\']'

# Search for fast-deep-equal imports to confirm the migration
rg -A 2 'from ["\']fast-deep-equal["\']'

Length of output: 116


🏁 Script executed:

#!/bin/bash
# Description: Re-verify removal of deep-equal and presence of fast-deep-equal imports/requires

echo "🔍 Checking for any remaining imports of deep-equal..."
rg -E "import\s+.*\s+from\s+['\"]deep-equal['\"]" || echo "✅ No deep-equal import found"
rg -E "require\(\s*['\"]deep-equal['\"]\s*\)" || echo "✅ No deep-equal require found"

echo
echo "🔍 Checking for fast-deep-equal usage..."
rg -E "import\s+.*\s+from\s+['\"]fast-deep-equal['\"]" || echo "⚠️ No fast-deep-equal import found"
rg -E "require\(\s*['\"]fast-deep-equal['\"]\s*\)" || echo "⚠️ No fast-deep-equal require found"

Length of output: 2327


🏁 Script executed:

#!/bin/bash
# Re-verify any remaining references to deep-equal and fast-deep-equal

echo "🔍 Searching for any references to 'deep-equal' (code or imports):"
rg "deep-equal" --color=never || echo "✅ No references to 'deep-equal' found"

echo
echo "🔍 Searching for any references to 'fast-deep-equal' (code or imports):"
rg "fast-deep-equal" --color=never || echo "⚠️ No references to 'fast-deep-equal' found"

Length of output: 4019


Dependency update approved: no remaining deep-equal imports

All references to deep-equal have been removed and replaced with fast-deep-equal in packages/grida-mixed-properties. Verified there are no lingering deep-equal imports or requires in this package.

turbo.json (1)

11-13:

Details

✅ Verification successful

Good standardization of task naming.

Renaming from "check-types" to "typecheck" follows standard npm script naming conventions and aligns with the broader standardization effort across the codebase.

Let's verify that all references to the old task name have been updated:


🏁 Script executed:

#!/bin/bash
# Description: Verify that all references to "check-types" have been updated to "typecheck"
# Expected: No remaining references to "check-types" task

# Search for any remaining references to check-types
rg -i 'check-types'

# Search for typecheck references to confirm the migration
rg -A 2 -B 2 '"typecheck"'

Length of output: 1531


Renaming Verified: No “check-types” References Remain

All instances of the old task name have been replaced with typecheck across the codebase:

  • turbo.json
  • package.json
  • editor/package.json
  • apps/blog/package.json
  • apps/backgrounds/package.json
  • apps/viewer/package.json

The task rename is consistent and the dependency chain remains intact. Approving the change.

packages/grida-mixed-properties/tsconfig.json (1)

3-3: Appropriate module resolution strategy for a bundled package.

Adding "moduleResolution": "bundler" is a good choice for this package as it provides more flexible module resolution that aligns with modern bundling tools and the package's build process using tsup.

apps/backgrounds/package.json (1)

10-11: LGTM! Good addition of typecheck script with proper formatting.

The changes are well-implemented:

  1. Trailing comma added: Improves git diff readability and follows JSON best practices
  2. TypeScript checking: The tsc --noEmit command is the standard approach for type checking without compilation
  3. Consistency: Aligns with the broader effort to standardize typecheck scripts across packages

This enables type checking independently of the build process, which is valuable for CI/CD and development workflows.

apps/viewer/package.json (1)

9-10: LGTM! Standard typecheck script addition.

The trailing comma addition and new typecheck script follow best practices. Using tsc --noEmit is appropriate for type checking without generating output files.

packages/grida-mixed-properties/index.ts (2)

1-1: LGTM! Performance improvement with library migration.

The migration from deep-equal to fast-deep-equal is a good performance optimization while maintaining the same API.


92-92: LGTM! Consistent update to use the new library.

The default compare function correctly uses equal from the fast-deep-equal library.

AGENTS.md (1)

156-162: LGTM! Helpful documentation for typecheck workflow.

The documentation clearly explains when and how to use the typecheck command as a fallback, including its dependencies and limitations. This will be valuable for developers encountering build issues.

editor/grida-canvas-react/provider.tsx (2)

19-19: LGTM! Consistent library migration.

The import change to fast-deep-equal is consistent with the project-wide migration for better performance.


250-252: LGTM! Updated to use the new equality function.

The compareNodeProperty function correctly uses equal from the fast-deep-equal library for both the special case handling and the default comparison.

const parent_id = getParentId(context, node_id);

if (!parent_id) {
// FIXME: this is not scoped by the scene - may result unexpected behavior.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Document the known issue with a TODO or track it separately.

The comment correctly identifies a known issue where sibling retrieval for root nodes is not scoped by scene. Consider:

  1. Adding a TODO: or FIXME: prefix to make it more visible
  2. Creating a GitHub issue to track this limitation
  3. Documenting the expected behavior vs current behavior more explicitly

Consider updating the comment to be more actionable:

-      // FIXME: this is not scoped by the scene - may result unexpected behavior.
+      // TODO: #<issue-number> - Root node siblings should be scoped by scene to prevent unexpected behavior across scenes
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// FIXME: this is not scoped by the scene - may result unexpected behavior.
// TODO: #<issue-number> - Root node siblings should be scoped by scene to prevent unexpected behavior across scenes
🤖 Prompt for AI Agents
In editor/grida-canvas/index.ts at line 1421, update the existing comment to
start with a clear TODO or FIXME prefix to highlight the known issue that
sibling retrieval for root nodes is not scoped by scene. Expand the comment to
explicitly describe the expected behavior versus the current behavior and
mention that this limitation may cause unexpected results. Additionally, create
a GitHub issue to track this problem separately for future resolution.

import eventTargetReducer from "./event-target.reducer";
import documentReducer from "./document.reducer";
import equal from "deep-equal";
import equal from "fast-deep-equal";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

LGTM! Performance improvement with dependency standardization.

The switch from deep-equal to fast-deep-equal is a good change that provides better performance while maintaining the same functionality. This aligns with similar changes across the codebase for consistency.

Since this affects the history system's change detection, please verify that the equality behavior remains consistent:


🏁 Script executed:

#!/bin/bash
# Description: Verify that fast-deep-equal is used consistently across the codebase and check for any remaining deep-equal imports

# Search for any remaining deep-equal imports
rg "from ['\"]deep-equal['\"]" --type=ts --type=js

# Search for fast-deep-equal usage to confirm consistency
rg "from ['\"]fast-deep-equal['\"]" --type=ts --type=js -A 2

Length of output: 1475


Replace all remaining deep-equal imports with fast-deep-equal

We’ve standardized on fast-deep-equal, but there are still several modules importing deep-equal. Please update these imports to avoid duplicate dependencies and ensure consistent behavior:

• editor/scaffolds/editor/feed.tsx
• editor/scaffolds/editor/reducers/database.reducer.ts
• editor/scaffolds/editor/sync/agent-theme.sync.tsx
• editor/scaffolds/editor/sync/agent-startpage.sync.tsx
• editor/grida-forms-hosted/e/interface.tsx

Example replacement:

- import equal from "deep-equal";
+ import equal from "fast-deep-equal";

After making these changes, rerun a global search to confirm no deep-equal imports remain.

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +141 to +143
public __get_node_siblings(node_id: string): string[] {
return editor.dq.getSiblings(this.mstate.document_ctx, node_id);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve method naming and document the inherited limitation.

The new method provides a useful interface to sibling retrieval, but there are some concerns:

  1. Naming inconsistency: The __ prefix typically indicates private/internal methods, but this is marked public
  2. Inherited limitation: This method inherits the scene scoping issue from editor.dq.getSiblings

Consider these improvements:

-  public __get_node_siblings(node_id: string): string[] {
-    return editor.dq.getSiblings(this.mstate.document_ctx, node_id);
-  }
+  /**
+   * Get sibling node IDs for the given node.
+   * 
+   * @warning Root node siblings are not scoped by scene - may include 
+   * siblings from other scenes. See issue #<issue-number>
+   */
+  public getNodeSiblings(node_id: string): string[] {
+    return editor.dq.getSiblings(this.mstate.document_ctx, node_id);
+  }

This provides:

  • Consistent naming without internal prefixes for public methods
  • Clear documentation about the limitation
  • Better API discoverability
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public __get_node_siblings(node_id: string): string[] {
return editor.dq.getSiblings(this.mstate.document_ctx, node_id);
}
/**
* Get sibling node IDs for the given node.
*
* @warning Root node siblings are not scoped by scene - may include
* siblings from other scenes. See issue #<issue-number>
*/
public getNodeSiblings(node_id: string): string[] {
return editor.dq.getSiblings(this.mstate.document_ctx, node_id);
}
🤖 Prompt for AI Agents
In editor/grida-canvas/editor.ts around lines 141 to 143, rename the method from
__get_node_siblings to getNodeSiblings to remove the misleading private/internal
prefix since it is public. Add a comment above the method clearly documenting
the inherited scene scoping limitation from editor.dq.getSiblings so users are
aware of this constraint. This will improve naming consistency, clarify
limitations, and enhance API discoverability.

Comment on lines +257 to +260
const selection = useEditorState(instance, (state) => state.selection);
const nodes = useEditorState(instance, (state) =>
selection.map((id) => state.document.nodes[id])
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential stale closure issue with refactored state management.

The refactoring introduces a potential bug where the nodes computation references the selection variable from a separate useEditorState call. This could lead to stale closure issues where the selection value used in the second useEditorState might not be the most current one.

Consider refactoring to use a single useEditorState call:

-  const selection = useEditorState(instance, (state) => state.selection);
-  const nodes = useEditorState(instance, (state) =>
-    selection.map((id) => state.document.nodes[id])
-  );
+  const { selection, nodes } = useEditorState(instance, (state) => ({
+    selection: state.selection,
+    nodes: state.selection.map((id) => state.document.nodes[id])
+  }));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const selection = useEditorState(instance, (state) => state.selection);
const nodes = useEditorState(instance, (state) =>
selection.map((id) => state.document.nodes[id])
);
const { selection, nodes } = useEditorState(instance, (state) => ({
selection: state.selection,
nodes: state.selection.map((id) => state.document.nodes[id])
}));
🤖 Prompt for AI Agents
In editor/grida-canvas-react/provider.tsx around lines 257 to 260, the code uses
two separate useEditorState calls where the second depends on the first's
selection variable, risking stale closure issues. Refactor by combining these
into a single useEditorState call that retrieves both selection and nodes
together, ensuring nodes are computed from the current selection state within
the same callback to avoid referencing outdated values.

@softmarshmallow softmarshmallow merged commit 9e1e9bd into main May 30, 2025
10 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Dec 21, 2025
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