Skip to content

dexie-svelte-query doesn't update like liveQuery #2231

@dfahlander

Description

@dfahlander

I've been using dexie-svelte-query in a Svelte 5 project and in most cases it seemed to work like a charm, but then I stumbled on a situation where it doesn't seem to monitor the underlying data correctly.

I'm rendering an array of attachments based on a live query. The first sample below does not update correctly while the other one (plain liveQuery with $ vars, updates correctly):

Not updating correctly:

  const localDraftQuery = stateQuery(
    () =>
      db.localDrafts.where("conversationId").equals(conversationId).first(),
    () => [conversationId]
  );
  const localDraft = $derived(() => localDraftQuery?.current);
  const attachments = $derived(localDraft()?.attachments ?? []);

Updating Correctly!:

  const localDraft = $derived(liveQuery(() => db.localDrafts.where("conversationId").equals(conversationId).first()));
  const attachments = $derived($localDraft?.attachements ?? []);

Unfortunatetely, I have no complete repro right now to share.

Related PR: #2116
Source of the svelte-query library: /libs/dexie-svelte-query/src/lib/stateQuery.svelte.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions