Skip to content

Commit

Permalink
Don't directly reference local state
Browse files Browse the repository at this point in the history
In svelte 5, $state referenced locally is not reactive, because of how evaluation occurs.

Svelte will warn about this at runtime (and does so here)
To make it reactive locally, the docs recommend using a closure, which is what we do here.
  • Loading branch information
dberlin authored Mar 2, 2025
1 parent b5339c5 commit 60d5c51
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/svelte-table/src/createTable.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ export function createTable<
let state = $state<Partial<TableState<TFeatures>>>(
getInitialTableState(_features, tableOptions.initialState),
)

const getState = () => state

const statefulOptions: TableOptions<TFeatures, TData> = mergeObjects(
tableOptions,
{
_features,
state: { ...state, ...tableOptions.state },
state: { ...getState(), ...tableOptions.state },
mergeOptions: (
defaultOptions: TableOptions<TFeatures, TData>,
newOptions: Partial<TableOptions<TFeatures, TData>>,
Expand Down

0 comments on commit 60d5c51

Please sign in to comment.