@tanstack/svelte-table 9.0.0-beta.38 → 9.0.0-beta.43

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.
@@ -1,264 +0,0 @@
1
- ---
2
- name: svelte/migrate-v8-to-v9
3
- description: >
4
- Mechanical migration from `@tanstack/svelte-table@8` to `@tanstack/svelte-table@9`. v9 in Svelte
5
- is a full rewrite — Svelte 5 runes only (no Svelte 3/4), no `/legacy` adapter (unlike React),
6
- `createSvelteTable` → `createTable`, `getCoreRowModel` / `getSortedRowModel` factories →
7
- row-model factories registered as slots inside `tableFeatures({...})`, `flexRender` helper →
8
- `<FlexRender>` component, writable-store `state` → rune-based getters / external atoms,
9
- `onStateChange` → per-slice `on[State]Change` or `atoms`. Plan a feature-by-feature audit, not a
10
- search-and-replace.
11
- type: lifecycle
12
- library: tanstack-table
13
- framework: svelte
14
- library_version: '9.0.0-alpha.48'
15
- requires:
16
- - setup
17
- - state-management
18
- - column-definitions
19
- sources:
20
- - TanStack/table:docs/framework/svelte/svelte-table.md
21
- - TanStack/table:docs/framework/svelte/guide/table-state.md
22
- - TanStack/table:packages/svelte-table/src/
23
- - TanStack/table:examples/svelte/basic-create-table/
24
- - TanStack/table:examples/svelte/basic-external-atoms/
25
- - TanStack/table:examples/svelte/basic-external-state/
26
- ---
27
-
28
- # Migrate v8 → v9 (Svelte)
29
-
30
- ## CRITICAL: v9 = Svelte 5
31
-
32
- **v9 of the Svelte adapter only supports Svelte 5+.** No backport. No shim. No `/legacy` import.
33
- The v9 adapter is built on Svelte 5 runes (`$state`, `$derived.by`, `$effect.pre`). If your app
34
- is still on Svelte 3/4, you have two real options:
35
-
36
- 1. Stay on `@tanstack/svelte-table@8`. v8 keeps working with the Svelte 3/4 writable-store API.
37
- 2. Migrate the app to Svelte 5 first, then migrate the table.
38
-
39
- There is no third option. Trying to install v9 on a Svelte 4 codebase will error at compile.
40
-
41
- > This makes the Svelte migration heavier than React's. React has a `/legacy` re-export that
42
- > mirrors the v8 surface; Svelte does not. Plan for a real rewrite of every table screen.
43
-
44
- ## What changed at the type / API level
45
-
46
- | v8 | v9 |
47
- | -------------------------------------------------- | ------------------------------------------------------------------------------------- |
48
- | `createSvelteTable(options)` | `createTable(options, selector?)` |
49
- | `getCoreRowModel()` | included by default; no factory |
50
- | `getPaginationRowModel()` | `tableFeatures({ paginatedRowModel: createPaginatedRowModel() })` |
51
- | `getSortedRowModel()` | `tableFeatures({ sortedRowModel: createSortedRowModel(), sortFns })` |
52
- | `getFilteredRowModel()` | `tableFeatures({ filteredRowModel: createFilteredRowModel(), filterFns })` |
53
- | `getExpandedRowModel()` | `tableFeatures({ expandedRowModel: createExpandedRowModel() })` |
54
- | `getGroupedRowModel()` | `tableFeatures({ groupedRowModel: createGroupedRowModel(), aggregationFns })` |
55
- | `getFacetedRowModel()` / `MinMax` / `UniqueValues` | facet APIs auto-derived when `*Facet*Feature` registered |
56
- | `flexRender(template, ctx)` helper | `<FlexRender header={h} />` / `<FlexRender cell={c} />` / `<FlexRender footer={h} />` |
57
- | `ColumnDef<TData>` | `ColumnDef<TFeatures, TData>` (extra generic) |
58
- | `createColumnHelper<TData>()` | `createColumnHelper<TFeatures, TData>()` |
59
- | writable store on the table instance | `table.atoms.<slice>` + `table.store` + `table.state` |
60
- | `onStateChange` (monolithic) | per-slice `on[State]Change`, or external `atoms` |
61
- | `useSvelteTable` (rare) | gone |
62
-
63
- ## What did NOT change
64
-
65
- - The data array is still the source of truth; columns are still defined the same way
66
- shape-wise (`accessorKey` / `accessorFn` / `header` / `cell` / `footer`).
67
- - Filter, sort, aggregation function registries are still `filterFns`, `sortFns`,
68
- `aggregationFns` — but now passed into row-model factories instead of being auto-resolved.
69
- - Feature APIs (`table.nextPage()`, `column.getCanSort()`, `row.toggleSelected()`) keep the
70
- same names.
71
-
72
- ## Migration checklist (per file)
73
-
74
- For each Svelte component that uses the table:
75
-
76
- 1. **Upgrade Svelte.** Ensure the app is on Svelte 5 and the component compiles in runes mode.
77
- 2. **Replace store with rune.** `let data = writable([])` → `let data = $state([])`. Reads
78
- inside markup are no longer `$data` — just `data`.
79
- 3. **Import surface.** `import { createSvelteTable, getCoreRowModel, flexRender }` →
80
- `import { createTable, FlexRender, tableFeatures, ... }`.
81
- 4. **Add `features`.** Create `const features = tableFeatures({ ... only the features this
82
- table uses ... })`.
83
- 5. **Move row-model factories into `tableFeatures`.** Every `get*RowModel: get*RowModel()` becomes a slot inside `tableFeatures({ ..., create*RowModel() })`. Any `*Fns` registry that was passed as a factory argument is now also a named slot in the same `tableFeatures` call.
84
- 6. **Generic columns.** Add `<typeof features, TData>` to `ColumnDef<>` and
85
- `createColumnHelper<>()`. TypeScript will tell you when you missed one.
86
- 7. **`data` as a getter.** `data: data` → `get data() { return data }`. Same for any other
87
- reactive option (`state.*`, `columns`, `rowCount`).
88
- 8. **State.** Pick the new ownership model — see below.
89
- 9. **Rendering.** `{flexRender(header.column.columnDef.header, header.getContext())}` →
90
- `<FlexRender header={header} />`. Same for cells and footers.
91
- 10. **Components / snippets in cells.** v8: pass a Svelte component constructor. v9: wrap with
92
- `renderComponent(MyCell, props)` or `renderSnippet(snippet, args)`.
93
-
94
- ## State ownership — choose one per slice
95
-
96
- ### Was: `writable` store + `onStateChange`
97
-
98
- ```svelte
99
- <script lang="ts">
100
- // v8
101
- import { writable } from 'svelte/store'
102
- const options = writable({ data, columns })
103
- $: $options.state = $state
104
- </script>
105
- ```
106
-
107
- ### Now: pick one of three
108
-
109
- **Internal (default).** Pass only `initialState` and let the table own it.
110
-
111
- ```ts
112
- const table = createTable({
113
- features,
114
- columns,
115
- get data() {
116
- return data
117
- },
118
- initialState: {
119
- pagination: { pageIndex: 0, pageSize: 25 },
120
- },
121
- })
122
- ```
123
-
124
- **External `state` + per-slice `on[State]Change`.** Closest to a literal v8 port.
125
-
126
- ```svelte
127
- <script lang="ts">
128
- let sorting: SortingState = $state([])
129
- let pagination: PaginationState = $state({ pageIndex: 0, pageSize: 10 })
130
-
131
- const table = createTable({
132
- features,
133
- columns,
134
- get data() {
135
- return data
136
- },
137
- state: {
138
- get sorting() {
139
- return sorting
140
- },
141
- get pagination() {
142
- return pagination
143
- },
144
- },
145
- onSortingChange: (updater) => {
146
- sorting = updater instanceof Function ? updater(sorting) : updater
147
- },
148
- onPaginationChange: (updater) => {
149
- pagination = updater instanceof Function ? updater(pagination) : updater
150
- },
151
- })
152
- </script>
153
- ```
154
-
155
- **External atoms (preferred for shared state).** Atomic, subscribable from anywhere.
156
-
157
- ```ts
158
- import { createAtom, useSelector } from '@tanstack/svelte-store'
159
-
160
- const sortingAtom = createAtom<SortingState>([])
161
- const paginationAtom = createAtom<PaginationState>({
162
- pageIndex: 0,
163
- pageSize: 10,
164
- })
165
-
166
- const sorting = useSelector(sortingAtom)
167
- const pagination = useSelector(paginationAtom)
168
-
169
- const table = createTable({
170
- features,
171
- columns,
172
- get data() {
173
- return data
174
- },
175
- atoms: {
176
- sorting: sortingAtom,
177
- pagination: paginationAtom,
178
- },
179
- })
180
- ```
181
-
182
- **Do not combine** `state.pagination` with `atoms.pagination` — atoms always win, `state` is
183
- discarded silently, you'll think your callbacks aren't firing.
184
-
185
- ## Rendering migration cheat sheet
186
-
187
- ```svelte
188
- <!-- v8 -->
189
- <th>
190
- {#if !header.isPlaceholder}
191
- <svelte:component
192
- this={flexRender(header.column.columnDef.header, header.getContext())}
193
- />
194
- {/if}
195
- </th>
196
-
197
- <!-- v9 -->
198
- <th>
199
- {#if !header.isPlaceholder}
200
- <FlexRender {header} />
201
- {/if}
202
- </th>
203
- ```
204
-
205
- For cells that render a custom Svelte component:
206
-
207
- ```svelte
208
- <!-- v8: column def -->
209
- { cell: () => MyCellComponent }
210
-
211
- <!-- v9: column def -->
212
- import { renderComponent } from '@tanstack/svelte-table'
213
- { cell: ({ row }) => renderComponent(MyCellComponent, { row }) }
214
- ```
215
-
216
- For inline snippets:
217
-
218
- ```svelte
219
- <!-- v9 -->
220
- import { renderSnippet } from '@tanstack/svelte-table'
221
-
222
- {#snippet myCell(row)}
223
- <strong>{row.original.firstName}</strong>
224
- {/snippet}
225
-
226
- { cell: ({ row }) => renderSnippet(myCell, row) }
227
- ```
228
-
229
- ## After the rewrite — verify
230
-
231
- - `pnpm test:types` (or `svelte-check`) catches missing `<typeof features, TData>` generics,
232
- missing `features` or row-model factory slots, and feature APIs called on tables that didn't
233
- register them.
234
- - `pnpm build` should pass with the new `features` set. Bundle should shrink — only the
235
- features you register are included.
236
- - Click through every table screen. Reset buttons, multi-sort, pagination reset on filter,
237
- expanded-row count under pagination — these are all the spots where v8 muscle memory
238
- reaches for an option (`autoResetPageIndex` etc.) that's still named the same in v9 but
239
- only takes effect if the matching feature is registered.
240
-
241
- ## Common failure modes during migration
242
-
243
- - **Trying to skip the Svelte 5 upgrade.** Will not work.
244
- - **Reaching for `useLegacyTable`.** Doesn't exist in `@tanstack/svelte-table`. That's a
245
- React-only escape hatch.
246
- - **Importing from `@tanstack/table-core` directly.** Re-exported by the adapter — go through
247
- the adapter.
248
- - **Plain `data` instead of `get data()` getter.** Largest single source of "but my data
249
- changed" bugs during migration.
250
- - **Plain `features: { rowPaginationFeature }` instead of `tableFeatures({...})`.** Loses
251
- inference; you'll get `any` everywhere.
252
- - **Forgetting feature registration after adding the row-model factory slot.** Adding
253
- `paginatedRowModel: createPaginatedRowModel()` to `tableFeatures` without also including
254
- `rowPaginationFeature` does nothing.
255
- - **Reimplementing v8 helpers** (`flexRender`-style functions, manual store subscriptions,
256
- hand-rolled selectors) instead of using `FlexRender` / `subscribeTable` / atom selectors.
257
- That's the #1 AI tell on this migration.
258
-
259
- ## Related skills
260
-
261
- - `tanstack-table/svelte/getting-started` — clean-slate setup.
262
- - `tanstack-table/svelte/table-state` — the v9 state model in depth.
263
- - `tanstack-table/core/state-management` — atom precedence rules.
264
- - `tanstack-table/svelte/production-readiness` — post-migration tuning.
@@ -1,258 +0,0 @@
1
- ---
2
- name: svelte/production-readiness
3
- description: >
4
- Ship-ready optimizations for `@tanstack/svelte-table@9` on Svelte 5. Tree-shake by registering
5
- ONLY the `features` you use; keep `features`, `columns`, and `data` stable; replace broad
6
- `(state) => state` selectors with narrow projections on `createTable`; reach for
7
- `subscribeTable(atom, selector?)` when only one block of markup should react; lean on rune-aware
8
- atom reads (`table.atoms.<slice>.get()`) for non-reactive paths; key every `{#each}` block on
9
- stable ids; debounce high-frequency writes with `@tanstack/svelte-pacer`. Svelte 5+ only.
10
- type: lifecycle
11
- library: tanstack-table
12
- framework: svelte
13
- library_version: '9.0.0-alpha.48'
14
- requires:
15
- - setup
16
- - state-management
17
- - svelte/table-state
18
- sources:
19
- - TanStack/table:docs/guide/features.md
20
- - TanStack/table:docs/framework/svelte/guide/table-state.md
21
- - TanStack/table:packages/svelte-table/src/createTable.svelte.ts
22
- - TanStack/table:packages/svelte-table/src/subscribe.ts
23
- - TanStack/table:examples/svelte/basic-external-atoms/
24
- - TanStack/table:examples/svelte/virtualized-rows/
25
- ---
26
-
27
- # Production Readiness — Svelte
28
-
29
- Once your tables work, this is the checklist for making them fast and small. Most of these are
30
- v9-specific — v8 tables won't have any of these levers.
31
-
32
- ## 1. Register only the features you use
33
-
34
- `features` is the bundle gate. Any feature you don't register is tree-shaken out — including
35
- its state slice, its API surface, and its reactive plumbing.
36
-
37
- ```ts
38
- // good — minimal table, ~smallest bundle
39
- const features = tableFeatures({})
40
-
41
- // good — feature-by-feature opt-in
42
- const features = tableFeatures({
43
- rowPaginationFeature,
44
- rowSortingFeature,
45
- })
46
-
47
- // bad — kitchen sink, every state slice created even when unused
48
- const features = tableFeatures({
49
- columnFilteringFeature,
50
- columnGroupingFeature,
51
- columnOrderingFeature,
52
- columnPinningFeature,
53
- columnResizingFeature,
54
- columnSizingFeature,
55
- columnVisibilityFeature,
56
- globalFilteringFeature,
57
- rowExpandingFeature,
58
- rowPaginationFeature,
59
- rowPinningFeature,
60
- rowSelectionFeature,
61
- rowSortingFeature,
62
- })
63
- ```
64
-
65
- If you find yourself running a table without a feature's UI ever showing, drop the feature.
66
-
67
- ## 2. Stable identities for `features`, `columns`, `data`
68
-
69
- `createTable` syncs options in `$effect.pre`. If any of these identities flip every component
70
- run, the table re-syncs more than it needs to.
71
-
72
- - **`features`**: declare at module scope, not inside the component function, and never
73
- inside `$derived` / `$effect`. The `features` object now also carries row-model factories
74
- and `*Fns` registries, so keeping it stable prevents unnecessary re-sync.
75
- - **`columns`**: same — module scope or `$state.frozen` / a non-reactive `const` in the
76
- component. Reactive recompute of columns is rare and almost always a bug.
77
- - **`data`**: pass with a getter (`get data()`) so the reference is stable when the data
78
- doesn't change. If you're reshaping data inside the component, do it once in a `$derived`,
79
- not on every read.
80
-
81
- ```svelte
82
- <script lang="ts">
83
- // module scope is fine in .svelte too, when truly static
84
- const features = tableFeatures({
85
- rowPaginationFeature,
86
- paginatedRowModel: createPaginatedRowModel(),
87
- })
88
- const columns = columnHelper.columns([
89
- /* ... */
90
- ])
91
-
92
- let rawRows = $state<Person[]>([])
93
- const data = $derived(rawRows.map(normalize)) // computed once per rawRows change
94
-
95
- const table = createTable({
96
- features,
97
- columns,
98
- get data() {
99
- return data
100
- },
101
- })
102
- </script>
103
- ```
104
-
105
- ## 3. Narrow the `table.state` selector
106
-
107
- The default selector is `(state) => state`. That makes `table.state` re-run any consumer when
108
- **any** slice changes. Pass a focused selector and you only re-render markup that actually
109
- depends on that slice.
110
-
111
- ```ts
112
- // good — only re-projects when pagination changes
113
- const table = createTable(options, (state) => ({
114
- pagination: state.pagination,
115
- }))
116
-
117
- // even better — only what your UI actually reads
118
- const table = createTable(options, (state) => ({
119
- pageIndex: state.pagination.pageIndex,
120
- pageSize: state.pagination.pageSize,
121
- }))
122
- ```
123
-
124
- If different parts of the UI need different slices, **don't** widen the selector — use
125
- `subscribeTable` instead (next section).
126
-
127
- ## 4. Reach for `subscribeTable` for fine-grained reactivity
128
-
129
- `subscribeTable(source, selector?)` is the per-block subscription. It returns an object whose
130
- `.current` re-runs only when the selected value changes (shallow compared).
131
-
132
- ```svelte
133
- <script lang="ts">
134
- import { subscribeTable } from '@tanstack/svelte-table'
135
-
136
- // dedicated subscription for the pager
137
- const pagination = subscribeTable(table.atoms.pagination)
138
-
139
- // dedicated subscription for a single row's selection state
140
- const isSelected = subscribeTable(
141
- table.atoms.rowSelection,
142
- (rs) => !!rs[row.id],
143
- )
144
- </script>
145
-
146
- <input type="checkbox" checked={isSelected.current} />
147
- ```
148
-
149
- Use it inside per-row components — the row block re-renders only on its own selection toggle,
150
- not on every row's toggle.
151
-
152
- ## 5. Non-reactive reads where you don't need reactivity
153
-
154
- Inside event handlers, derived calculations, or one-shot logic, read atoms directly. Cheaper
155
- than subscribing.
156
-
157
- ```ts
158
- function exportSelected() {
159
- const selection = table.atoms.rowSelection.get()
160
- const selectedIds = Object.keys(selection).filter((id) => selection[id])
161
- // ...
162
- }
163
- ```
164
-
165
- `table.state` is the same idea for a full snapshot.
166
-
167
- ## 6. Key every `{#each}` block on a stable id
168
-
169
- Svelte without keys recreates nodes on reorder. Result: lost input focus, lost scroll, lost
170
- component state. Every TanStack Table loop has a stable id.
171
-
172
- ```svelte
173
- {#each table.getHeaderGroups() as headerGroup (headerGroup.id)}
174
- <tr>
175
- {#each headerGroup.headers as header (header.id)}
176
- <th>...</th>
177
- {/each}
178
- </tr>
179
- {/each}
180
-
181
- {#each table.getRowModel().rows as row (row.id)}
182
- <tr>
183
- {#each row.getVisibleCells() as cell (cell.id)}
184
- <td>...</td>
185
- {/each}
186
- </tr>
187
- {/each}
188
- ```
189
-
190
- ## 7. Don't fight `$effect.pre`
191
-
192
- `createTable` is already syncing options in `$effect.pre`. Don't write a second `$effect`
193
- that calls `table.setOptions` — it'll race with the built-in sync and may render with stale
194
- state.
195
-
196
- If you need to react to an option change with a side effect, put the side effect in your own
197
- `$effect`, not the option write.
198
-
199
- ## 8. Debounce high-frequency writes
200
-
201
- Two places will hammer table state at keystroke / pointermove rate:
202
-
203
- - **Filter inputs.** Wrap `setFilterValue` calls with a debounced callback.
204
- - **Column resizing.** v9 commits `columnSizing` continuously by default; use the resize-end
205
- commit mode or debounce.
206
-
207
- ```ts
208
- import { createDebouncer } from '@tanstack/svelte-pacer/debouncer'
209
-
210
- const debouncedSetFilter = createDebouncer(
211
- (value: string) => column.setFilterValue(value),
212
- { wait: 200 },
213
- )
214
- ```
215
-
216
- See the `compose-with-tanstack-pacer` skill for full examples.
217
-
218
- ## 9. Virtualization for large datasets
219
-
220
- `getRowModel().rows.length > ~1000` and rows are simple? Performance is fine without
221
- virtualization. Above that, or with heavy per-row markup, use `@tanstack/svelte-virtual`. See
222
- the `compose-with-tanstack-virtual` skill.
223
-
224
- ## 10. Don't ship debug flags
225
-
226
- `debugTable: true`, `debugRows`, `debugHeaders` all log. Strip them or gate on `import.meta.env.DEV`.
227
-
228
- ## 11. Don't reimplement built-ins
229
-
230
- The #1 production-readiness regression we see in audits: somebody hand-rolled the thing the
231
- table already does. If you're writing any of these, register the feature instead.
232
-
233
- - Hand-rolled sort comparator across rows → `rowSortingFeature` + `createSortedRowModel`
234
- - Hand-rolled page math (`rows.slice(start, end)`) → `rowPaginationFeature` +
235
- `createPaginatedRowModel`
236
- - Hand-rolled selection toggle (`selected[row.id] = !selected[row.id]`) → `rowSelectionFeature`
237
- - Hand-rolled column hide map → `columnVisibilityFeature`
238
- - Hand-rolled column resizer → `columnResizingFeature`
239
- - Hand-rolled debounced filter that doesn't update through `setFilterValue` →
240
- `columnFilteringFeature` + pacer
241
-
242
- Each rewrite breaks tree-shaking, breaks the reset APIs, and breaks devtools introspection.
243
-
244
- ## Quick smoke test before shipping
245
-
246
- - Bundle: does the table chunk match the features you registered? (`pnpm build` and inspect.)
247
- - DevTools profiler: clicking sort triggers exactly one re-render of the headers and rows,
248
- not every consumer of `table.state`.
249
- - Resize / filter: no jank, no per-keystroke server hits (pacer / debounce).
250
- - Reload: state restored from your atom / URL / storage, no flicker.
251
- - Stress: 100k-row dataset with virtualization stays interactive.
252
-
253
- ## Related skills
254
-
255
- - `tanstack-table/svelte/table-state` — selectors, atoms, subscribeTable.
256
- - `tanstack-table/svelte/compose-with-tanstack-pacer` — debounce patterns.
257
- - `tanstack-table/svelte/compose-with-tanstack-virtual` — virtualization.
258
- - `tanstack-table/svelte/compose-with-tanstack-store` — atom ownership patterns.