Skip to content

fix(react): deep merge models by namespace in entity updates#525

Merged
MartianGreed merged 2 commits intomainfrom
fix/deep-merge-models
Feb 13, 2026
Merged

fix(react): deep merge models by namespace in entity updates#525
MartianGreed merged 2 commits intomainfrom
fix/deep-merge-models

Conversation

@MartianGreed
Copy link
Copy Markdown
Collaborator

@MartianGreed MartianGreed commented Feb 12, 2026

Problem

mergeModels in createEntityQueryWithUpdatesAtom and createEntitiesInfiniteScrollWithUpdatesAtom does a shallow spread:

{ ...existing, ...updates }

When a subscription update arrives for a single model (e.g. ARCADE-Order), the parsed update produces { ARCADE: { Order: {...} } }. The shallow spread replaces the entire ARCADE namespace, losing sibling models like Game, Book, etc.

This means derived atoms (like listingsAtom in arcade) may not see updated entities because the merge destroys other model data on the same entity.

Fix

Deep merge at the namespace level:

const result = { ...existing };
for (const namespace in updates) {
    result[namespace] = {
        ...existing[namespace],
        ...updates[namespace],
    };
}
return result;

Only the specific models within a namespace get replaced; siblings are preserved.

Summary by CodeRabbit

Bug Fixes

  • Fixed entity subscription updates that were incorrectly removing sibling entities within the same namespace when applying targeted updates. The subscription system now performs proper deep merging to preserve all related entities while correctly applying updates, preventing unintended data loss during synchronization.

The mergeModels function was doing a shallow spread at the top level,
which meant subscription updates for a single model (e.g. Order) would
overwrite the entire namespace, losing sibling models (e.g. Game, Book).

Now merges at the namespace level so only the updated models within a
namespace are replaced while others are preserved.

Fixes entity subscription updates not reflecting in derived atoms.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 12, 2026

📝 Walkthrough

Walkthrough

This PR fixes a shallow-merge bug in entity subscription updates by modifying the mergeModels function to perform namespace-scoped merging, preserving sibling models within namespaces when updating individual models.

Changes

Cohort / File(s) Summary
Changeset Release Note
.changeset/fix-deep-merge-models.md
Documents a patch release for @dojoengine/react addressing a shallow-merge issue in entity subscription updates.
Entity Merge Logic
packages/react/src/effect/atoms/entities.ts
Modified mergeModels function to perform namespace-scoped merging instead of shallow top-level merging, preserving existing entries within each namespace when updating individual models.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Deep in the namespaces, siblings did cry,
Lost in the shallows, they'd wave goodbye,
But now with our fix, they're preserved and whole,
A namespace-scoped merge fulfills our goal,
Hop hop, the data flows free! 🌿

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description comprehensively covers the problem, the fix, and code examples, but lacks the required sections from the template including linked issues, checklist items, and documentation/test updates. Add a 'Closes #' section for linked issues, fill out the checklist to indicate whether documentation and tests were updated, and clarify if any examples or CI jobs need attention.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately describes the main change: fixing the deep merge of models by namespace in entity updates, which is the core objective of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/deep-merge-models

No actionable comments were generated in the recent review. 🎉

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

@MartianGreed MartianGreed merged commit 80a54a2 into main Feb 13, 2026
10 checks passed
@MartianGreed MartianGreed deleted the fix/deep-merge-models branch February 13, 2026 07:50
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