carbon-components-svelte 0.89.0 → 0.89.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-components-svelte",
3
- "version": "0.89.0",
3
+ "version": "0.89.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Svelte implementation of the Carbon Design System",
6
6
  "type": "module",
@@ -46,15 +46,39 @@
46
46
  */
47
47
  export let ref = null;
48
48
 
49
- import { tick, getContext } from "svelte";
49
+ import { tick, getContext, afterUpdate, onMount } from "svelte";
50
50
  import Search from "../Search/Search.svelte";
51
51
 
52
52
  const ctx = getContext("DataTable") ?? {};
53
53
 
54
+ let rows = null;
55
+ let unsubscribe = null;
56
+
54
57
  $: if (shouldFilterRows) {
55
- filteredRowIds = ctx?.filterRows(value, shouldFilterRows);
58
+ unsubscribe = ctx?.tableRows.subscribe((tableRows) => {
59
+ // Only update if the rows have actually changed.
60
+ // This approach works in both Svelte 4 and Svelte 5.
61
+ if (JSON.stringify(tableRows) !== JSON.stringify(rows)) {
62
+ rows = tableRows;
63
+ }
64
+ });
65
+ } else {
66
+ rows = null;
56
67
  }
57
68
 
69
+ onMount(() => {
70
+ return () => {
71
+ unsubscribe?.();
72
+ };
73
+ });
74
+
75
+ afterUpdate(() => {
76
+ // Only filter rows in a callback to avoid an infinite update loop.
77
+ if (rows !== null) {
78
+ filteredRowIds = ctx?.filterRows(value, shouldFilterRows);
79
+ }
80
+ });
81
+
58
82
  async function expandSearch() {
59
83
  await tick();
60
84
  if (disabled || persistent || expanded) return;