-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify/clarify client loading for all templates #442
Comments
To clarify, the |
I'm not convinced yet that this is overall more elegant. Many components typically need to keep track of a loading state anyway, for example to make a zome call to fetch all posts to display. So we might not really be able to get rid of having loading states in the components with this change. And if the error occurs anyway due to a component being accidentally or due to lack of understanding placed outside an |
Maybe what I'd say is that it's reasonable to do it that way in Vue but I think it's probably not worth reverting the changes in the Svelte template if there often is async stuff to be done in the onMount hook of components anyway. |
Child components do have their own loading state for loading the component's data via zome call, that's true. And they don't really have to handle an extra on-loading state as the client is being connected, and the changes are pretty small for a decent benefit to the hApp dev, I suppose. (NB looks like #425 merely moved the |
This is true, although there are two loading states in this case, one for fetching data as you described and the other for setting up the initial websocket connection, I think the child components would need to be able to get some sort of |
I'm not sure I'm understanding the question here, but my approach is always to make sure the holochain client is connected before rendering any app content. While awaiting connection to the holochain client I display a general loading screen. To me this is simple and ideal because it avoids pushing down the logic for checking if the client is connected into all the components, and only does it in one place. The components always have a connected client and the dev doesn't ever have to think about it. |
@mattyg yes, that's what I'm advocating -- don't put too much responsibility on child components, let it break if you mount them in the wrong spot, and give hApp devs some guideposts to help them understand this behaviour. Should be graspable cuz it's not that different from establishing any WebSocket connection -- you want to await the promise before you do anything that requires the conn. |
Exactly, I would prefer to keep it simple like that and have that guard/ check much higher up the tree. The approach that was implemented with #425 while it still works, still doesn't guarantee safety, especially when the call to |
In #424 we described the discovery that Svelte templates will fail with an error message when you load a component before the HC client is loaded. #425 fixed it by adding an async
getClient
function and having the children await on that function.In #436 I said the race condition is also present in Vue templates. @c12i suggested I just put the child components inside the root component's "if loading" guard, which seems to me to be a much more elegant solution than making the children responsible for awaiting client state.
If others (cc @c12i @matthme @mattyg ) think this is a better way to go, then we need two follow-up tasks:
The text was updated successfully, but these errors were encountered: