From 03360cefa1b7038174fa3c1fc3a04400b4cdbbce Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 10 Feb 2021 11:38:19 -0500 Subject: [PATCH] fix(compiler-sfc): treat const reactive() bindings as mutable --- packages/compiler-core/src/transforms/vFor.ts | 2 +- packages/compiler-sfc/src/compileScript.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/compiler-core/src/transforms/vFor.ts b/packages/compiler-core/src/transforms/vFor.ts index 5cff0eae..e42cfc77 100644 --- a/packages/compiler-core/src/transforms/vFor.ts +++ b/packages/compiler-core/src/transforms/vFor.ts @@ -79,7 +79,7 @@ export const transformFor = createStructuralDirectiveTransform( const isStableFragment = forNode.source.type === NodeTypes.SIMPLE_EXPRESSION && - forNode.source.constType > ConstantTypes.CAN_SKIP_PATCH + forNode.source.constType > ConstantTypes.NOT_CONSTANT const fragmentFlag = isStableFragment ? PatchFlags.STABLE_FRAGMENT : keyProp diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index d0a08a8a..7b2a869c 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -1036,12 +1036,15 @@ function walkDeclaration( ) if (id.type === 'Identifier') { let bindingType - if ( + const userReactiveBinding = userImportAlias['reactive'] || 'reactive' + if (isCallOf(init, userReactiveBinding)) { + // treat reactive() calls as let since it's meant to be mutable + bindingType = BindingTypes.SETUP_LET + } else if ( // if a declaration is a const literal, we can mark it so that // the generated render fn code doesn't need to unref() it isDefineCall || - (isConst && - canNeverBeRef(init!, userImportAlias['reactive'] || 'reactive')) + (isConst && canNeverBeRef(init!, userReactiveBinding)) ) { bindingType = BindingTypes.SETUP_CONST } else if (isConst) {