-
-
Notifications
You must be signed in to change notification settings - Fork 695
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
Get error about missing "tracing" dependency when trying to use #[component] macro #2156
Comments
I'm sorry, I can't reproduce the issue by starting with one of our starters and removing the (And just checking: When you say "see red squiggle," is this just in rust-analyzer or are you getting an error while building, and what is the error?) |
The red squiggle is rust-analyzer. I will get up a repro. I didn't use a starter. |
Ran cargo build, got same error there as well:
|
Upgraded to rust 1.75, build still fails on missing tracing. |
Okay, apparently the issue is with leptos-axum. Adding it triggers the issue |
Cargo.toml:
main.rs:
|
Hmm, leptos-axum has a hard dependency on tracing, so I don't know if this something that can be fixed in the features system of cargo? Looking at the Cargo of leptos_axum,
|
Hmm, still can't see how this is enabling the tracing feature on leptos itself? |
Thanks. It's specific to the MRE:
use leptos::{component, IntoView};
#[component]
fn SignupForm() -> impl IntoView {}
[package]
name = "las"
version = "0.1.0"
edition = "2021"
[dependencies]
leptos = "0.5.4"
leptos_axum = "0.5.4"
|
Oh okay yeah it's this: leptos/leptos_macro/src/component.rs Lines 191 to 194 in 16cf3c4
Using the Gating this on the Leptos (In the meantime |
Ahhh in lib.rs ( but also in many other files)
If while the error is shown as originating on the component macro, the actual issue is with the view!() macro. When this macro is expanded in my code, it injects a direct dependency on tracing in the scope of my code, not Fix is to have ssr feature also turn on tracing, or rework the cfg_attribute. Have not tested. ymmv
Though perhaps all usages of cfg_attr referencing ssr should be fixed up? |
Here is the expanded main.rs Note that the file now has dependencies on tracing. #![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
use leptos::{component, view, IntoView};
/// Props for the [`SignupForm`] component.
///
///
#[builder(crate_module_path = ::leptos::typed_builder)]
struct SignupFormProps {}
#[automatically_derived]
impl SignupFormProps {
/**
Create a builder for building `SignupFormProps`.
On the builder, call to set the values of the fields.
Finally, call `.build()` to create the instance of `SignupFormProps`.
*/
#[allow(dead_code, clippy::default_trait_access)]
fn builder() -> SignupFormPropsBuilder<()> {
SignupFormPropsBuilder {
fields: (),
phantom: ::core::default::Default::default(),
}
}
}
#[must_use]
#[doc(hidden)]
#[allow(dead_code, non_camel_case_types, non_snake_case)]
struct SignupFormPropsBuilder<TypedBuilderFields = ()> {
fields: TypedBuilderFields,
phantom: ::core::marker::PhantomData<()>,
}
#[automatically_derived]
impl<TypedBuilderFields> Clone for SignupFormPropsBuilder<TypedBuilderFields>
where
TypedBuilderFields: Clone,
{
#[allow(clippy::default_trait_access)]
fn clone(&self) -> Self {
Self {
fields: self.fields.clone(),
phantom: ::core::default::Default::default(),
}
}
}
#[allow(dead_code, non_camel_case_types, missing_docs)]
#[automatically_derived]
impl SignupFormPropsBuilder<()> {
#[allow(clippy::default_trait_access, clippy::used_underscore_binding)]
pub fn build(self) -> SignupFormProps {
let () = self.fields;
#[allow(deprecated)] SignupFormProps {}.into()
}
}
#[allow(missing_docs)]
impl ::leptos::Props for SignupFormProps {
type Builder = SignupFormPropsBuilder;
fn builder() -> Self::Builder {
SignupFormProps::builder()
}
}
impl ::leptos::DynAttrs for SignupFormProps {
fn dyn_attrs(mut self, v: Vec<(&'static str, ::leptos::Attribute)>) -> Self {
self
}
}
impl ::leptos::IntoView for SignupFormProps {
fn into_view(self) -> ::leptos::View {
SignupForm().into_view()
}
}
///
#[allow(non_snake_case, clippy::too_many_arguments)]
#[allow(clippy::needless_lifetimes)]
#[allow(clippy::let_with_type_underscore)]
fn SignupForm() -> impl IntoView {
{}
#[allow(clippy::suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL
&& tracing::Level::INFO <= ::tracing::level_filters::LevelFilter::current()
|| { false }
{
__tracing_attr_span = {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite = {
static META: ::tracing::Metadata<'static> = {
::tracing_core::metadata::Metadata::new(
"<SignupForm />",
"leptos_bug",
tracing::Level::INFO,
::core::option::Option::Some("src/main.rs"),
::core::option::Option::Some(3u32),
::core::option::Option::Some("leptos_bug"),
::tracing_core::field::FieldSet::new(
&[],
::tracing_core::callsite::Identifier(&__CALLSITE),
),
::tracing::metadata::Kind::SPAN,
)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL
&& tracing::Level::INFO
<= ::tracing::level_filters::LevelFilter::current()
&& {
interest = __CALLSITE.interest();
!interest.is_never()
}
&& ::tracing::__macro_support::__is_enabled(
__CALLSITE.metadata(),
interest,
)
{
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta, &{ meta.fields().value_set(&[]) })
} else {
let span = ::tracing::__macro_support::__disabled_span(
__CALLSITE.metadata(),
);
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy::suspicious_else_formatting)]
{
#[allow(
unknown_lints,
unreachable_code,
clippy::diverging_sub_expression,
clippy::let_unit_value,
clippy::unreachable,
clippy::let_with_type_underscore,
clippy::empty_loop
)]
if false {
let __tracing_attr_fake_return: _ = loop {};
return __tracing_attr_fake_return;
}
{
let span = ::leptos::leptos_dom::tracing::Span::current();
::leptos::leptos_dom::Component::new(
"SignupForm",
move || {
#[cfg(debug_assertions)]
let _guard = span.entered();
__SignupForm()
},
)
}
}
}
}
#[doc(hidden)]
#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
fn __SignupForm() -> impl IntoView {
{
#[allow(unused_braces)]
{
let _ = ::leptos::leptos_dom::html::div;
let _ = ::leptos::leptos_dom::html::div;
let _ = ::leptos::leptos_dom::html::h1;
let _ = ::leptos::leptos_dom::html::h1;
::leptos::HtmlElement::from_chunks(
::leptos::leptos_dom::html::Div::default(),
[
leptos::leptos_dom::html::StringOrView::String(
{
let res = ::alloc::fmt::format(
format_args!(
"<div{0}><h1{1}>Hello World</h1></div>",
::leptos::leptos_dom::HydrationCtx::peek().map(| id | { let
res = ::alloc::fmt::format(format_args!(" data-hk=\"{0}\"",
id)); res }).unwrap_or_default(),
::leptos::leptos_dom::HydrationCtx::id().map(| id | { let
res = ::alloc::fmt::format(format_args!(" data-hk=\"{0}\"",
id)); res }).unwrap_or_default()
),
);
res
}
.into(),
),
],
)
}
}
}
fn main() {
{
::std::io::_print(format_args!("Hello, world!\n"));
};
} |
Yeah, I plan on using tracing anyways, but it was weird that adding leptos_axum was breaking for me. |
Sorry didn't see your updates in the midst of my analysis. Anyways more info is always better. :D |
Note that none of the I'm honestly not sure why adding A PR would be welcome to fix this, although as I said I probably can't merge it until 0.6 (in the next few weeks). |
Leptos_axum enables ssr feature on leptos, ssr via cfg-attr on view macro emits tracing calls when view!() macro is used. So yes, its the cfg_attr emitting tracing attribute macros on the view macro when ssr is enabled. |
leptos_auxm enables ssr on leptos leptos ssr feature enables ssr on leptos_macro leptos_macro, lib.rs:
|
FWIW, I'm running into this issue as well. Yep, it's enabling ssr or debug_assertions that causes the issue. I'm seeing it without leptos axum (I'm currently using actix.) Glad to see it's already triaged for 0.6! ❤️ And thanks for including the workaround! |
Just wanted to add, this was all working fine for me when I had my Might the fix be as simple as changing the import to |
I was wrong about this one: what I noted was already gated on the I believe #2211 fixes this (or at least it does in the repro above). |
Describe the bug
When using the component attribute macro, get an error saying tracing is a missing dependency.
Leptos Dependencies
[dependencies]
leptos = "0.5.4"
axum = "0.7.2"
leptos_axum = "0.5.4"
To Reproduce
Steps to reproduce the behavior:
Expected behavior
According to the docs, component macro shouldn't require tracing crate.
Screenshots
Additional context
enabling the tracing feature for leptos does not fix it
The view function in lib.rs seems to have a direct dependency on tracing that is not feature gated?
Adding tracing as a direct dependency to the cargo.toml fixes the issue
The text was updated successfully, but these errors were encountered: