Skip to content

fix: recs remove component on empty values #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025

Conversation

MartianGreed
Copy link
Collaborator

@MartianGreed MartianGreed commented Apr 3, 2025

Closes #

Introduced changes

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Add a dedicated CI job for new examples
  • Performed self-review of the code

Summary by CodeRabbit

Release Notes:
This update improves the overall display and reliability of the system by ensuring that only relevant components are shown. Users will notice a cleaner interface as components without data are now automatically removed.

  • Bug Fixes

    • Automatically removed empty components for a more streamlined and consistent experience.
  • New Features

    • Introduced a new command for monitoring build dependencies during development.

Copy link

coderabbitai bot commented Apr 3, 2025

Walkthrough

This pull request introduces several adjustments across the codebase. A new changeset entry for the @dojoengine/state package addresses the removal of empty components. Additionally, a new npm script has been added to watch dependency builds with a specified concurrency. Multiple TypeScript files in the SDK have undergone syntactical refinements—primarily the removal of trailing commas in generic type declarations and type definitions—without altering functionality. Finally, the state management module has been updated to improve error handling, logging, and control flow in component management.

Changes

File(s) Change Summary
.changeset/blue-points-drop.md Added a new patch entry for the @dojoengine/state package to fix removal of empty components.
package.json Introduced a new script: "dev:deps": "turbo watch build:deps --concurrency 20".
packages/sdk/src/react/{hooks/hooks.ts, hooks/index.ts, hooks/state.ts, provider.tsx}
packages/sdk/src/types.ts
Removed trailing commas and adjusted formatting for generic type declarations and type definitions.
packages/state/src/recs/index.ts Updated imports to use the type keyword; added Metadata and Schema type imports; enhanced error handling, logging, and control flow in the setEntities function.
examples/example-vite-grpc-playground/src/App.tsx Removed unused imports: ToriiQueryBuilder and ClauseBuilder from @dojoengine/sdk.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Client Code
    participant SE as setEntities
    participant CH as Component Handler
    participant Log as Logger

    Caller->>SE: Call setEntities(entity)
    SE->>CH: Check for existence of recsComponent
    alt Component exists
        SE->>SE: Verify rawValue
        alt rawValue is empty
            SE->>Log: Log "Component removal" warning
            SE->>CH: Invoke removeComponent(rawValue)
        else rawValue valid
            SE->>Log: Log rawValue and convertedValue details
            alt Conversion fails
                SE->>Log: Log error message
            else Conversion successful
                SE->>CH: Invoke setComponent(convertedValue)
            end
        end
    else
        SE->>Log: Log warning indicating missing component
    end
Loading

Possibly related PRs

Poem

Oh, what a hop in our code-filled glade,
With commas trimmed and errors swayed.
I munch on scripts and logs so bright,
As empty components vanish out of sight.
From changes small to fixes grand,
This rabbit codes with a joyful hand! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 667a753 and 6becde8.

📒 Files selected for processing (9)
  • .changeset/blue-points-drop.md (1 hunks)
  • examples/example-vite-grpc-playground/src/App.tsx (0 hunks)
  • package.json (1 hunks)
  • packages/sdk/src/react/hooks/hooks.ts (1 hunks)
  • packages/sdk/src/react/hooks/index.ts (1 hunks)
  • packages/sdk/src/react/hooks/state.ts (2 hunks)
  • packages/sdk/src/react/provider.tsx (1 hunks)
  • packages/sdk/src/types.ts (3 hunks)
  • packages/state/src/recs/index.ts (3 hunks)
💤 Files with no reviewable changes (1)
  • examples/example-vite-grpc-playground/src/App.tsx
🚧 Files skipped from review as they are similar to previous changes (8)
  • packages/sdk/src/react/provider.tsx
  • packages/sdk/src/react/hooks/index.ts
  • package.json
  • packages/sdk/src/react/hooks/hooks.ts
  • .changeset/blue-points-drop.md
  • packages/state/src/recs/index.ts
  • packages/sdk/src/react/hooks/state.ts
  • packages/sdk/src/types.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: check

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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

@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 (8)
.changeset/blue-points-drop.md (1)

1-6: Clear Changelog Entry for Empty Component Removal
The changeset entry clearly documents the patch for @dojoengine/state and details the fix related to removing components with empty values. For improved clarity and future maintainability, consider adding a brief note or reference (e.g., an issue number or test coverage details) that explains the context of this change.

packages/state/src/recs/index.ts (1)

417-426: Fixed grammar in console log messages.

The log messages have been corrected from "Did not found" to "Did not find".

These are minor improvements to log message readability.

packages/sdk/src/react/hooks/state.ts (2)

33-33: Removed trailing comma in type declaration.

This is a minor syntactic correction that improves code style consistency.


60-60: Removed trailing comma in type declaration.

This is a minor syntactic correction that improves code style consistency.

packages/sdk/src/types.ts (4)

251-251: Removed trailing comma in type declaration for ToriiResponse.

This is a minor syntactic correction that improves code style consistency across type definitions.


