-
-
Notifications
You must be signed in to change notification settings - Fork 960
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
Add tracing to virtual_dom #1949
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e09e8e8
Beginning work on DioxusLabs/dioxus#1161: fix a few typos
jereanon 7990ce6
Add tracing-fluent-assertion dependency. Start adding spans to some v…
jereanon 913fcba
Unit test showing use of spans. Spans/events for virtual_dom.
jereanon 660c0f2
Reformat files
jereanon c409a78
rename test
jereanon 862bf61
Merge branch 'DioxusLabs:main' into feature/1161
jereanon 7a8bf21
Merge branch 'main' into feature/1161
jereanon 4339665
fix formatting
ealmloff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use dioxus::html::SerializedHtmlEventConverter; | ||
use dioxus::prelude::*; | ||
use dioxus_core::ElementId; | ||
use std::rc::Rc; | ||
use tracing_fluent_assertions::{AssertionRegistry, AssertionsLayer}; | ||
use tracing_subscriber::{layer::SubscriberExt, Registry}; | ||
|
||
#[test] | ||
fn basic_tracing() { | ||
// setup tracing | ||
let assertion_registry = AssertionRegistry::default(); | ||
let base_subscriber = Registry::default(); | ||
// log to standard out for testing | ||
let std_out_log = tracing_subscriber::fmt::layer().pretty(); | ||
let subscriber = base_subscriber | ||
.with(std_out_log) | ||
.with(AssertionsLayer::new(&assertion_registry)); | ||
tracing::subscriber::set_global_default(subscriber).unwrap(); | ||
|
||
let new_virtual_dom = assertion_registry | ||
.build() | ||
.with_name("VirtualDom::new") | ||
.was_created() | ||
.was_entered_exactly(1) | ||
.was_closed() | ||
.finalize(); | ||
|
||
let edited_virtual_dom = assertion_registry | ||
.build() | ||
.with_name("VirtualDom::rebuild") | ||
.was_created() | ||
.was_entered_exactly(1) | ||
.was_closed() | ||
.finalize(); | ||
|
||
set_event_converter(Box::new(SerializedHtmlEventConverter)); | ||
let mut dom = VirtualDom::new(app); | ||
|
||
dom.rebuild(&mut dioxus_core::NoOpMutations); | ||
|
||
new_virtual_dom.assert(); | ||
edited_virtual_dom.assert(); | ||
|
||
for _ in 0..3 { | ||
dom.handle_event( | ||
"click", | ||
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())), | ||
ElementId(2), | ||
true, | ||
); | ||
dom.process_events(); | ||
_ = dom.render_immediate_to_vec(); | ||
} | ||
} | ||
|
||
fn app() -> Element { | ||
let mut idx = use_signal(|| 0); | ||
let onhover = |_| println!("go!"); | ||
|
||
rsx! { | ||
div { | ||
button { | ||
onclick: move |_| { | ||
idx += 1; | ||
println!("Clicked"); | ||
}, | ||
"+" | ||
} | ||
button { onclick: move |_| idx -= 1, "-" } | ||
ul { | ||
{(0..idx()).map(|i| rsx! { | ||
ChildExample { i: i, onhover: onhover } | ||
})} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[component] | ||
fn ChildExample(i: i32, onhover: EventHandler<MouseEvent>) -> Element { | ||
rsx! { li { onmouseover: move |e| onhover.call(e), "{i}" } } | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm torn on testing the traces we output. The tests added in this PR are for APIs that are already public (new and rebuild) but for internal functions it feels like these tests would be very fragile. For example, it isn't defined exactly how many times poll_tasks should be called every rebuild, so we probably shouldn't test how many times that trace is seen
On the other hand, if tracing is the API we plan to use for dev tools in the future, it might make sense to test that tracing is working correctly
The specific tests added in this PR don't seem flakey and are easy enough to remove if they do end up being problematic, so I'm going to go ahead and merge this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't recommend testing the traces outputted, but for the purposes of this PR/issue, i felt it was necessary to prove completion of the work.