@toolbox-web/grid-angular 1.0.0-rc.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2644,10 +2644,16 @@ function provideGridIcons(icons) {
2644
2644
  */
2645
2645
  function injectGrid(selector = 'tbw-grid') {
2646
2646
  const elementRef = inject(ElementRef);
2647
+ const destroyRef = inject(DestroyRef);
2647
2648
  // Reactive signals
2648
2649
  const isReady = signal(false, ...(ngDevMode ? [{ debugName: "isReady" }] : /* istanbul ignore next */ []));
2649
2650
  const config = signal(null, ...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
2650
2651
  const element = signal(null, ...(ngDevMode ? [{ debugName: "element" }] : /* istanbul ignore next */ []));
2652
+ // Track destruction so async work doesn't touch signals after teardown
2653
+ let destroyed = false;
2654
+ destroyRef.onDestroy(() => {
2655
+ destroyed = true;
2656
+ });
2651
2657
  // Initialize after render
2652
2658
  afterNextRender(() => {
2653
2659
  const gridElement = elementRef.nativeElement.querySelector(selector);
@@ -2656,13 +2662,22 @@ function injectGrid(selector = 'tbw-grid') {
2656
2662
  return;
2657
2663
  }
2658
2664
  element.set(gridElement);
2659
- // Wait for grid to be ready
2660
- gridElement.ready?.().then(async () => {
2665
+ // Wait for grid to be ready. Use Promise.resolve to guard against
2666
+ // gridElement.ready being undefined (would otherwise throw on .then).
2667
+ Promise.resolve(gridElement.ready?.())
2668
+ .then(async () => {
2669
+ if (destroyed)
2670
+ return;
2661
2671
  isReady.set(true);
2662
2672
  const effectiveConfig = await gridElement.getConfig?.();
2673
+ if (destroyed)
2674
+ return;
2663
2675
  if (effectiveConfig) {
2664
2676
  config.set(effectiveConfig);
2665
2677
  }
2678
+ })
2679
+ .catch((err) => {
2680
+ console.error('[injectGrid] Error waiting for grid to be ready:', err);
2666
2681
  });
2667
2682
  });
2668
2683
  // Computed visible columns