Skip to content

add a way to force update a state variable #14520

Open
@olivierchatry

Description

@olivierchatry

Describe the problem

I'm using a custom made data store with realtime update. In svelte 4, when the value got updated, I was just doing value = value to refresh different bindings. In svelte 5 it is not possible anymore as before updating bindings, the system check if the value is the same. What more is, inside some of the object, we have our classes that are filled automatically ( think relationships ) and so it seems like svelte is not detecting the change in values.

I'm not sure if I'm clear in what I'm explaining, but basically, I would need something to inform the system to update bindings forcefully.

To be a bit more precise:

The system we have in my company needs to be used without svelte, so we have our own data system. We have so call "Resource" and "ResourceCollection" ( that are basically relationships ). The system handle realtime update accross client using web sockets. To get "informed" of these change we subscribe to the resource. The only way I found to make the refresh working is by doing that ( subscribeAndDo is internal to our system ) :

  let unsub
  $effect(() => {
    unsub?.unsubscribe?.()
    unsub = account.subscribeAndDo(onDestroy, () => {
      const newAccount = account
      account = null
      account = newAccount
    })
  })

Describe the proposed solution

The goal here is, whenever the props "account" change, we subscribe to it. Then whever something change in "account" the callback will be called. Here, I'm using the "trick" to make sure that svelte update the bindings. It would be great if we can have a $forceUpdate(account) instead. if that make any sense.

Importance

would make my life easier

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions