From c8d528b3b18e320ca0cee1542ae5fc659c1cca81 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 21 Jan 2022 09:29:41 -0500 Subject: [PATCH] fix: proprogation of root context --- packages/core/src/scopes.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/core/src/scopes.rs b/packages/core/src/scopes.rs index a4b32e50d..cfc555543 100644 --- a/packages/core/src/scopes.rs +++ b/packages/core/src/scopes.rs @@ -702,19 +702,22 @@ impl ScopeState { while let Some(parent) = search_parent.take() { let parent = unsafe { &*parent }; - if parent - .shared_contexts - .borrow_mut() - .insert(TypeId::of::(), value.clone()) - .is_some() - { - log::warn!("Context already provided to parent scope - replacing it"); + if parent.scope_id() == ScopeId(0) { + let exists = parent + .shared_contexts + .borrow_mut() + .insert(TypeId::of::(), value.clone()); + + if exists.is_some() { + log::warn!("Context already provided to parent scope - replacing it"); + } + return value; } search_parent = parent.parent_scope; } - value + unreachable!("all apps have a root scope") } /// Try to retrieve a SharedState with type T from the any parent Scope.