xstate icon indicating copy to clipboard operation
xstate copied to clipboard

fix(vue): triggerRef in the update selected function

Open Hebilicious opened this issue 1 year ago • 4 comments

fix #5091

I'm 100% sure this is not the best way to do this, but this works on my end ... So I will need to investigate this further. Will let this open as a draft for now.

Hebilicious avatar Sep 25 '24 08:09 Hebilicious

⚠️ No Changeset found

Latest commit: e7e5e44c3758eec4c1380bd604539406ad71115a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Sep 25 '24 08:09 changeset-bot[bot]

Please add a test case verifying the fixed behavior.

Andarist avatar Sep 25 '24 08:09 Andarist

Please add a test case verifying the fixed behavior.

Hi @Andarist

Due to the tests failing, I went ahead and investigated in depth, and found out that the issue wasn't related to xstate, but to the way vue works with Map objects (realised that the issue was happening with Map only). So as far as I know this is not related to xstate. And doing something like useSelector(myRef, s => [...s.context.myMap.values()]) would properly update. I will investigate more on the vue side and try to reproduce the issue without xstate.

On another note, I did some performance adjustements: I've noticed that useSelector is called in useActor, which is not necessary. Additionally it might be better to suggest using vue native computed to derive state, as it will not create an extra watcher and simply automatically update given that snapshot from useActor is a vue ref. Assuming a nested list scenario, useSelector could create a lot of watchers which is not necessary if the user just want to read the context (assuming this is the primary use of useSelector).

Should I update this PR with the performance adjustement and some suggested doc updates ?

Hebilicious avatar Sep 25 '24 13:09 Hebilicious

I'd prefer new dedicated PRs instead of repurposing this one

Andarist avatar Sep 25 '24 13:09 Andarist

for reference https://github.com/statelyai/xstate/pull/5382

Hebilicious avatar Oct 02 '25 14:10 Hebilicious