Improve warnings when trying to update outside of pending suspense boundaries on the server (#2575)

* Improve warnings when trying to update outside of pending suspense boundaries on the server

* remove suspense resolve log
This commit is contained in:
Evan Almloff authored and GitHub committed 2024-07-17 19:32:33 -07:00
1 parent 88af3e7eff
commit e794be5d78
14 files changed
+409 -313

No files matched your search

+15 -25
View File
@@ -2,7 +2,7 @@
//!
//! This module provides the primary mechanics to create a hook-based, concurrent VDOM for Rust.
use crate::innerlude::{SuspenseBoundaryProps, Work};
use crate::innerlude::Work;
use crate::properties::RootProps;
use crate::root_wrapper::RootScopeWrapper;
use crate::{
@@ -225,6 +225,9 @@ pub struct VirtualDom {
pub(crate) runtime: Rc<Runtime>,
// The scopes that have been resolved since the last render
pub(crate) resolved_scopes: Vec<ScopeId>,
rx: futures_channel::mpsc::UnboundedReceiver<SchedulerMsg>,
}
@@ -330,6 +333,7 @@ impl VirtualDom {
queued_templates: Default::default(),
elements: Default::default(),
mounts: Default::default(),
resolved_scopes: Default::default(),
};
let root = VProps::new(
@@ -776,8 +780,6 @@ impl VirtualDom {
// Queue any new events before we start working
self.queue_events();
let mut resolved_scopes = Vec::new();
// Render whatever work needs to be rendered, unlocking new futures and suspense leaves
let _runtime = RuntimeGuard::new(self.runtime.clone());
@@ -791,34 +793,21 @@ impl VirtualDom {
}
}
Work::RerunScope(scope) => {
if self
let scope_id: ScopeId = scope.id;
let run_scope = self
.runtime
.get_state(scope.id)
.filter(|scope| scope.should_run_during_suspense())
.is_some()
{
let scope_state = self.get_scope(scope.id).unwrap();
let was_suspended =
SuspenseBoundaryProps::downcast_ref_from_props(&*scope_state.props)
.filter(|props| props.suspended())
.is_some();
.is_some();
if run_scope {
// If the scope is dirty, run the scope and get the mutations
self.run_and_diff_scope(None::<&mut NoOpMutations>, scope.id);
let scope_state = self.get_scope(scope.id).unwrap();
let is_now_suspended =
SuspenseBoundaryProps::downcast_ref_from_props(&*scope_state.props)
.filter(|props| props.suspended())
.is_some();
self.run_and_diff_scope(None::<&mut NoOpMutations>, scope_id);
if is_now_suspended {
resolved_scopes.retain(|&id| id != scope.id);
} else if was_suspended {
resolved_scopes.push(scope.id);
}
tracing::trace!("Ran scope {:?} during suspense", scope_id);
} else {
tracing::warn!(
"Scope {:?} was marked as dirty, but will not rerun during suspense. Only nodes that are under a suspense boundary rerun during suspense",
scope.id
scope_id
);
}
}
@@ -833,8 +822,9 @@ impl VirtualDom {
}
}
resolved_scopes.sort_by_key(|&id| self.runtime.get_state(id).unwrap().height);
resolved_scopes
self.resolved_scopes
.sort_by_key(|&id| self.runtime.get_state(id).unwrap().height);
std::mem::take(&mut self.resolved_scopes)
}
/// Get the current runtime