Skip to content

perf(grid-item): place a new item from its first render - #75

Closed
zahidzorbaz wants to merge 9 commits into
qmhc:mainfrom
dolusoft:pr/first-placement-r2
Closed

zahidzorbaz wants to merge 9 commits into
qmhc:mainfrom
dolusoft:pr/first-placement-r2

Conversation

@zahidzorbaz

Copy link
Copy Markdown
Contributor

Item 7 of the proposal in #71, stacked on #74. Please review only the last commit. Draft until the earlier PRs are merged.

Symptom

When a grid mounts or new items are added, items visibly fly in from the top-left corner of the container (in a 300-cell grid, all 300 did on load).

Cause

A GridItem that the registry has not confirmed yet renders with an empty style. If anything forces a style recalculation before the next render (common while a large page mounts), the browser fixes transform: none as the starting value of the transition, and the transform transition then animates each item from the container origin to its real position.

Change

  • An unconfirmed item renders with the box GridLayout has already committed for its id, instead of an empty style.
  • registered stays false until the registry pass, so ownership, interaction binding (no interactjs instance, no dragstart listener) and container-resized side effects are unchanged.
  • If the registry rejects the item, its style is cleared whether it was registered before or not.
  • An id change is not a first placement and keeps the existing behaviour.

Result: corner fly-in 300 → 0 cells. No public API change.

Tests

tests/first-placement.spec.tsx: the committed box is rendered before the registry confirms the item; an item with an invalid containing block has its box cleared and errors keep their order; missing-id and duplicate-id paths are unchanged; an unconfirmed item cannot start an interaction (checked on the per-element interactjs instance and dragstart listener, with a confirmed item as positive control).

pnpm test (460 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.
An item the registry has not confirmed yet now renders with the box
GridLayout already committed for its id instead of an empty style. The
empty first render let a forced style read fix transform: none, so new
items flew in from the container origin over the transform transition.
registered stays false until the registry pass, so ownership,
interaction binding and container-resized side effects are unchanged;
a rejected item has its style cleared whether it was registered before
or not.
@netlify

netlify Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for grid-layout-plus ready!

Name Link
🔨 Latest commit d91a4ab
🔍 Latest deploy log https://app.netlify.com/projects/grid-layout-plus/deploys/6ac5563267733d0008f4407c
😎 Deploy Preview https://deploy-preview-75--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