Replies: 3 comments 3 replies
-
I converted this to a conversation, hope you don't mind! |
Beta Was this translation helpful? Give feedback.
-
Thank you for the proposition. A couple of things that comes to mind following my first read...
While you are totally right that pooling is bad for performance, I am not sure that it matters for this case as the polling happens for a very short (and kind of predictable) period. Suggested changesThere are a few things to I could add regarding this section but maybe that would be better if you review the suggested changes first:
Support Suspense
I am not sure why developers would want to do that. Both cannot happen at the same time. A page cannot be loaded until all the modules are registered as there's currently no mechanism to know the requested page is included in which module. While I agree that we could work on a more sophisticated mechanism to support eager rendering of a page, I don't think this is something worth working on at the moment. Such a mecanism would encounter a few bumps:
Let me know if I am missing something, maybe I didn't understand correctly what you meant here. I would also like to understand how Suspense would integrated with the A unique loader (fallback) should be rendered until:
|
Beta Was this translation helpful? Give feedback.
-
Polling
I indeed mixed up the two. 😅 The suggested change can apply to both
I omitted local modules for brievity. We can most likely apply the same changes as for the remote modules.
I haven't used it yet, but from my understanding, my suggested changes can also apply to it. SuspenseI'm not interested in using I'm only interested in using I haven't used What happens if the registration is completed before a React component has time to declare It's late so I'm posting this as is. If I haven't everything from your previous comment, feel free to re-ask. Sorry about that. 🙇 |
Beta Was this translation helpful? Give feedback.
-
I believe there are a few ways to improve the usability of the
useAreModulesReady()
hook.Replacing polling with an observer
Currently, the
useAreModulesReady
hook usessetInterval
to know when module registration is done. The default timeout is 100ms.Polling is bad for performance for multiple reasons. Setting the interval too low will make the device waste compute time. Setting the interval too high will hurt the time it takes for the app to load.
Using polling is completely unecessary. We can use the Observer pattern to get rid of polling.
Suggested changes
LocalModuleRegistry
We can add a
addRemoteModulesReadyListener(callback: () => void): void
function to the module. This function should fire all registed callback methods when the registration status of remote modules is set to"ready"
.We should also add a function
removeRemoteModulesReadyListener(callback: () => void): void
to unregister the callback. This can be useful if the React component listening to the event gets unmounted.useAreModulesReady()
This hook should use the
useSyncExternalStore
hook.Support Suspense
Supporting Suspense will allow developers use the same Suspense fallback for both loading modules and waiting for their pages to load. This is critical when the loading component is animated (i.e. a loading spinner) to avoid a jitter when the remote modules are loaded, but the individual pages still need to load.
Suggested changes
I suggest the creation of a new hook
useSuspenseAreModulesReady
that causes a component to suspend until the modules are loaded.Using useAreModulesReady
Using Firefly's AppRouter
Passing a fallbackElement to Firefly's AppRouter
We can force the existance of a fallback element by requiring a prop.
Internally, we should still use the same
<Suspense>
boundary for both Squide loading the remote modules and React Router loading the routes, otherwise we'll end up with the jitter.That's all I can think of right now. There's a lot of Squide internals that is still unknown to me, so let me know if this feasable or not.
These are very nitpicky suggestions, but I still wanted to document them.
Thank you for your time 🙇
Beta Was this translation helpful? Give feedback.
All reactions