Skip to content

fix: resolve race condition in anchor positioning for newly created anchors#244

Merged
Antamansid merged 2 commits intomainfrom
fix_achor_race_condition
Feb 17, 2026
Merged

fix: resolve race condition in anchor positioning for newly created anchors#244
Antamansid merged 2 commits intomainfrom
fix_achor_race_condition

Conversation

@Antamansid
Copy link
Collaborator

Problem

When creating new endpoints on HTML layer (zoomed-in React rendering), a race condition occurred between React and Canvas rendering cycles:

  • React components immediately subscribed to $anchorStates signal changes
  • Canvas anchor initialization happened later via lifecycle hooks
  • React tried to access anchor position before Canvas component was ready
  • This caused crashes or incorrect positioning (anchors rendered at 0,0)

Solution

Added a readiness signal to synchronize React and Canvas rendering:

  1. AnchorState: Added public $viewComponentReady signal
  2. setViewComponent(): Sets the signal to true when Canvas anchor is initialized
  3. useBlockAnchorPosition(): Waits for readiness before accessing anchor position

This ensures React re-renders automatically when the Canvas component becomes available, eliminating the race condition without breaking encapsulation.

@Antamansid Antamansid requested a review from draedful as a code owner February 13, 2026 10:25
@gravity-ui-bot
Copy link
Contributor

Preview is ready.

@Antamansid Antamansid requested a review from draedful February 17, 2026 15:07
@Antamansid Antamansid merged commit 9ce95c5 into main Feb 17, 2026
4 checks passed
@Antamansid Antamansid deleted the fix_achor_race_condition branch February 17, 2026 15:27
@gravity-ui gravity-ui bot mentioned this pull request Feb 17, 2026
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.

3 participants

Comments