258-258: Removed trailing comma in type declaration for SubscribeResponse.

This is a minor syntactic correction that improves code style consistency across type definitions.


526-526: Removed trailing comma in type declaration for SubscribeParams.

This is a minor syntactic correction that improves code style consistency across interface type parameters.


538-538: Removed trailing comma in type declaration for GetParams.

This is a minor syntactic correction that improves code style consistency across interface type parameters.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1864f82 and 667a753.

📒 Files selected for processing (8)
  • .changeset/blue-points-drop.md (1 hunks)
  • package.json (1 hunks)
  • packages/sdk/src/react/hooks/hooks.ts (1 hunks)
  • packages/sdk/src/react/hooks/index.ts (1 hunks)
  • packages/sdk/src/react/hooks/state.ts (2 hunks)
  • packages/sdk/src/react/provider.tsx (1 hunks)
  • packages/sdk/src/types.ts (3 hunks)
  • packages/state/src/recs/index.ts (3 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
packages/sdk/src/react/hooks/index.ts (2)
packages/sdk/src/types.ts (1)
  • SchemaType (51-71)
examples/example-vite-token-balance/src/typescript/models.gen.ts (1)
  • SchemaType (68-80)
packages/state/src/recs/index.ts (1)
packages/state/src/utils/index.ts (1)
  • convertValues (3-62)
packages/sdk/src/react/hooks/state.ts (2)
packages/sdk/src/types.ts (1)
  • SchemaType (51-71)
examples/example-vite-token-balance/src/typescript/models.gen.ts (1)
  • SchemaType (68-80)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: check
  • GitHub Check: build
🔇 Additional comments (12)
package.json (1)

16-16: New Dev Dependency Script Added
The addition of "dev:deps": "turbo watch build:deps --concurrency 20" is a useful enhancement that enables dedicated watching of dependency builds with a specified concurrency. Ensure that this script aligns with your development environment’s performance expectations and does not conflict with other dev scripts.

packages/sdk/src/react/hooks/index.ts (1)

20-22: Remove Trailing Comma in Generic Type Parameter
The removal of the trailing comma from the generic type declaration (i.e. changing Schema extends SchemaType, to Schema extends SchemaType) is a clean formatting improvement. It enhances consistency across similar declarations in the codebase without affecting functionality.

🧰 Tools
🪛 Biome (1.9.4)

[error] 20-20: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 20-20: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)

packages/sdk/src/react/provider.tsx (1)

16-19: Formatting Improvement in DojoContextType Declaration
The consolidation of the type parameters (i.e. the removal of the trailing comma after Client extends (...args: any) => any) in the DojoContextType interface enhances readability and consistency with other parts of the codebase. This is a purely cosmetic change with no impact on functionality.

🧰 Tools
🪛 Biome (1.9.4)

[error] 17-17: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)


[error] 17-17: Unexpected any. Specify a different type.

any disables many type checking rules. Its use should be avoided.

(lint/suspicious/noExplicitAny)

packages/sdk/src/react/hooks/hooks.ts (1)

15-18: Remove Trailing Comma in Generic Type Parameter
The update removes the trailing comma from the generic type parameter declaration in the createSubscriptionHook function (Historical extends boolean = false). This change aligns with similar formatting improvements elsewhere in the codebase, contributing to cleaner and more consistent type definitions.

packages/state/src/recs/index.ts (8)

2-6: Improved type safety with explicit type imports.

Using the type keyword for imports ensures these are treated as type-only imports, which can help with tree-shaking and prevents accidental runtime usage of type information.


9-9: Added removeComponent import to support empty value handling.

This import is necessary to support the new functionality for removing components when they contain empty values.


13-20: Improved import organization with the type keyword.

Using a dedicated import type statement for these imports improves code organization and makes it clear that these are type-only imports.


434-440: Improved error handling with early returns.

The code now checks for the existence of recsComponent first and returns early if not found, improving readability and maintainability.


442-453: Implemented component removal for empty values.

This is the core implementation of the PR fix. The code now checks if rawValue is an empty object (no keys) and removes the component in that case, preventing empty components from being stored.

This change is the main feature mentioned in the PR title "fix: recs remove component on empty values".


455-470: Enhanced logging for better debugging.

Improved the logging of raw and converted values, providing more context by including the component name and entity key in the log messages.


472-476: Added validation for convertedValue.

Added an explicit check to ensure convertedValue is valid before continuing with component operations.


478-492: Reorganized component update logic.

The code flow has been restructured to be more logical:

  1. First, check if the component exists
  2. If so, update it and continue
  3. Otherwise, set the component

This improves readability and better separates the update vs. set operations.

@MartianGreed MartianGreed force-pushed the fix/recs-remove-component branch from 667a753 to 6becde8 Compare April 3, 2025 19:02
@MartianGreed MartianGreed merged commit 5f1a79a into main Apr 3, 2025
5 of 6 checks passed
@MartianGreed MartianGreed deleted the fix/recs-remove-component branch April 3, 2025 19:34
This was referenced May 8, 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