Skip to content

No reactivity after deleting a key from an object-shaped signal #1145

@yurivish

Description

@yurivish

Bug Report

Pen

Click the button once to toggle on, click again to toggle off; notice the lack of a reactive update to the second click.

It looks like setting a signal-object entry to null removes the key, but does not invalidate bindings that depend on key membership.

This means that things like like 'key' in $selection and Object.keys($selection) stay stale until an unrelated reactive change.

Possible cause is: at signals.ts:616 in the newValue == null branch, Datastar deletes deepObj[prop] but does not bump the key-tracking signal and does not dispatch(path, null):

if (newValue == null) {
delete deepObj[prop]
// if newValue is a computed set the computed directly instead of wrapping in signal
} else if (hasOwn(newValue, computedSymbol)) {

Possible fix is:

  if (newValue == null) {
    delete deepObj[prop]
    dispatch(path, null)
    keys(keys() + 1)
  }

Datastar Version

RC8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions