-
Notifications
You must be signed in to change notification settings - Fork 3
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
Programmatic registration is not working #5
Comments
We unfortunately can't enable dynamic registration because then we don't have a "top" module which serves as the basis for module graph traversal. I've been pretty vocal in nodejs loader discussions that |
Yes, I noticed it before: Lines 3 to 6 in 3f1aa25
Yes, it feels a bit weird using it. Most related comment: Currently I only have a bad workaround for this which is to register it both ways but that of course leads to a minor issue and memory leaks. |
What do you roughly mean by that in that case we don't have a "top" module? |
The hot update algorithm starts here: Line 444 in 3f1aa25
We just start from "top" or "main" and traverse the entire dependency graph to dispatch a hot update. In the case of dynamic register then there is no "main". If there is no main then we would need to start the traversal from the module which was updated and work our way down. In theory it would be faster because you could run into an |
To my understanding registered custom loaders should apply to subsequent dynamic imports in the module where the custom loaders are registered (https://nodejs.org/api/module.html#enabling). |
It is not a problem with the loader chain, it is the dynohot runtime. As I mentioned before the "loader" side of things is actually very simple. It's a stateless code transformation. If we allow dynamic registration of the dynohot loader runtime then the application no longer forms a neat graph. The commit message of 0586bc4 has some more information there. It becomes, I believe, impossible to detect module update deadlocks in this case. I think we can probably make it work by making an invisible "top" module and starting the graph from there but I don't know if the complexity is worth it for this curiosity. I'm of the opinion that loaders should be declared statically and not dynamically due to the way they affect the module graph. |
Ah, I see. I think I understand some of it now. So could we separate the dynohot loader and the dynohot runtime? So then we could register the dynohot loader (programmatically as well) and start the runtime (also programmatically (and manually (not as part of the loader))) separately. |
Some time ago I consulted with bloop (asked it couple of questions) on dynohot and I started to understand the problem a bit more. So I can see that it is hard to solve it nicely. I think full dynamic registration support would mean that the main module would not be hot reloadable (which is okay in my use case). Now as a better workaround I am using a separately imported module to register the loaders |
Moving all your loaders to a separate --import is a good solution, I hadn't thought of that. |
index.js
main.js
or
command line registration works as expected:
or
The text was updated successfully, but these errors were encountered: