Assume the virtual dom is not rendering while not diffing components (#3406)

* Invert when the rendering flag is set

* Add a playwright test to make sure effects, and web-sys integration is working

* fix playwright test
This commit is contained in:
Evan Almloff authored and GitHub committed 2024-12-20 12:08:57 -08:00
1 parent cf1940cdac
commit 01ebccc269
8 files changed
+79 -15

No files matched your search

+9 -5
View File
@@ -74,7 +74,7 @@ impl Runtime {
Rc::new(Self {
sender,
rendering: Cell::new(true),
rendering: Cell::new(false),
scope_states: Default::default(),
scope_stack: Default::default(),
suspense_stack: Default::default(),
@@ -108,6 +108,14 @@ impl Runtime {
}
}
/// Run a closure with the rendering flag set to true
pub(crate) fn while_rendering<T>(&self, f: impl FnOnce() -> T) -> T {
self.rendering.set(true);
let result = f();
self.rendering.set(false);
result
}
/// Create a scope context. This slab is synchronized with the scope slab.
pub(crate) fn create_scope(&self, context: Scope) {
let id = context.id;
@@ -380,9 +388,7 @@ impl Runtime {
);
for listener in listeners.into_iter().rev() {
if let AttributeValue::Listener(listener) = listener {
self.rendering.set(false);
listener.call(uievent.clone());
self.rendering.set(true);
let metadata = uievent.metadata.borrow();
if !metadata.propagates {
@@ -420,9 +426,7 @@ impl Runtime {
// Only call the listener if this is the exact target element.
if attr.name.get(2..) == Some(name) && target_path == this_path {
if let AttributeValue::Listener(listener) = &attr.value {
self.rendering.set(false);
listener.call(uievent.clone());
self.rendering.set(true);
break;
}
}