Skip to content

fix: fix blocks flashing on mount at zero-zero position#268

Merged
draedful merged 3 commits intogravity-ui:mainfrom
marshallern:fix-flashing-at-zero
Mar 23, 2026
Merged

fix: fix blocks flashing on mount at zero-zero position#268
draedful merged 3 commits intogravity-ui:mainfrom
marshallern:fix-flashing-at-zero

Conversation

@marshallern
Copy link
Contributor

@marshallern marshallern commented Mar 17, 2026

Problem

When blocks mount at the detailed react view, they flash at 0 0 position before rendering at the correct one.
How to reproduce

  1. Set the SCALES parameter in config at [0.15, 0.15, 0.20] so that even at small scales rendered a react component.
  2. Open some graph with the lots of blocks
  3. Start zooming-in and zooming-out so that new blocks mount

Why it happens

In Block.tsx useSignalEffect is only called after first render because it is run asynchronously. Hence, for a moment you can see blocks at the default positions at 0 0.

Solution

Create another hook that sets the correct block positions that is run before the first render.

Bug screencast: https://github.com/user-attachments/assets/460df84c-e16a-4d00-812c-0cf40a9cc48c

@gravity-ui-bot
Copy link
Contributor

Preview is ready.

Copy link
Collaborator

@draedful draedful left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to contribute and for the clear write-up — fixes like this really help the library, and we appreciate you digging into the flashing issue.

The approach with useLayoutEffect looks good. One small follow-up: the new effect duplicates the geometry / z-index logic that already lives in useSignalEffect. Would you mind extracting a shared helper (e.g. something like applyBlockContainerLayout(...)) and calling it from both places? That way we keep mount-time and signal-driven updates aligned if this block changes later

@marshallern
Copy link
Contributor Author

@draedful extracted the common logic and moved it to a separate utils file

@marshallern marshallern requested a review from draedful March 23, 2026 14:39
Copy link
Collaborator

@draedful draedful left a comment

Choose a reason for hiding this comment

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

Everything is fine, thanks for the contribution.

@draedful draedful merged commit 055ce4f into gravity-ui:main Mar 23, 2026
5 checks passed
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