tivac/xstate-component-tree

The Meta field is stomped when using the component helper

Morklympious opened this issue · 1 comments

Hello!

In doing some interesting edge-casery, the meta tag in the component helper is actually stomping on meta data that might already exist on a statenode, the offending line is essentially right here

you can see that there's a raw assignment to node.meta = meta, which causes anything that might previously already exist on that statenode's metadata to be lost.

This is just an issue that was in the back of my mind that I might put a CR up for, but essentially it's as simple as us running an Object.assign for the existing meta with the new metadata that is the loading component..

I'm unsure if we want this to be compatible with other load calls in the statenode meta (if people need to do other asynchronous work), but if we do, we should also augment the load function to include the already existing node.meta.load if there is one.

tivac commented

Looks like the helper would let you pass meta fields as part of the first arg (if it's an object), not the second. Anything that isn't component or props on that first arg will get turned into the meta object being assigned to. I don't think that is particularly clear, but it's how the code is set up to work atm.

I'm fine with it stomping meta.load, but it could certainly output a console.warn or even throw an error if meta.load is already defined.