Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Change log
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*

- [14.1.1 (TBD)](#1411-tbd)
- [14.1.0 (2026-11-04)](#1410-2026-11-04)
- [14.0.0 (2026-09-20)](#1400-2026-09-20)
- [13.3.0 (2026-09-11)](#1330-2026-09-11)
Expand Down Expand Up @@ -148,6 +149,9 @@ Change log

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## 14.1.1 (TBD)
* fix: [#3459](https://github.com/gridstack/gridstack.js/issues/3459) React/Vue wrappers: a `change` event fired mid drag/resize no longer unmounts the item's content (state lost)

## 14.1.0 (2026-11-04)
* feat: [#3451](https://github.com/gridstack/gridstack.js/pull/3451), [#3452](https://github.com/gridstack/gridstack.js/pull/3452) dragging between grids now goes by how much of the item is over a grid (like jquery-ui's `intersect` before v6) rather than where the cursor is. Also make it possible to insert above a nested grid even when parent grid overlapps exactly.
* feat: [#3356](https://github.com/gridstack/gridstack.js/issues/3356) auto-scroll triggers off the cursor nearing an edge (not just widget being clipped)
Expand Down
41 changes: 41 additions & 0 deletions react/projects/lib/gridstack-react.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,47 @@ describe("GridStack React wrapper", () => {
expect(document.querySelector('[data-testid="h"]')?.textContent).toBe("5");
});

it("#3459 keeps item content mounted when change fires while node.el is the drag placeholder", async () => {
let mounts = 0;
function Probe() {
useState(() => { mounts++; return 0; });
return <span data-testid="probe">hi</span>;
}

await act(async () => {
root.render(
<GridStack
options={{
column: 12, cellHeight: 50, margin: 0,
children: [{ id: "p1", x: 0, y: 0, w: 2, h: 2, component: "P" }],
}}
components={{ P: () => <Probe /> }}
/>
);
});
await act(flush);
expect(document.querySelector('[data-testid="probe"]')).not.toBeNull();

const g = (container.querySelector(".grid-stack") as GridHTMLElement).gridstack as GridStackInstance;
const node = g.engine.nodes[0];
const realEl = node.el!;

// what _onStartMoving leaves behind: node.el is the placeholder (no .grid-stack-item-content)
node.el = g.placeholder;
const t = g as unknown as { _triggerChangeEvent(): unknown };
await act(async () => {
node.h = 3;
node._dirty = true;
t._triggerChangeEvent();
});
await act(flush);

expect(document.querySelector('[data-testid="probe"]')).not.toBeNull();
expect(mounts).toBe(1);

node.el = realEl;
});

it("#2960 useGridStack().removeWidget takes an element, matching core's signature", async () => {
let api: ReturnType<typeof useGridStack> | undefined;
function Probe() {
Expand Down
4 changes: 3 additions & 1 deletion react/projects/lib/src/gridstack-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export function GridStackItem({
const node = Utils.findInGrid(grid, id, true);
const cont =
(node?.el?.querySelector(".grid-stack-item-content") as HTMLElement | null) ?? null;
setContainer((prev) => (prev === cont ? prev : cont));
// Mid drag/resize `node.el` is GS's placeholder (no content container); a `change` fired then
// must not null the container or the portal unmounts and the widget loses its state (#3459).
setContainer((prev) => (prev === cont ? prev : !cont && node && prev?.isConnected ? prev : cont));
}, [grid, id, layoutVersion, optsKey]);

// Tracks whether the component is "truly unmounting" vs. Strict Mode double-invoke.
Expand Down
41 changes: 41 additions & 0 deletions vue/projects/lib/gridstack-vue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,45 @@ describe('GridStack Vue wrapper', () => {

expect(document.querySelector('[data-testid="h"]')?.textContent).toBe('5')
})

it('keeps item content mounted when change fires while node.el is the drag placeholder (#3459)', async () => {
let mounts = 0
const Probe = defineComponent({
setup() {
mounts++
return () => h('span', { 'data-testid': 'probe' }, 'hi')
},
})

const Root = defineComponent({
setup() {
const options = {
column: 12, cellHeight: 50, margin: 0,
children: [{ id: 'p1', x: 0, y: 0, w: 2, h: 2, component: 'P' }],
}
return () => h(GridStack, { options, components: { P: Probe } })
},
})

;({ app, container } = mountApp(Root))
await flush()
expect(document.querySelector('[data-testid="probe"]')).not.toBeNull()

const g = (container.querySelector('.grid-stack') as GridHTMLElement).gridstack!
const node = g.engine.nodes[0]
const realEl = node.el!

// what _onStartMoving leaves behind: node.el is the placeholder (no .grid-stack-item-content)
node.el = g.placeholder
const t = g as unknown as { _triggerChangeEvent(): unknown }
node.h = 3
node._dirty = true
t._triggerChangeEvent()
await flush()

expect(document.querySelector('[data-testid="probe"]')).not.toBeNull()
expect(mounts).toBe(1)

node.el = realEl
})
})
3 changes: 3 additions & 0 deletions vue/projects/lib/src/gridstack-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export const GridStackItem = defineComponent({
if (!g) return
const node = Utils.findInGrid(g, props.id, true)
const cont = (node?.el?.querySelector('.grid-stack-item-content') as HTMLElement | null) ?? null
// Mid drag/resize `node.el` is GS's placeholder (no content container); a `change` fired then
// must not null the target or the teleport unmounts and the widget loses its state (#3459).
if (!cont && node && containerEl.value?.isConnected) return
containerEl.value = cont
}

Expand Down