From acbbf4eb246a8cb3b531037021f4d2530661fb62 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Tue, 19 Jul 2022 19:47:35 +0800 Subject: [PATCH 1/3] fix(runtime): only teardown state when the component is not hidden before this check when we are using slot's ifCondition, the slot may have unmount traits result multiple times --- .../_internal/ImplWrapper/UnmountImplWrapper.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/runtime/src/components/_internal/ImplWrapper/UnmountImplWrapper.tsx b/packages/runtime/src/components/_internal/ImplWrapper/UnmountImplWrapper.tsx index 7603953a..4285c09e 100644 --- a/packages/runtime/src/components/_internal/ImplWrapper/UnmountImplWrapper.tsx +++ b/packages/runtime/src/components/_internal/ImplWrapper/UnmountImplWrapper.tsx @@ -33,14 +33,18 @@ export const UnmountImplWrapper = React.forwardRef) => { const result = executeTrait(trait, properties); + const prevIsHidden = isHidden; setIsHidden(!!result.unmount); if (result.unmount) { // Every component's state is initialized in initStateAnd Method. // So if if it should not render, we should remove it from store. - delete stateManager.store[c.id]; + // Only clear the store when the component is not hidden before this check. + if (!prevIsHidden) { + delete stateManager.store[c.id]; + } } }, - [c.id, executeTrait, stateManager] + [c.id, executeTrait, stateManager, isHidden] ); useEffect(() => { From 25787ec1724ce824dfa91f6a20c2947861e676d0 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Tue, 19 Jul 2022 20:11:15 +0800 Subject: [PATCH 2/3] fix(runtime): check whether this is the first time render of an UnmountImplWrapper when we are using slot's ifCondition, the slot may have unmount traits result multiple times --- .../ImplWrapper/UnmountImplWrapper.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/runtime/src/components/_internal/ImplWrapper/UnmountImplWrapper.tsx b/packages/runtime/src/components/_internal/ImplWrapper/UnmountImplWrapper.tsx index 4285c09e..35c0f579 100644 --- a/packages/runtime/src/components/_internal/ImplWrapper/UnmountImplWrapper.tsx +++ b/packages/runtime/src/components/_internal/ImplWrapper/UnmountImplWrapper.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect, useMemo, useState } from 'react'; +import React, { useCallback, useEffect, useMemo, useState, useRef } from 'react'; import { RuntimeTraitSchema } from '@sunmao-ui/core'; import { ImplWrapperMain } from './ImplWrapperMain'; import { useRuntimeFunctions } from './hooks/useRuntimeFunctions'; @@ -11,6 +11,8 @@ export const UnmountImplWrapper = React.forwardRef @@ -38,8 +40,19 @@ export const UnmountImplWrapper = React.forwardRef