xstate-tools icon indicating copy to clipboard operation
xstate-tools copied to clipboard

Bug: Display difficulties when splitting machine into multible files

Open ohjah opened this issue 1 year ago • 5 comments

XState version

XState version 5

Description

i have a very complex global state machine. to make it more readable and editable i want to split the code into multible files, import the independet parts and init the machine. when i have all parts in one big file it works fine and the xstate extension can easyly show me what my statechart looks like but when i put the parts in different files and import them it just shows me an empty box.

ps: i dont want to invoke or spwan actors to split the machine. i already tried this and because context between actors is isolated this does not work for me.

ps: im using xstate with react

basic example:

export const authenticationStates = {
	initial: 'unauthenticated',
	states: {
		unauthenticated: {
			on: { REGISTER_USER: 'authenticated' }
		},
		authenticated: {
			on: { LOGOUT_USER: 'unauthenticated' }
		}
	}
};
setup({
	types: {
		events: {} as authEvents,
		context: {} as {
			auth: authenticationContextType;
		}
	}
}).createMachine({
	id: 'global',
	type: 'parallel',
	context: { auth: authenticationContext },
	states: {
		auth: authenticationStates
	}
});

Expected result

image

Actual result

image

Reproduction

i dont think that is nessesary in this case. if needed i submit later

Additional context

i cannot tell yet but i think it still works but the xstate extenstion defently has problems to display the statechart

ohjah avatar Nov 12 '24 17:11 ohjah

The VSCode extension does not currently support state machines spread out in multiple files.

davidkpiano avatar Nov 19 '24 12:11 davidkpiano

ok i can now surely say that the state machine is still working. its just not displayed by xstate tooling

ohjah avatar Nov 28 '24 09:11 ohjah

Is there a plan to add it anytime?

vamsi-lz avatar Dec 13 '24 01:12 vamsi-lz

Is there a plan to add it anytime?

Not with the current tooling, which works via static analysis of the AST, and it gets much more complicated if the machine definition is spread out in multiple files.

The recommended way moving forward is to use Stately Inspect to visualize machines in real-time without having to parse the AST. Much more future-proof and avoids the issue of having to predict the many, many different ways machines can be authored (partial definitions, across files, dynamic keys, etc. etc.)

davidkpiano avatar Dec 17 '24 08:12 davidkpiano

i tryed to use inspect but because i use react native i got this problem

https://github.com/partykit/partykit/issues/516

ohjah avatar Dec 18 '24 10:12 ohjah