Skip to content

Commit

Permalink
fix: prevent removing active instances in normal mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sibbng committed Jan 15, 2021
1 parent fae5ab0 commit 3aef4b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/reactivue/src/component.ts
Expand Up @@ -26,8 +26,10 @@ export const getNewInstanceId = () => {
// When React is in Strict mode, it runs state functions twice
// Remove unmounted instances before creating new one
Object.keys(_vueState).forEach((id) => {
if (!_vueState[+id].isActive)
unmount(+id)
setTimeout(() => {
if (_vueState[+id]?.isActive === false)
unmount(+id)
}, 0)
})
}

Expand Down
5 changes: 4 additions & 1 deletion packages/reactivue/src/useSetup.ts
Expand Up @@ -60,11 +60,14 @@ export function useSetup<State extends Record<any, any>, Props = {}>(
let isChanged = false

useInstanceScope(id, (instance) => {
if (!instance || !instance.isUnmounting)
if (!instance)
return

instance.isActive = true

if (!instance.isUnmounting)
return

const props = Object.assign({}, (ReactProps || {})) as any
const setup = setupFunction(readonly(props))

Expand Down

0 comments on commit 3aef4b8

Please sign in to comment.