optimizer: attach required sub-QRLs to QRL #326
wmertens
started this conversation in
Proposals For Qwik
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
What is it about?
avoiding throwing during execution
What's the motivation for this proposal?
If you have code like
then we generated the component QRL and the task QRL. Each has an import function like
const cmp123 = () => import('./q-123.js')When we run the component the first time, we first resolve its QRL, which will import the module. Then we run it.
When encountering the task QRL, it creates a QRL that it needs to resolve, and that will throw a Promise. If you have multiple tasks, you will throw once for every task, the first time it is used in the client.
But we know that 100% of the time, task QRLs will be needed to run the component QRL, so we could instead resolved all the needed QRLs modules ahead of time.
Proposed Solution / Feature
What do you propose?
The optimizer should supply a list of required QRL modules to a generated
qrl()call. Then resolving the qrl should wait until they are all imported before resolving.Note that this is only about code that is definitely needed. A qrl like
const handler = $(...)is not required to run the component code. So the optimizer should use heuristics like "it has to be nameduse[A-Z]\w+\$"Code examples
The resulting code could be something like
The registry would be a global map of imports that retains resolved modules, so they only need to be async imported once. The import statements are still necessary for vite to know the import graph, but maybe we can use the renderDynamicImportHook hook so only the path is needed and the imports are done by the registry.
Links / References
No response
Beta Was this translation helpful? Give feedback.
All reactions