dioxus
dioxus copied to clipboard
[dioxus_web] panic_hook feature is hard to disable
Specific Demand
When using dioxus
with the web feature, the crate pulls in dioxus_web
with its default features enabled, one of which is panic_hook
. Given the way cargo is setup, once a feature is enabled by any dependency (even transitive ones) it is enabled for all users of that crate. This makes it hard for consumers of the dioxus
crate to use their own panic handler other than initializing it after running dioxus::web::launch
as to overwrite the handler added by dioxus.
Implement Suggestion
It may be a better idea to not install a panic handler at all and instead in the documentation show that one should be setup by the consumer if they want to get panic messages. The way it is currently setup also locks users into the console_error_panic_hook
panic handler. Although this handler is quite good for almost all uses, it is better for the user to have a choice and pull in any panic hook they choose.
Perhaps we could keep our current strategy with configuration and an opt-out via configuration in the launch cfg?
It does allow for dioxus to setup the wasm runtime for users and let them just focus on their code while allowing more technical users to override the defaults.
But this seems like a very round about way of doing it. Adding the panic handler is normally the first thing one would run in their main, but with dioxus, it basically becomes the last. My code has me installing a logger before running dioxus, and I want a panic handler to be installed before I do it which leads to manually installing my panic handler before all the code and after running dioxus.
We are going to fix this in #387 by changing how features are applied on top of eachother.