Skip to content

Conversation

Hebilicious
Copy link

@Hebilicious Hebilicious commented Oct 2, 2025

This is a draft PR that attempts to move away from component life-cycle hooks in composables to effect scopes .

All tests are passing, with one caveat :

Now nextTick needs to be used when passing a callback to useActorRef that access state that is not initialized.

  const actor = useActorRef(machine, {}, (nextState) => {
    nextTick(() => {
      state.value = nextState.value;
    });
  });
  const state = ref(actor.getSnapshot().value);

I feel like this is fine because this is kind of an odd pattern anyways.
Using onMounted is more idiomatic to vue imo, and maybe we should change the test to :

const state = ref() //shallowRef would work too
const actor = useActorRef(machine, {}, (nextState) => {
    state.value = nextState.value;
});
onMounted(() => { state.value = actor.getSnapshot().value });

(Users should not be using useActorRef directly in most cases anyways, so its fine if the test doesn't use shallowRef)

@changeset-bot
Copy link

changeset-bot bot commented Oct 2, 2025

⚠️ No Changeset found

Latest commit: 6d6c6ba

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

@Hebilicious
Copy link
Author

@Andarist I've been testing this in production, it appears to be an improvement. Would you mind taking a look please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant