diff --git a/packages/runtime/src/App.tsx b/packages/runtime/src/App.tsx index 5c83ce6a..47155bf1 100644 --- a/packages/runtime/src/App.tsx +++ b/packages/runtime/src/App.tsx @@ -17,7 +17,7 @@ export const App: React.FC = props => { const { options, services, - debugStore = false, + debugStore = true, debugEvent = false, hooks, isInEditor = false, diff --git a/packages/runtime/src/components/_internal/ImplWrapper/ImplWrapperMain.tsx b/packages/runtime/src/components/_internal/ImplWrapper/ImplWrapperMain.tsx index 05f43df1..d81b9774 100644 --- a/packages/runtime/src/components/_internal/ImplWrapper/ImplWrapperMain.tsx +++ b/packages/runtime/src/components/_internal/ImplWrapper/ImplWrapperMain.tsx @@ -7,7 +7,7 @@ import { useRuntimeFunctions } from './hooks/useRuntimeFunctions'; import { getSlotElements } from './hooks/useSlotChildren'; import { useGlobalHandlerMap } from './hooks/useGlobalHandlerMap'; import { useEleRef } from './hooks/useEleMap'; -import { initStateAndMethod } from '../../../utils/initStateAndMethod'; +import { initSingleComponentState } from '../../../utils/initStateAndMethod'; import ComponentErrorBoundary from '../ComponentErrorBoundary'; export const ImplWrapperMain = React.forwardRef( @@ -23,7 +23,7 @@ export const ImplWrapperMain = React.forwardRef) => { const result = executeTrait(trait, properties); + const prevIsHidden = isHidden; setIsHidden(!!result.unmount); - if (result.unmount) { + + const isLastRender = slotContext ? slotContext.renderSet.size === 0 : true; + + if (result.unmount && isLastRender) { // Every component's state is initialized in initStateAnd Method. // So if if it should not render, we should remove it from store. @@ -52,12 +56,12 @@ export const UnmountImplWrapper = React.forwardRef { diff --git a/packages/runtime/src/utils/initStateAndMethod.ts b/packages/runtime/src/utils/initStateAndMethod.ts index 029eccb4..a79633fe 100644 --- a/packages/runtime/src/utils/initStateAndMethod.ts +++ b/packages/runtime/src/utils/initStateAndMethod.ts @@ -13,12 +13,11 @@ import { JSONSchema7Object } from 'json-schema'; export function initStateAndMethod( registry: RegistryInterface, stateManager: StateManagerInterface, - components: RuntimeComponentSchema[], - mark?: true + components: RuntimeComponentSchema[] ) { components.forEach(c => { - initSingleComponentState(registry, stateManager, c); - if (mark) { + const inited = initSingleComponentState(registry, stateManager, c); + if (inited) { stateManager.initSet.add(c.id); } }); @@ -28,7 +27,7 @@ export function initSingleComponentState( registry: RegistryInterface, stateManager: StateManagerInterface, c: RuntimeComponentSchema -) { +): boolean { if (stateManager.store[c.id]) { return false; } @@ -60,4 +59,6 @@ export function initSingleComponentState( stateManager.store[moduleSchema.id] = moduleInitState; } catch {} } + + return true; }