move ScopeId methods to the runtime (#4723)

* move `ScopeId` methods to runtime methods

* cargo check unused

* wip...

* wip...

* fix consume context

* fix test

* guard hoisted

* fix doc comment
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2025-10-04 01:55:52 -07:00
1 parent c56bac04f4
commit c29cef4ea3
40 files changed
+466 -697

No files matched your search

+3 -4
View File
@@ -1,6 +1,6 @@
use dioxus_core::provide_context;
use dioxus_core::queue_effect;
use dioxus_core::ScopeId;
use dioxus_core::{provide_context, Runtime};
use dioxus_document::{
Document, Eval, EvalError, Evaluator, LinkProps, MetaProps, ScriptProps, StyleProps,
};
@@ -69,8 +69,7 @@ extern "C" {
fn init_document_with(document: impl FnOnce(), history: impl FnOnce()) {
use dioxus_core::has_context;
ScopeId::ROOT.in_runtime(|| {
Runtime::current().in_scope(ScopeId::ROOT, || {
if has_context::<Rc<dyn Document>>().is_none() {
document();
}
@@ -80,7 +79,7 @@ fn init_document_with(document: impl FnOnce(), history: impl FnOnce()) {
})
}
/// Provides the Document through [`ScopeId::provide_context`].
/// Provides the Document through [`dioxus_core::provide_context`].
pub fn init_document() {
// If hydrate is enabled, we add the FullstackWebDocument with the initial hydration data
#[cfg(not(feature = "hydrate"))]
+1 -1
View File
@@ -149,7 +149,7 @@ impl WebsysDom {
let server_data = HydrationContext::from_serialized(&data, debug_types, debug_locations);
// If the server serialized an error into the suspense boundary, throw it on the client so that it bubbles up to the nearest error boundary
if let Some(error) = server_data.error_entry().get().ok().flatten() {
dom.in_runtime(|| id.throw_error(error));
dom.in_runtime(|| dom.runtime().throw_error(id, error));
}
server_data.in_context(|| {
// rerun the scope with the new data
+7 -9
View File
@@ -6,7 +6,7 @@
pub use crate::cfg::Config;
use crate::hydration::SuspenseMessage;
use dioxus_core::VirtualDom;
use dioxus_core::{ScopeId, VirtualDom};
use dom::WebsysDom;
use futures_util::{pin_mut, select, FutureExt, StreamExt};
@@ -53,7 +53,7 @@ pub async fn run(mut virtual_dom: VirtualDom, web_config: Config) -> ! {
#[cfg(feature = "document")]
if let Some(history) = web_config.history.clone() {
virtual_dom.in_runtime(|| dioxus_core::ScopeId::ROOT.provide_context(history));
virtual_dom.in_scope(ScopeId::ROOT, || dioxus_core::provide_context(history));
}
#[cfg(feature = "document")]
@@ -129,16 +129,14 @@ pub async fn run(mut virtual_dom: VirtualDom, web_config: Config) -> ! {
HydrationContext::from_serialized(&hydration_data, debug_types, debug_locations);
// If the server serialized an error into the root suspense boundary, throw it into the root scope
if let Some(error) = server_data.error_entry().get().ok().flatten() {
virtual_dom.in_runtime(|| dioxus_core::ScopeId::APP.throw_error(error));
virtual_dom.in_runtime(|| virtual_dom.runtime().throw_error(ScopeId::APP, error));
}
server_data.in_context(|| {
virtual_dom.in_runtime(|| {
virtual_dom.in_scope(ScopeId::ROOT, || {
// Provide a hydration compatible create error boundary method
dioxus_core::ScopeId::ROOT.in_runtime(|| {
dioxus_core::provide_create_error_boundary(
dioxus_fullstack_core::init_error_boundary,
);
});
dioxus_core::provide_create_error_boundary(
dioxus_fullstack_core::init_error_boundary,
);
#[cfg(feature = "document")]
document::init_fullstack_document();
});