From 6c58dfdcdfca02fb087f99813e484afdc04a2b51 Mon Sep 17 00:00:00 2001 From: nicole chung <771170+nicolechung@users.noreply.github.com> Date: Tue, 5 Sep 2023 09:20:54 -0400 Subject: [PATCH] fix: Resize plugin, add destroy check (#226) --- .changeset/fresh-oranges-scream.md | 7 +++++++ ember-headless-table/src/plugins/column-resizing/plugin.ts | 5 +++++ 2 files changed, 12 insertions(+) create mode 100644 .changeset/fresh-oranges-scream.md diff --git a/.changeset/fresh-oranges-scream.md b/.changeset/fresh-oranges-scream.md new file mode 100644 index 00000000..ae5c65d6 --- /dev/null +++ b/.changeset/fresh-oranges-scream.md @@ -0,0 +1,7 @@ +--- +'ember-headless-table': patch +--- + +Bugfix: the plugin for resize was not checking if the table was destroyed first. + +This fixes that so the observer is not listening for a removed table, which was causing an error in the preferences (since it was trying to set preferences for a table which is not on screen) diff --git a/ember-headless-table/src/plugins/column-resizing/plugin.ts b/ember-headless-table/src/plugins/column-resizing/plugin.ts index af9d3291..20b933aa 100644 --- a/ember-headless-table/src/plugins/column-resizing/plugin.ts +++ b/ember-headless-table/src/plugins/column-resizing/plugin.ts @@ -1,5 +1,6 @@ import { cached, tracked } from '@glimmer/tracking'; import { assert } from '@ember/debug'; +import { isDestroyed, isDestroying } from '@ember/destroyable'; import { action } from '@ember/object'; import { preferences } from '[public-plugin-types]'; @@ -435,6 +436,10 @@ function getObserver(element: HTMLElement, table: Table): ResizeObserver { if (existing) return existing; existing = new ResizeObserver((entries: ResizeObserverEntry[]) => { + if (isDestroyed(table) || isDestroying(table)) { + return; + } + for (let entry of entries) { meta.forTable(table, ColumnResizing).onTableResize(entry); }