-
-
Notifications
You must be signed in to change notification settings - Fork 774
enh: hygienize usages of re-exports #4069
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
base: main
Are you sure you want to change the base?
Conversation
This is also a breaking change to existing user code that uses the re-exports, so that is an important trade-off to consider in removing the re-exports, rather than making a decision about what would be ideal if we were starting from scratch. |
So it's a breaking change, I'm OK with it. |
Maybe you could expand on the reasoning in favor of the change, then? I don't understand either of the problems you describe. Specifically:
Of the 5 you list here (
I'm not sure I understand the confusion. In the example you give, you remove the line If I were creating the library again in a vacuum, would it be worth |
That is a matter of opinion, it's the whole point of this PR. If the framework wants to bundle in their public API
Yes, the web is plenty of cases where wasm-bindgen has been pinned to a specific version in Cargo.toml files to solve a problem because the bidgen format is unstable and all releases are like major version changes. See https://stackoverflow.com/questions/76452749/leptos-with-axum-issue-with-wasm-bindgen-versions If wasm-bindgen is used in an application from leptos and as direct dependency when leptos is pinning it to I don't really care so much. These dependencies are not there because is easier to import from leptos itself than installing them properly. Are there because were needed to be added for generating proc-macro code in an unhygienic way. If you're fine with keeping them reexported in that way, I'm OK, and will write a lint to forbid leptos reexports because I don't want to deal with these maintainment nightmares. I was going to write the lint at first, just opened this in case it could be solved in a better way. Feel free to close. |
For the people interested on this, I've written a lint to forbid usages of these re-exports from leptos. See |
The crate
leptos
re-exports several dependencies to use them in the#[component]
macro:wasm_bindgen
web_sys
- There is a direct usage of it in an example.tracing
serde
serde_json
This is problematic because it could hide the definition of direct dependencies of a project in Leptos, which can cause hard to debug issues with version mismatches of duplicated dependencies and duplication of dependencies itself. Additionally, it confuses to developer consumers of Leptos about if they must use, for some reason, the dependencies from this path.
Leptos has an example with this problem going unnoticed that serves to understand the problem.
use leptos::wasm_bindgen::JsCast;
inexamples/directives/src/lib.rs
.trunk serve
in theexamples/directives
directory.Rustc will show an error like this:
Note that the error message suggests to import
JsCast
fromleptos::wasm_bindgen
, which is not a good suggestion for the reasons explained above.The solution included in this PR is to hide re-exports of
leptos
in a__reexports
internal public module. This is the solution suggested in rust-lang/rust#63687 (comment) for hygienic usage of libraries in proc-macro generated code.You can see linked PRs in the issue of the linked comment examples of the same solution in other libraries. Are called different to
__reexports
, sometimes__export
(liballoc),__macro_support
... but it is consistent that rustc will not suggest to import from a module starting with__
.