@@ -137,7 +137,8 @@ import VRendererCell from './VRendererCell.vue'
137137import VAggregatorCell from ' ./VAggregatorCell.vue'
138138import VDragAndDropCell from ' ./VDragAndDropCell.vue'
139139import VPivottable from ' ../pivottable/VPivottable.vue'
140- import { computed , watch , shallowRef , watchEffect , onUnmounted } from ' vue'
140+ import TableRenderer from ' ../pivottable/renderer'
141+ import { computed , watch , toRaw } from ' vue'
141142import {
142143 usePropsState ,
143144 useMaterializeInput ,
@@ -182,6 +183,7 @@ const props = withDefaults(
182183 > (),
183184 {
184185 aggregators : () => defaultAggregators ,
186+ renderers : () => TableRenderer ,
185187 hiddenAttributes : () => [],
186188 hiddenFromAggregators : () => [],
187189 pivotModel: undefined ,
@@ -291,9 +293,10 @@ const { allFilters, materializedInput } = useMaterializeInput(
291293)
292294
293295const rendererItems = computed (() =>
294- Object .keys (state .renderers ).length ? state .renderers : {}
296+ state . renderers && Object .keys (state .renderers ).length ? state .renderers : {}
295297)
296298const aggregatorItems = computed (() => state .aggregators )
299+
297300const rowAttrs = computed (() => {
298301 return state .rows .filter (
299302 (e ) =>
@@ -327,38 +330,11 @@ const unusedAttrs = computed(() => {
327330 .sort (sortAs (pivotUiState .unusedOrder ))
328331})
329332
330- // Use shallowRef instead of computed to prevent creating new PivotData instances on every access
331- const pivotData = shallowRef (new PivotData (state ))
332-
333- // Update pivotData when state changes, and clean up the watcher
334- const stopWatcher = watchEffect (() => {
335- // Clean up old PivotData if exists
336- const oldPivotData = pivotData .value
337- pivotData .value = new PivotData (state )
338-
339- // Clear old data references
340- if (oldPivotData ) {
341- oldPivotData .tree = {}
342- oldPivotData .rowKeys = []
343- oldPivotData .colKeys = []
344- oldPivotData .rowTotals = {}
345- oldPivotData .colTotals = {}
346- oldPivotData .filteredData = []
347- }
348- })
349-
350- // Clean up on unmount
351- onUnmounted (() => {
352- stopWatcher ()
353- if (pivotData .value ) {
354- pivotData .value .tree = {}
355- pivotData .value .rowKeys = []
356- pivotData .value .colKeys = []
357- pivotData .value .rowTotals = {}
358- pivotData .value .colTotals = {}
359- pivotData .value .filteredData = []
360- }
361- })
333+ const pivotData = computed (() => new PivotData ({
334+ ... state ,
335+ data: toRaw (state .data ),
336+ aggregators: toRaw (state .aggregators )
337+ }))
362338const pivotProps = computed (() => ({
363339 data: state .data ,
364340 aggregators: state .aggregators ,
@@ -408,22 +384,19 @@ watch(
408384 } as Partial <typeof state >)
409385 }
410386 },
411- { deep: true , immediate: true }
387+ { immediate: true }
412388)
413389
414390watch (
415- [ allFilters , materializedInput ] ,
391+ materializedInput ,
416392 () => {
417- // Only update the changed properties, not the entire state
393+ // Only update data when materializedInput changes
418394 updateMultiple ({
419- allFilters: allFilters .value ,
420- materializedInput: materializedInput .value ,
421- data: materializedInput .value // Ensure data is also updated
395+ data: materializedInput .value
422396 })
423397 },
424398 {
425- immediate: true // Add immediate to ensure initial update
426- // Removed deep: true - this was causing 80% of memory leak
399+ immediate: true
427400 }
428401)
429402 </script >
0 commit comments