Skip to content

data-on-signal-patch when debounced receives the wrong list of changes #1122

@jpeg729

Description

@jpeg729

Bug Report

The example

I was trying to create a page with auto-save and an indicator.

Signals

{
    data: { /* stuff to save */ },
    version: 0, // updated by the frontend on every change
    savedVersion: 0, // updated by the backend confirming the version saved.
}

auto-save

<div data-on-signal-patch__debounce.500ms="@post(..)"
      data-on-signal-patch-filter="{include: /^data/}"
></div>

indicator

<div data-on-signal-patch="$version++"
    data-on-signal-patch-filter="{include: /^data/}"
    data-text="($version === $savedVersion) ? 'saved' : 'saving'"
></div>

What happens

  1. User clicks on something, { data: .. } is updated
  2. The non-debounced on-signal-patch runs immediately and receives changes { data: .. }. It sets { version: 1 }
  3. The debounced on-signal-patch runs after its delay, but receives changes { version: 1 } and the filter is applied, so the value isn't evaluated.

What I expected

I expected the debounced on-signal-patch to react to { data: .. } but that is not what it received.
I also notice that evt is undefined when the value is run, which is not entirely unexpected.

Datastar Version

v1.0.0-RC.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions