Skip to content

perf(grid-item): write the position style to the element instead of re-rendering - #74

Closed
zahidzorbaz wants to merge 8 commits into
qmhc:mainfrom
dolusoft:pr/direct-position-style-r2
Closed

zahidzorbaz wants to merge 8 commits into
qmhc:mainfrom
dolusoft:pr/direct-position-style-r2

Conversation

@zahidzorbaz

Copy link
Copy Markdown
Contributor

Item 6 of the proposal in #71, stacked on #73. Please review only the last two commits. Draft until the earlier PRs are merged.

Problem

Even with equal styles skipped, an item whose box does change is re-rendered. Each re-render runs onUpdated, which requests a registry pass, and the pass reads offsetParent, forcing a style/layout recalculation of the whole grid. During a drag this happens on every pointer step.

Change

  • perf(grid-item): write the position style to the element instead of re-rendering: GridItem keeps state.style as the source of truth. A synchronous watcher mirrors it into a non-reactive renderStyle object and into the element's inline style, writing only changed properties and removing keys the next style no longer has. The template binds renderStyle, so other re-renders (fallthrough style/class, SSR, first mount) always output current values. The root renders under v-if="renderStyle", so a GridItem outside a GridLayout still renders nothing. Position style keys and values are limited by validatePositionStyleResult and cannot change the item's containing block, so skipping the registry pass for a box-only change does not weaken the ownership guarantee.
  • perf(grid-layout): read every ownership fact before a registry pass writes: a registry pass reads layout membership and the DOM ownership facts of all registered items first, then applies registration state, style resets, interaction unbinding and errors in the same order as before. A rejected item's style reset no longer sits between two offsetParent reads.

In a Chrome run with 300 cells and the earlier PRs applied, the pointermove handler during a drag went from 345 ms to 2 ms. No public API change.

Behaviour note for review: position keys (transform, top, width, ...) passed through an external style attribute on GridItem are not supported; the direct write wins until the next render. If you want that case handled explicitly (for example by dropping those keys from the fallthrough style), I can add it.

Tests

tests/style-equality.spec.tsx (new describe): an external update validates once; drag steps start no registry pass (with a positive control); fallthrough style/class re-renders keep the current box; the exposed style state and the element agree after moves and a reset; the placeholder follows the drag. tests/registry-validation.spec.tsx: a pass reads every containing block before it writes any rejected item.

pnpm test (456 passed), pnpm lint, pnpm lint:style, pnpm test:types, pnpm check:docs and pnpm build pass.

…loop

Validation, compactor result checks and the engine collision helpers ran an
O(n^2) pairwise loop on every layout, even when layouts have no
collision. hasAnyCollision sorts items by their top edge (y) and sweeps once; the pairwise
loop now only runs when the sweep found an overlap, to report the same
first colliding item as before.
The engine's committed layout, session base and working copies and each
evaluation's next layout are now deep-frozen after their validating
clone and recorded in a private WeakSet. Snapshotting a recorded array
copies it field by field instead of re-reading every descriptor, and
states that never change are shared instead of cloned. External inputs keep the validating
path. Returned and emitted layout
arrays and items remain mutable copies, isolated from internal state.
…hanged

Every commit and drag step bumps positionStyleRevision and each GridItem
recomputes its style. A new object with the same values still triggered a
re-render, so every item re-rendered whenever any item moved. GridItem now
assigns the style only when sameStyle finds a difference; GridLayout keeps
the root height object and renderedLayoutStyle the same way.
The layout watcher runs before the config watcher, so a layout that arrived
together with a new colNum was validated with the old column count. Going
from a narrow to a wide grid (colNum 1 -> 12) emitted a transient
invalid-layout and one invalid-registration (missing-id) per new item, then
recovered a tick later.

In non-responsive mode the layout is now observed with the incoming colNum
(restored when the layout is not accepted), and snapshotObservedLayout
validates with the same next config acceptExternalLayout applies. A layout
that does not fit the new colNum is still rejected.
Every GridItem onUpdated validated the whole registry synchronously and each
registration queued another full pass; every pass searched the deep reactive
currentLayout linearly per item. With n items re-rendering this was O(n^3)
proxy reads during a flush that re-rendered all items.

- the registry keeps at most one deferred pass, queued with queuePostFlushCb
  so it runs at the end of the current flush; synchronous passes consume it
- hasLayoutItem, the injected GridItem lookup and the resize constraint check
  use an id index built from the raw layout once per replacement
- id-change cancellation and the interaction/layout-sync passes stay synchronous
…ndler

Vue runs post-flush callbacks without try/finally, so a throw from the
queuePostFlushCb validation left activePostFlushCbs set and stopped every
later updated/mounted hook and flush: 'post' watcher on the page. The
callback now catches and reports through handleError (SCHEDULER) on the
GridLayout instance; a throwing errorHandler is rethrown from a microtask.

Tests: the scheduler keeps running after a throwing pass; an invalid
registration is emitted in the same flush, before a later nextTick; an id
removed by an external layout update is missing-id through the index.
…e-rendering

A box-only change re-rendered every moved GridItem, and each re-render queued a registry
pass that read offsetParent and forced a style/layout of the whole grid. GridItem now
keeps
state.style as the source and syncs a non-reactive renderStyle plus the element's inline
style from a synchronous watcher, writing only the changed properties. Other re-renders
still patch the current values, so merged fallthrough styles never restore a stale box.
The root renders under v-if="renderStyle" so a GridItem outside GridLayout keeps
rendering nothing (E2E-26).
…rites

The registry pass now reads layout membership and the DOM ownership
facts of all registered items first, then applies registration state,
style resets, interaction unbinding and errors in the same order as
before. A rejected item's style reset no longer sits between two
offsetParent reads, so it no longer forces a style/layout per rejected
item.
@netlify

netlify Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for grid-layout-plus ready!

Name Link
🔨 Latest commit f019dd0
🔍 Latest deploy log https://app.netlify.com/projects/grid-layout-plus/deploys/6ac5562c642ade0008f5a6ae
😎 Deploy Preview https://deploy-preview-74--grid-layout-plus.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@qmhc
qmhc marked this pull request as ready for review October 13, 2026 04:06
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.

2 participants