Skip to content

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

Open
Antamansid wants to merge 1 commit intomainfrom
fix_achor_race_condition
Open

fix: resolve race condition in anchor positioning for newly created anchors#244
Antamansid wants to merge 1 commit 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.


public $selected = computed(() => this.block.store.anchorSelectionBucket.isSelected(this.id));

public $viewComponentReady = signal<boolean>(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you want to watch to viewComponentReady state, you have to unset that state on unmount Anchor component

protected unmount() {

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