#Migrating to XState5...

1 messages · Page 1 of 1 (latest)

mighty snow
#

I'm getting this error after migrating to XState5:

useActor is not a function or its return value is not iterable.

How do I fix that?

jolly epoch
#

Strange, can you share a CodeSandbox reproduction?

visual iris
#

spawnBehavior is removed from xstate5?

jolly epoch
proven merlin
# mighty snow https://stackblitz.com/edit/github-dmggxz?file=package.json

Hello, I've taken a quick look at the project. There is no more useActor() on the MixerMachineContext object (was removed in beta 4), but instead you have useActorRef() now, which returns the actor reference directly.

const mixerActor = MixerMachineContext.useActorRef();
mixerActor.subscribe(...);
mixerActor.send({ type: '...' });
mixerActor.getSnapshot();
// ...

And if you wish, the context object also gives you direct access to useSelector().

const volume = MixerMachineContext.useSelector(state => state.context.volume);
mighty snow
# proven merlin Hello, I've taken a quick look at the project. There is no more `useActor()` on ...

Thank you, but I'm back to v4 for now. I'm having performance problems. Any clue how to get the track fx panels to work on this? Right now they snap back into place because I'm using useSelector but if I don't there's performance issues. https://stackblitz.com/edit/github-h2gbyx?file=package.json

Run Xstate Mixer created by Stevebarakat on StackBlitz

proven merlin
#

There's a lot going on here, but just focusing on the issue at hand, you were assigning mutated data when updating the new position inside saveTrackPanelPosition, so the selector is not seeing the change due to the shallow compare. I've quickly modified the assign here for assign({ trackPanelData: {...tempTrackPanelData} }) and I can see the drag position updating afterwards.

mighty snow
proven merlin
#

I haven't forked anything, just tried directly on your shared project, mostly at the bottom of the mixerMachine file.

But like I said, there's a lot going on here. As soon as I start dragging the dialog around, the song that plays comes to a crawl and eventually stops playing, but this is a first step in getting things right. Just need to find what are causing the performance drops. One example is the ChannelStrip component, which listens to the whole trackPanelData, so any update to it will rerender everything below. I'd like to take a deeper look if I can find time, but this project definitely looks promising.

mighty snow
mighty snow
jolly epoch
mighty snow
jolly epoch
#

Gotcha (just saw the other comment), looking

mighty snow
#

I refactored it to address what @proven merlin was talking about. I think...

#

not sure which is better. probably this one.

jolly epoch
#

Okay, I'll look at this one

#

Without looking, chances are if you're managing drag position in that same state machine, that's the likely culprit

#

This goes for any state management - there's too many updates happening too frequently to one store

#

When in reality, it's local to that component (until you're done dragging)

mighty snow
mighty snow
jolly epoch
#

You can use a local useMachine too

#

That won't affect the context, the dragging will only be isolated to that component

#

Which should improve performance

mighty snow
#

🤔

#

Okay. I'll try that.

jolly epoch
#

Let me know how it goes. You're working on a really ambitious example; no doubt you'll be an XState expert by the end of this haha

mighty snow
jolly epoch
#

Can you point me to the code that is doing the dragging logic?

mighty snow
mighty snow
#

...but the track fx panels aren't.

#

able to.

#

...that one crashes when the settings are changed. I just realized.

#

Nevermind. It's not important. I'm doing the local state thing now.

jolly epoch
#

Okay, let me know if that improves things

mighty snow
# jolly epoch Okay, let me know if that improves things

I started by just using useState to localize that data and there's still performance issues. I think they're related to the fx settings using context.
https://stackblitz.com/edit/github-ffbgbb?file=src%2Fcomponents%2FChannelStrip.tsx
Wouldn't it just be better if I hadn't used createActorContext from the start and just used props like @tulip cradle mentioned #1104805753686069391 message.

Run Xstate Mixer Ts created by Stevebarakat on StackBlitz

Discord

Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.

jolly epoch
#

Can you pinpoint which properties are updating frequently and causing the perf issues?

mighty snow
#

Good question... I think so.

#

lol... I'm assuming you want me to tell you what they are.

#

...ummm. I guess any of the track panel settings (ie: position, size, active) and track fx settings (ie: reverbDecay, delayMix, etc...).

jolly epoch
#

So I'd make sure that when you're dragging, those track panel settings aren't being set

#

You can "temporarily" set them in the component (useState or whatever) and then when you're done, send an event saying "here is the final position it should be at"

mighty snow
jolly epoch
#

Yes of course

mighty snow
#

Okay. I have to learn how to do that. I have to start all over though...