diff --git a/common/changes/@visactor/vtable/fix-issue-5217-null-container_2026-07-13-13-10.json b/common/changes/@visactor/vtable/fix-issue-5217-null-container_2026-07-13-13-10.json new file mode 100644 index 000000000..18175a2f2 --- /dev/null +++ b/common/changes/@visactor/vtable/fix-issue-5217-null-container_2026-07-13-13-10.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "fix: handle null table container", + "type": "none", + "packageName": "@visactor/vtable" + } + ], + "packageName": "@visactor/vtable", + "email": "biukam.w@gmail.com" +} \ No newline at end of file diff --git a/packages/vtable/__tests__/options/listTable-null-container.test.ts b/packages/vtable/__tests__/options/listTable-null-container.test.ts new file mode 100644 index 000000000..c65163c3d --- /dev/null +++ b/packages/vtable/__tests__/options/listTable-null-container.test.ts @@ -0,0 +1,10 @@ +// @ts-nocheck +import { ListTable } from '../../src'; + +global.__VERSION__ = 'none'; + +describe('ListTable null container', () => { + test('throws a clear error when the container argument is null', () => { + expect(() => new ListTable(null, { columns: [] })).toThrow("vtable's container is undefined"); + }); +}); diff --git a/packages/vtable/src/core/BaseTable.ts b/packages/vtable/src/core/BaseTable.ts index be40871fb..cc34e4ce4 100644 --- a/packages/vtable/src/core/BaseTable.ts +++ b/packages/vtable/src/core/BaseTable.ts @@ -267,7 +267,7 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI { if (Env.mode === 'node') { options = container as BaseTableConstructorOptions; container = null; - } else if (!(container instanceof HTMLElement)) { + } else if (container && !(container instanceof HTMLElement)) { options = container as BaseTableConstructorOptions; if ((container as BaseTableConstructorOptions).container) { container = (container as BaseTableConstructorOptions).container;