Use when Rust Yrs replicas converge but lose offline edits after creating nested shared maps independently, or when designing shared map initialization.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Rust Yrs Shared Map Identity?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/sickn33-rust-yrs-shared-map-identity)
---
name: rust-yrs-shared-map-identity
description: "Use when Rust Yrs replicas converge but lose offline edits after creating nested shared maps independently, or when designing shared map initialization."
category: development
risk: critical
source: self
source_type: self
date_added: "2026-12-02"
author: ShianMike
tags: [rust, yrs, yjs, crdt, offline-sync, shared-map]
---
# Rust Yrs Shared Map Identity
## When to Use
- Two replicas add different fields offline and one entry disappears after synchronization.
- Each client initializes a nested `MapPrelim` when a parent key is missing.
- A shared document schema needs a top-level namespace or an initialization step for nested shared types.
## Prerequisites
- Record the Yrs version, the update encoding used by all peers, and the names and types of shared roots.
- Identify which transaction integrates each nested shared object and when another peer can first see it.
- Use distinct client IDs for active replicas. Fixed IDs are useful in synthetic tests that need deterministic outcomes.
## 1. Find the object each peer actually edits
1. Trace the parent key and child object separately. Two peers can assign different shared map objects to the same parent key. Both assignments compete, even when their child edits use different keys.
2. Check whether edits go through the integrated map already stored under the key. Creating another `MapPrelim` and assigning it replaces the parent entry.
3. Capture snapshots before either peer receives the other's changes. Compare the visible result after both updates arrive and confirm the expected fields on both replicas.
```text
Replica A creates project.notes, then inserts alpha
Replica B creates another project.notes, then inserts beta
After sync replicas agree on one visible notes map
```
## 2. Arrange for the peers to edit one shared object
1. For stable document-wide collections, consider a named root map via `Doc::get_or_insert_map`. The root name and shared kind form part of the application schema. Both peers use the same root and insert their own entries into it.
2. For a collection nested under a parent record, integrate the child once and distribute that document update before peers edit it offline. Have existing clients retrieve and mutate the integrated child.
3. Handle a missing child explicitly during sync or recovery. An empty local view can mean that the document is insufficiently initialized. For truly concurrent nested creation, define an application-level merge or choose a root layout that supports independently created entries.
## 3. Verify offline semantics and replay
1. Assert both visible content and convergence. Include a case with distinct entry keys and another for writes to the same key if the product relies on it.
2. Exchange updates captured before either receives the other. Test replay and, when relevant, out-of-order or duplicate delivery with the real update encoding.
3. For existing documents, test saved updates and schema migration in disposable replicas. Preserve the original serialized state until visible entries and references are verified.
## Example
Run the [two-replica fixture](references/concurrent-nested-map-creation.md). It checks independent nested creation, edits to a named root, and edits to a nested map initialized once and shared.
## Limitations
- The fixture uses in-memory Rust peers and V1 full-state updates. It does not test JavaScript interoperability, a transport, incremental sync recovery, or persistence.
- Sharing one map retains concurrent edits at separate keys. Concurrent assignments to the same key still follow map conflict rules.
## Safety and Side Effects
- The fixture mutates synthetic in-memory documents. Cargo writes a scratch lockfile and build artifacts.
- Changing a shared root or nested layout affects persisted updates. Verify migration and recovery before changing production documents.
## Related Skills and Documentation
- For Rust client state and persistence, see [Robius State Management](https://github.com/sickn33/agentic-awesome-skills/blob/main/skills/robius-state-management/SKILL.md).
- For Rust development, see [Rust Pro](https://github.com/sickn33/agentic-awesome-skills/blob/main/skills/rust-pro/SKILL.md).
- See [Yrs shared and integrated types](https://docs.rs/yrs/latest/yrs/), [MapRef conflict resolution](https://docs.rs/yrs/latest/yrs/types/map/struct.MapRef.html), and the [Yjs map API](https://docs.yjs.dev/api/shared-types/y.map).