diff --git a/components/_util/ActionButton.tsx b/components/_util/ActionButton.tsx index cc967ca99..0958d2404 100644 --- a/components/_util/ActionButton.tsx +++ b/components/_util/ActionButton.tsx @@ -1,5 +1,5 @@ import type { ExtractPropTypes, PropType } from 'vue'; -import { onMounted, ref, defineComponent, onBeforeUnmount } from 'vue'; +import { shallowRef, onMounted, defineComponent, onBeforeUnmount } from 'vue'; import Button from '../button'; import type { ButtonProps } from '../button'; import type { LegacyButtonType } from '../button/buttonTypes'; @@ -32,9 +32,9 @@ export default defineComponent({ name: 'ActionButton', props: actionButtonProps, setup(props, { slots }) { - const clickedRef = ref(false); - const buttonRef = ref(); - const loading = ref(false); + const clickedRef = shallowRef(false); + const buttonRef = shallowRef(); + const loading = shallowRef(false); let timeoutId: any; const isDestroyed = useDestroyed(); onMounted(() => { diff --git a/components/_util/BaseInput.tsx b/components/_util/BaseInput.tsx index 009613a74..db85e3a4f 100644 --- a/components/_util/BaseInput.tsx +++ b/components/_util/BaseInput.tsx @@ -1,4 +1,4 @@ -import { defineComponent, ref, withDirectives } from 'vue'; +import { defineComponent, shallowRef, withDirectives } from 'vue'; import antInput from './antInputDirective'; import PropTypes from './vue-types'; const BaseInput = defineComponent({ @@ -8,7 +8,7 @@ const BaseInput = defineComponent({ }, emits: ['change', 'input'], setup(_p, { emit }) { - const inputRef = ref(null); + const inputRef = shallowRef(null); const handleChange = (e: Event) => { const { composing } = e.target as any; if ((e as any).isComposing || composing) { diff --git a/components/_util/PortalWrapper.tsx b/components/_util/PortalWrapper.tsx index 5c02f3ba3..083ed4c81 100644 --- a/components/_util/PortalWrapper.tsx +++ b/components/_util/PortalWrapper.tsx @@ -4,7 +4,7 @@ import setStyle from './setStyle'; import Portal from './Portal'; import { defineComponent, - ref, + shallowRef, watch, onMounted, onBeforeUnmount, @@ -60,9 +60,9 @@ export default defineComponent({ }, setup(props, { slots }) { - const container = ref(); - const componentRef = ref(); - const rafId = ref(); + const container = shallowRef(); + const componentRef = shallowRef(); + const rafId = shallowRef(); const scrollLocker = new ScrollLocker({ container: getParent(props.getContainer) as HTMLElement, }); diff --git a/components/_util/hooks/_vueuse/useElementSize.ts b/components/_util/hooks/_vueuse/useElementSize.ts index 90beea16b..bc90e9a06 100644 --- a/components/_util/hooks/_vueuse/useElementSize.ts +++ b/components/_util/hooks/_vueuse/useElementSize.ts @@ -1,4 +1,4 @@ -import { ref, watch } from 'vue'; +import { shallowRef, watch } from 'vue'; import type { MaybeComputedElementRef } from './unrefElement'; import type { UseResizeObserverOptions } from './useResizeObserver'; import { useResizeObserver } from './useResizeObserver'; @@ -23,8 +23,8 @@ export function useElementSize( options: UseResizeObserverOptions = {}, ) { const { box = 'content-box' } = options; - const width = ref(initialSize.width); - const height = ref(initialSize.height); + const width = shallowRef(initialSize.width); + const height = shallowRef(initialSize.height); useResizeObserver( target, diff --git a/components/_util/hooks/_vueuse/useSupported.ts b/components/_util/hooks/_vueuse/useSupported.ts index 7705bf63d..360e8e613 100644 --- a/components/_util/hooks/_vueuse/useSupported.ts +++ b/components/_util/hooks/_vueuse/useSupported.ts @@ -1,9 +1,8 @@ import { tryOnMounted } from './tryOnMounted'; -import type { Ref } from 'vue'; -import { ref } from 'vue'; +import { shallowRef } from 'vue'; export function useSupported(callback: () => unknown, sync = false) { - const isSupported = ref() as Ref; + const isSupported = shallowRef(); const update = () => (isSupported.value = Boolean(callback())); diff --git a/components/_util/hooks/useBreakpoint.ts b/components/_util/hooks/useBreakpoint.ts index 49b84cfe1..1c20a996d 100644 --- a/components/_util/hooks/useBreakpoint.ts +++ b/components/_util/hooks/useBreakpoint.ts @@ -1,10 +1,10 @@ import type { Ref } from 'vue'; -import { onMounted, onUnmounted, ref } from 'vue'; +import { onMounted, onUnmounted, shallowRef } from 'vue'; import type { ScreenMap } from '../../_util/responsiveObserve'; import useResponsiveObserve from '../../_util/responsiveObserve'; function useBreakpoint(): Ref { - const screens = ref({}); + const screens = shallowRef({}); let token = null; const responsiveObserve = useResponsiveObserve(); diff --git a/components/_util/hooks/useDestroyed.ts b/components/_util/hooks/useDestroyed.ts index 57cc17230..7fa1f5022 100644 --- a/components/_util/hooks/useDestroyed.ts +++ b/components/_util/hooks/useDestroyed.ts @@ -1,7 +1,7 @@ -import { onBeforeUnmount, ref } from 'vue'; +import { onBeforeUnmount, shallowRef } from 'vue'; const useDestroyed = () => { - const destroyed = ref(false); + const destroyed = shallowRef(false); onBeforeUnmount(() => { destroyed.value = true; }); diff --git a/components/_util/hooks/useFlexGapSupport.ts b/components/_util/hooks/useFlexGapSupport.ts index eb3c100ec..592cc762a 100644 --- a/components/_util/hooks/useFlexGapSupport.ts +++ b/components/_util/hooks/useFlexGapSupport.ts @@ -1,8 +1,8 @@ -import { onMounted, ref } from 'vue'; +import { onMounted, shallowRef } from 'vue'; import { detectFlexGapSupported } from '../styleChecker'; export default () => { - const flexible = ref(false); + const flexible = shallowRef(false); onMounted(() => { flexible.value = detectFlexGapSupported(); }); diff --git a/components/_util/hooks/useLayoutState.ts b/components/_util/hooks/useLayoutState.ts index 78630a882..95189fccd 100644 --- a/components/_util/hooks/useLayoutState.ts +++ b/components/_util/hooks/useLayoutState.ts @@ -1,5 +1,5 @@ import type { Ref } from 'vue'; -import { onBeforeUnmount, ref } from 'vue'; +import { onBeforeUnmount, shallowRef } from 'vue'; import raf from '../raf'; export type Updater = (prev: State) => State; @@ -9,11 +9,11 @@ export type Updater = (prev: State) => State; export function useLayoutState( defaultState: State, ): [Ref, (updater: Updater) => void] { - const stateRef = ref(defaultState); + const stateRef = shallowRef(defaultState); let tempState = stateRef.value; let updateBatchRef = []; - const rafRef = ref(); + const rafRef = shallowRef(); function setFrameState(updater: Updater) { raf.cancel(rafRef.value); updateBatchRef.push(updater); diff --git a/components/_util/transButton.tsx b/components/_util/transButton.tsx index caced47cd..548948d55 100644 --- a/components/_util/transButton.tsx +++ b/components/_util/transButton.tsx @@ -1,5 +1,5 @@ import type { CSSProperties } from 'vue'; -import { defineComponent, ref, onMounted } from 'vue'; +import { defineComponent, shallowRef, onMounted } from 'vue'; /** * Wrap of sub component which need use as Button capacity (like Icon component). * This helps accessibility reader to tread as a interactive button to operation. @@ -25,7 +25,7 @@ const TransButton = defineComponent({ autofocus: { type: Boolean, default: undefined }, }, setup(props, { slots, emit, attrs, expose }) { - const domRef = ref(); + const domRef = shallowRef(); const onKeyDown = (event: KeyboardEvent) => { const { keyCode } = event; if (keyCode === KeyCode.ENTER) { diff --git a/components/_util/wave/WaveEffect.tsx b/components/_util/wave/WaveEffect.tsx index 8b7474756..1f3ce23d1 100644 --- a/components/_util/wave/WaveEffect.tsx +++ b/components/_util/wave/WaveEffect.tsx @@ -1,5 +1,5 @@ import type { CSSProperties } from 'vue'; -import { onBeforeUnmount, onMounted, Transition, render, defineComponent, ref } from 'vue'; +import { onBeforeUnmount, onMounted, Transition, render, defineComponent, shallowRef } from 'vue'; import useState from '../hooks/useState'; import { objectType } from '../type'; import { getTargetWaveColor } from './util'; @@ -19,7 +19,7 @@ const WaveEffect = defineComponent({ className: String, }, setup(props) { - const divRef = ref(null); + const divRef = shallowRef(null); const [color, setWaveColor] = useState(null); const [borderRadius, setBorderRadius] = useState([]); diff --git a/components/affix/index.tsx b/components/affix/index.tsx index 7c8d42ff9..8fa2be9f1 100644 --- a/components/affix/index.tsx +++ b/components/affix/index.tsx @@ -1,7 +1,7 @@ import type { ComponentPublicInstance, CSSProperties, ExtractPropTypes, PropType } from 'vue'; import { defineComponent, - ref, + shallowRef, reactive, watch, onMounted, @@ -77,8 +77,8 @@ const Affix = defineComponent({ inheritAttrs: false, props: affixProps(), setup(props, { slots, emit, expose, attrs }) { - const placeholderNode = ref(); - const fixedNode = ref(); + const placeholderNode = shallowRef(); + const fixedNode = shallowRef(); const state = reactive({ affixStyle: undefined, placeholderStyle: undefined, diff --git a/components/alert/index.tsx b/components/alert/index.tsx index 68dba0a25..63a61aa6e 100644 --- a/components/alert/index.tsx +++ b/components/alert/index.tsx @@ -1,5 +1,5 @@ import type { CSSProperties, ExtractPropTypes, PropType } from 'vue'; -import { computed, defineComponent, ref } from 'vue'; +import { computed, defineComponent, shallowRef } from 'vue'; import CloseOutlined from '@ant-design/icons-vue/CloseOutlined'; import CheckCircleOutlined from '@ant-design/icons-vue/CheckCircleOutlined'; import ExclamationCircleOutlined from '@ant-design/icons-vue/ExclamationCircleOutlined'; @@ -71,9 +71,9 @@ const Alert = defineComponent({ setup(props, { slots, emit, attrs, expose }) { const { prefixCls, direction } = useConfigInject('alert', props); const [wrapSSR, hashId] = useStyle(prefixCls); - const closing = ref(false); - const closed = ref(false); - const alertNode = ref(); + const closing = shallowRef(false); + const closed = shallowRef(false); + const alertNode = shallowRef(); const handleClose = (e: MouseEvent) => { e.preventDefault(); @@ -103,7 +103,7 @@ const Alert = defineComponent({ return props.banner ? 'warning' : 'info'; }); expose({ animationEnd }); - const motionStyle = ref({}); + const motionStyle = shallowRef({}); return () => { const { banner, closeIcon: customCloseIcon = slots.closeIcon?.() } = props; diff --git a/components/avatar/Avatar.tsx b/components/avatar/Avatar.tsx index 3b4a6ffe9..5713610fc 100644 --- a/components/avatar/Avatar.tsx +++ b/components/avatar/Avatar.tsx @@ -1,7 +1,7 @@ import type { VueNode } from '../_util/type'; import type { CSSProperties, ExtractPropTypes, PropType } from 'vue'; -import { computed, defineComponent, nextTick, onMounted, ref, watch } from 'vue'; +import { computed, defineComponent, nextTick, onMounted, shallowRef, watch } from 'vue'; import { getPropsSlot } from '../_util/props-util'; import PropTypes from '../_util/vue-types'; import useBreakpoint from '../_util/hooks/useBreakpoint'; @@ -44,12 +44,12 @@ const Avatar = defineComponent({ props: avatarProps(), slots: ['icon'], setup(props, { slots, attrs }) { - const isImgExist = ref(true); - const isMounted = ref(false); - const scale = ref(1); + const isImgExist = shallowRef(true); + const isMounted = shallowRef(false); + const scale = shallowRef(1); - const avatarChildrenRef = ref(null); - const avatarNodeRef = ref(null); + const avatarChildrenRef = shallowRef(null); + const avatarNodeRef = shallowRef(null); const { prefixCls } = useConfigInject('avatar', props); const [wrapSSR, hashId] = useStyle(prefixCls); diff --git a/components/button/button.tsx b/components/button/button.tsx index 47cbbb6b0..9d655e912 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -4,7 +4,7 @@ import { onBeforeUnmount, onMounted, onUpdated, - ref, + shallowRef, Text, watch, watchEffect, @@ -17,7 +17,7 @@ import devWarning from '../vc-util/devWarning'; import LoadingIcon from './LoadingIcon'; import useStyle from './style'; import type { ButtonType } from './buttonTypes'; -import type { VNode, Ref } from 'vue'; +import type { VNode } from 'vue'; import { GroupSizeContext } from './button-group'; import { useCompactItemContext } from '../space/Compact'; @@ -42,12 +42,12 @@ export default defineComponent({ const { prefixCls, autoInsertSpaceInButton, direction, size } = useConfigInject('btn', props); const [wrapSSR, hashId] = useStyle(prefixCls); const groupSizeContext = GroupSizeContext.useInject(); - const buttonNodeRef = ref(null); - const delayTimeoutRef = ref(undefined); + const buttonNodeRef = shallowRef(null); + const delayTimeoutRef = shallowRef(undefined); let isNeedInserted = false; - const innerLoading: Ref = ref(false); - const hasTwoCNChar = ref(false); + const innerLoading = shallowRef(false); + const hasTwoCNChar = shallowRef(false); const autoInsertSpace = computed(() => autoInsertSpaceInButton.value !== false); const { compactSize, compactItemClassnames } = useCompactItemContext(prefixCls, direction); diff --git a/components/collapse/PanelContent.tsx b/components/collapse/PanelContent.tsx index 29a2aabff..6c33b614c 100644 --- a/components/collapse/PanelContent.tsx +++ b/components/collapse/PanelContent.tsx @@ -1,4 +1,4 @@ -import { defineComponent, ref, watchEffect } from 'vue'; +import { defineComponent, shallowRef, watchEffect } from 'vue'; import { collapsePanelProps } from './commonProps'; import classNames from '../_util/classNames'; @@ -7,7 +7,7 @@ export default defineComponent({ name: 'PanelContent', props: collapsePanelProps(), setup(props, { slots }) { - const rendered = ref(false); + const rendered = shallowRef(false); watchEffect(() => { if (props.isActive || props.forceRender) { @@ -20,7 +20,6 @@ export default defineComponent({ const { prefixCls, isActive, role } = props; return (
props.open ?? props.visible); watch( mergedOpen, diff --git a/components/form/FormItem.tsx b/components/form/FormItem.tsx index 985de0486..244aaf19e 100644 --- a/components/form/FormItem.tsx +++ b/components/form/FormItem.tsx @@ -13,7 +13,7 @@ import { defineComponent, computed, nextTick, - ref, + shallowRef, watchEffect, onBeforeUnmount, toRaw, @@ -158,12 +158,12 @@ export default defineComponent({ const eventKey = `form-item-${++indexGuid}`; const { prefixCls } = useConfigInject('form', props); const [wrapSSR, hashId] = useStyle(prefixCls); - const itemRef = ref(); + const itemRef = shallowRef(); const formContext = useInjectForm(); const fieldName = computed(() => props.name || props.prop); - const errors = ref([]); - const validateDisabled = ref(false); - const inputRef = ref(); + const errors = shallowRef([]); + const validateDisabled = shallowRef(false); + const inputRef = shallowRef(); const namePath = computed(() => { const val = fieldName.value; return getNamePath(val); @@ -188,7 +188,7 @@ export default defineComponent({ }; const fieldValue = computed(() => getNewFieldValue()); - const initialValue = ref(cloneDeep(fieldValue.value)); + const initialValue = shallowRef(cloneDeep(fieldValue.value)); const mergedValidateTrigger = computed(() => { let validateTrigger = props.validateTrigger !== undefined @@ -228,7 +228,7 @@ export default defineComponent({ return isRequired || props.required; }); - const validateState = ref(); + const validateState = shallowRef(); watchEffect(() => { validateState.value = props.validateStatus; }); @@ -445,8 +445,8 @@ export default defineComponent({ }); }); - const marginBottom = ref(null); - const showMarginOffset = ref(false); + const marginBottom = shallowRef(null); + const showMarginOffset = shallowRef(false); const updateMarginBottom = () => { if (itemRef.value) { const itemStyle = getComputedStyle(itemRef.value); diff --git a/components/input-number/index.tsx b/components/input-number/index.tsx index 828fdffc7..d68a4a147 100644 --- a/components/input-number/index.tsx +++ b/components/input-number/index.tsx @@ -1,5 +1,5 @@ import type { ExtractPropTypes, HTMLAttributes, App } from 'vue'; -import { watch, defineComponent, ref, computed } from 'vue'; +import { watch, defineComponent, shallowRef, computed } from 'vue'; import classNames from '../_util/classNames'; import UpOutlined from '@ant-design/icons-vue/UpOutlined'; import DownOutlined from '@ant-design/icons-vue/DownOutlined'; @@ -62,15 +62,15 @@ const InputNumber = defineComponent({ const mergedSize = computed(() => compactSize.value || size.value); const disabledContext = useInjectDisabled(); const mergedDisabled = computed(() => disabled.value ?? disabledContext.value); - const mergedValue = ref(props.value === undefined ? props.defaultValue : props.value); - const focused = ref(false); + const mergedValue = shallowRef(props.value === undefined ? props.defaultValue : props.value); + const focused = shallowRef(false); watch( () => props.value, () => { mergedValue.value = props.value; }, ); - const inputNumberRef = ref(null); + const inputNumberRef = shallowRef(null); const focus = () => { inputNumberRef.value?.focus(); }; diff --git a/components/input-number/src/InputNumber.tsx b/components/input-number/src/InputNumber.tsx index 9fa230564..e6b64d7d3 100644 --- a/components/input-number/src/InputNumber.tsx +++ b/components/input-number/src/InputNumber.tsx @@ -6,7 +6,7 @@ import { getNumberPrecision, num2str, validateNumber } from './utils/numberUtil' import useCursor from './hooks/useCursor'; import useFrame from './hooks/useFrame'; import type { HTMLAttributes } from 'vue'; -import { watch, computed, ref, defineComponent } from 'vue'; +import { watch, computed, shallowRef, defineComponent } from 'vue'; import type { ChangeEvent, KeyboardEventHandler } from '../../_util/EventInterface'; import KeyCode from '../../_util/KeyCode'; import classNames from '../../_util/classNames'; @@ -85,11 +85,11 @@ export default defineComponent({ }, slots: ['upHandler', 'downHandler'], setup(props, { attrs, slots, emit, expose }) { - const inputRef = ref(); - const focus = ref(false); - const userTypingRef = ref(false); - const compositionRef = ref(false); - const decimalValue = ref(getMiniDecimal(props.value)); + const inputRef = shallowRef(); + const focus = shallowRef(false); + const userTypingRef = shallowRef(false); + const compositionRef = shallowRef(false); + const decimalValue = shallowRef(getMiniDecimal(props.value)); function setUncontrolledDecimalValue(newDecimal: DecimalClass) { if (props.value === undefined) { @@ -139,7 +139,7 @@ export default defineComponent({ }; // >>> Formatter - const inputValue = ref(''); + const inputValue = shallowRef(''); const mergedFormatter = (number: string, userTyping: boolean) => { if (props.formatter) { diff --git a/components/input-number/src/hooks/useFrame.ts b/components/input-number/src/hooks/useFrame.ts index 64e19a9e7..aebe43d07 100644 --- a/components/input-number/src/hooks/useFrame.ts +++ b/components/input-number/src/hooks/useFrame.ts @@ -1,11 +1,11 @@ import raf from '../../../_util/raf'; -import { onBeforeUnmount, ref } from 'vue'; +import { onBeforeUnmount, shallowRef } from 'vue'; /** * Always trigger latest once when call multiple time */ export default () => { - const idRef = ref(0); + const idRef = shallowRef(0); const cleanUp = () => { raf.cancel(idRef.value); diff --git a/components/input/Password.tsx b/components/input/Password.tsx index 1f4c66a20..0a62f9061 100644 --- a/components/input/Password.tsx +++ b/components/input/Password.tsx @@ -6,7 +6,7 @@ import EyeOutlined from '@ant-design/icons-vue/EyeOutlined'; import EyeInvisibleOutlined from '@ant-design/icons-vue/EyeInvisibleOutlined'; import type { InputProps } from './inputProps'; import inputProps from './inputProps'; -import { computed, defineComponent, ref } from 'vue'; +import { computed, defineComponent, shallowRef } from 'vue'; import useConfigInject from '../config-provider/hooks/useConfigInject'; import omit from '../_util/omit'; @@ -29,7 +29,7 @@ export default defineComponent({ iconRender: Function, }, setup(props, { slots, attrs, expose }) { - const visible = ref(false); + const visible = shallowRef(false); const onVisibleChange = () => { const { disabled } = props; if (disabled) { @@ -37,7 +37,7 @@ export default defineComponent({ } visible.value = !visible.value; }; - const inputRef = ref(); + const inputRef = shallowRef(); const focus = () => { inputRef.value?.focus(); }; diff --git a/components/input/Search.tsx b/components/input/Search.tsx index 4ec8fe3a9..b3ebded7f 100644 --- a/components/input/Search.tsx +++ b/components/input/Search.tsx @@ -1,5 +1,5 @@ import type { PropType } from 'vue'; -import { computed, ref, defineComponent } from 'vue'; +import { computed, shallowRef, defineComponent } from 'vue'; import classNames from '../_util/classNames'; import Input from './Input'; import SearchOutlined from '@ant-design/icons-vue/SearchOutlined'; @@ -32,8 +32,8 @@ export default defineComponent({ }, }, setup(props, { slots, attrs, expose, emit }) { - const inputRef = ref(); - const composedRef = ref(false); + const inputRef = shallowRef(); + const composedRef = shallowRef(false); const focus = () => { inputRef.value?.focus(); }; diff --git a/components/input/TextArea.tsx b/components/input/TextArea.tsx index e0bf37ce8..c6dcaaea2 100644 --- a/components/input/TextArea.tsx +++ b/components/input/TextArea.tsx @@ -4,7 +4,7 @@ import { defineComponent, getCurrentInstance, nextTick, - ref, + shallowRef, watch, watchEffect, } from 'vue'; @@ -58,9 +58,9 @@ export default defineComponent({ const formItemContext = useInjectFormItemContext(); const formItemInputContext = FormItemInputContext.useInject(); const mergedStatus = computed(() => getMergedStatus(formItemInputContext.status, props.status)); - const stateValue = ref(props.value === undefined ? props.defaultValue : props.value); - const resizableTextArea = ref(); - const mergedValue = ref(''); + const stateValue = shallowRef(props.value === undefined ? props.defaultValue : props.value); + const resizableTextArea = shallowRef(); + const mergedValue = shallowRef(''); const { prefixCls, size, direction } = useConfigInject('input', props); // Style @@ -71,10 +71,10 @@ export default defineComponent({ }); // Max length value const hasMaxLength = computed(() => Number(props.maxlength) > 0); - const compositing = ref(false); + const compositing = shallowRef(false); - const oldCompositionValueRef = ref(); - const oldSelectionStartRef = ref(0); + const oldCompositionValueRef = shallowRef(); + const oldSelectionStartRef = shallowRef(0); const onInternalCompositionStart = (e: CompositionEvent) => { compositing.value = true; // 拼音输入前保存一份旧值 diff --git a/components/layout/Sider.tsx b/components/layout/Sider.tsx index d9a937f5d..4f438bc0e 100644 --- a/components/layout/Sider.tsx +++ b/components/layout/Sider.tsx @@ -1,6 +1,14 @@ import classNames from '../_util/classNames'; import type { PropType, ExtractPropTypes, CSSProperties } from 'vue'; -import { inject, defineComponent, ref, watch, onMounted, onBeforeUnmount, provide } from 'vue'; +import { + inject, + defineComponent, + shallowRef, + watch, + onMounted, + onBeforeUnmount, + provide, +} from 'vue'; import PropTypes from '../_util/vue-types'; import { tuple } from '../_util/type'; import initDefaultProps from '../_util/props-util/initDefaultProps'; @@ -72,10 +80,10 @@ export default defineComponent({ setup(props, { emit, attrs, slots }) { const { prefixCls } = useConfigInject('layout-sider', props); const siderHook = inject(SiderHookProviderKey, undefined); - const collapsed = ref( + const collapsed = shallowRef( !!(props.collapsed !== undefined ? props.collapsed : props.defaultCollapsed), ); - const below = ref(false); + const below = shallowRef(false); watch( () => props.collapsed, @@ -95,7 +103,7 @@ export default defineComponent({ }; // ========================= Responsive ========================= - const responsiveHandlerRef = ref<(mql: MediaQueryListEvent | MediaQueryList) => void>( + const responsiveHandlerRef = shallowRef<(mql: MediaQueryListEvent | MediaQueryList) => void>( (mql: MediaQueryListEvent | MediaQueryList) => { below.value = mql.matches; emit('breakpoint', mql.matches); diff --git a/components/mentions/index.tsx b/components/mentions/index.tsx index 3c23fb032..8435d5b29 100644 --- a/components/mentions/index.tsx +++ b/components/mentions/index.tsx @@ -1,5 +1,5 @@ import type { App, PropType, ExtractPropTypes } from 'vue'; -import { computed, watch, ref, defineComponent } from 'vue'; +import { computed, watch, shallowRef, defineComponent } from 'vue'; import classNames from '../_util/classNames'; import PropTypes from '../_util/vue-types'; import VcMentions, { Option } from '../vc-mentions'; @@ -115,9 +115,9 @@ const Mentions = defineComponent({ } const { prefixCls, renderEmpty, direction } = useConfigInject('mentions', props); const [wrapSSR, hashId] = useStyle(prefixCls); - const focused = ref(false); - const vcMentions = ref(null); - const value = ref(props.value ?? props.defaultValue ?? ''); + const focused = shallowRef(false); + const vcMentions = shallowRef(null); + const value = shallowRef(props.value ?? props.defaultValue ?? ''); const formItemContext = useInjectFormItemContext(); const formItemInputContext = FormItemInputContext.useInject(); const mergedStatus = computed(() => getMergedStatus(formItemInputContext.status, props.status)); diff --git a/components/menu/src/Menu.tsx b/components/menu/src/Menu.tsx index 9f260d10f..75c65723b 100644 --- a/components/menu/src/Menu.tsx +++ b/components/menu/src/Menu.tsx @@ -117,7 +117,7 @@ export default defineComponent({ return props.inlineCollapsed; }); const { itemsNodes } = useItems(props); - const isMounted = ref(false); + const isMounted = shallowRef(false); onMounted(() => { isMounted.value = true; }); @@ -267,7 +267,7 @@ export default defineComponent({ const disabled = computed(() => !!props.disabled); const isRtl = computed(() => direction.value === 'rtl'); const mergedMode = ref('vertical'); - const mergedInlineCollapsed = ref(false); + const mergedInlineCollapsed = shallowRef(false); watchEffect(() => { if ((props.mode === 'inline' || props.mode === 'vertical') && inlineCollapsed.value) { @@ -293,7 +293,7 @@ export default defineComponent({ // >>>>> Cache & Reset open keys when inlineCollapsed changed const inlineCacheOpenKeys = ref(mergedOpenKeys.value); - const mountRef = ref(false); + const mountRef = shallowRef(false); // Cache watch( @@ -426,13 +426,13 @@ export default defineComponent({ siderCollapsed, defaultMotions: computed(() => (isMounted.value ? defaultMotions.value : null)), motion: computed(() => (isMounted.value ? props.motion : null)), - overflowDisabled: ref(undefined), + overflowDisabled: shallowRef(undefined), onOpenChange: onInternalOpenChange, onItemClick: onInternalClick, registerMenuInfo, unRegisterMenuInfo, selectedSubMenuKeys, - isRootMenu: ref(true), + isRootMenu: shallowRef(true), expandIcon, forceSubMenuRender: computed(() => props.forceSubMenuRender), rootClassName: hashId, diff --git a/components/menu/src/MenuItem.tsx b/components/menu/src/MenuItem.tsx index fe4ec5b92..a5406d140 100644 --- a/components/menu/src/MenuItem.tsx +++ b/components/menu/src/MenuItem.tsx @@ -1,7 +1,14 @@ import { flattenChildren, getPropsSlot, isValidElement } from '../../_util/props-util'; import PropTypes from '../../_util/vue-types'; import type { ExtractPropTypes, PropType } from 'vue'; -import { computed, defineComponent, getCurrentInstance, onBeforeUnmount, ref, watch } from 'vue'; +import { + computed, + defineComponent, + getCurrentInstance, + onBeforeUnmount, + shallowRef, + watch, +} from 'vue'; import { useInjectKeyPath, useMeasure } from './hooks/useKeyPath'; import { useInjectFirstLevel, useInjectMenu } from './hooks/useMenuContext'; import { cloneElement } from '../../_util/vnode'; @@ -64,7 +71,7 @@ export default defineComponent({ unRegisterMenuInfo, } = useInjectMenu(); const firstLevel = useInjectFirstLevel(); - const isActive = ref(false); + const isActive = shallowRef(false); const keysPath = computed(() => { return [...parentKeys.value, key]; }); diff --git a/components/menu/src/PopupTrigger.tsx b/components/menu/src/PopupTrigger.tsx index 1c29be662..a061d9200 100644 --- a/components/menu/src/PopupTrigger.tsx +++ b/components/menu/src/PopupTrigger.tsx @@ -1,6 +1,6 @@ import Trigger from '../../vc-trigger'; import type { PropType } from 'vue'; -import { computed, defineComponent, onBeforeUnmount, ref, watch } from 'vue'; +import { computed, defineComponent, onBeforeUnmount, shallowRef, watch } from 'vue'; import type { MenuMode } from './interface'; import { useInjectForceRender, useInjectMenu } from './hooks/useMenuContext'; import { placements, placementsRtl } from './placements'; @@ -31,7 +31,7 @@ export default defineComponent({ slots: ['popup'], emits: ['visibleChange'], setup(props, { slots, emit }) { - const innerVisible = ref(false); + const innerVisible = shallowRef(false); const { getPopupContainer, rtl, @@ -54,7 +54,7 @@ export default defineComponent({ const popupPlacement = computed(() => popupPlacementMap[props.mode]); - const visibleRef = ref(); + const visibleRef = shallowRef(); watch( () => props.visible, visible => { diff --git a/components/menu/src/SubMenu.tsx b/components/menu/src/SubMenu.tsx index 468007d3e..e5764242d 100644 --- a/components/menu/src/SubMenu.tsx +++ b/components/menu/src/SubMenu.tsx @@ -1,6 +1,13 @@ import PropTypes from '../../_util/vue-types'; import type { PropType, ExtractPropTypes } from 'vue'; -import { computed, defineComponent, getCurrentInstance, ref, watch, onBeforeUnmount } from 'vue'; +import { + computed, + defineComponent, + getCurrentInstance, + shallowRef, + watch, + onBeforeUnmount, +} from 'vue'; import useProvideKeyPath, { useInjectKeyPath, useMeasure } from './hooks/useKeyPath'; import { useInjectMenu, @@ -67,7 +74,7 @@ export default defineComponent({ (isValid(vnodeKey) ? `sub_menu_${++indexGuid}_$$_${vnodeKey}` : (key as string)); const { parentEventKeys, parentInfo, parentKeys } = useInjectKeyPath(); const keysPath = computed(() => [...parentKeys.value, key]); - const childrenEventKeys = ref([]); + const childrenEventKeys = shallowRef([]); const menuInfo = { eventKey, key, @@ -119,8 +126,8 @@ export default defineComponent({ const subMenuPrefixCls = computed(() => `${prefixCls.value}-submenu`); const mergedDisabled = computed(() => contextDisabled.value || props.disabled); - const elementRef = ref(); - const popupRef = ref(); + const elementRef = shallowRef(); + const popupRef = shallowRef(); // // ================================ Icon ================================ // const mergedItemIcon = itemIcon || contextItemIcon; @@ -135,7 +142,7 @@ export default defineComponent({ return selectedSubMenuKeys.value.includes(key); }); - const isActive = ref(false); + const isActive = shallowRef(false); watch( activeKeys, () => { diff --git a/components/menu/src/hooks/useItems.tsx b/components/menu/src/hooks/useItems.tsx index b4db72f39..b49127f9d 100644 --- a/components/menu/src/hooks/useItems.tsx +++ b/components/menu/src/hooks/useItems.tsx @@ -115,7 +115,7 @@ function convertItemsToNodes( */ export default function useItems(props: MenuProps) { const itemsNodes = shallowRef([]); - const hasItmes = ref(false); + const hasItmes = shallowRef(false); const store = shallowRef>(new Map()); watch( () => props.items, diff --git a/components/page-header/index.tsx b/components/page-header/index.tsx index 5de97b6ec..849488600 100644 --- a/components/page-header/index.tsx +++ b/components/page-header/index.tsx @@ -1,5 +1,5 @@ import type { ExtractPropTypes, PropType } from 'vue'; -import { defineComponent, ref, computed } from 'vue'; +import { defineComponent, shallowRef, computed } from 'vue'; import PropTypes from '../_util/vue-types'; import { filterEmpty, flattenChildren, isEmptyContent } from '../_util/props-util'; import ArrowLeftOutlined from '@ant-design/icons-vue/ArrowLeftOutlined'; @@ -49,7 +49,7 @@ const PageHeader = defineComponent({ // style const [wrapSSR, hashId] = useStyle(prefixCls); - const compact = ref(false); + const compact = shallowRef(false); const isDestroyed = useDestroyed(); const onResize = ({ width }: { width: number }) => { if (!isDestroyed.value) { diff --git a/components/qrcode/QRCodeCanvas.tsx b/components/qrcode/QRCodeCanvas.tsx index 7f9192a91..6ef45fe17 100644 --- a/components/qrcode/QRCodeCanvas.tsx +++ b/components/qrcode/QRCodeCanvas.tsx @@ -1,5 +1,5 @@ import type { CSSProperties } from 'vue'; -import { defineComponent, ref, watch, computed, watchEffect } from 'vue'; +import { defineComponent, shallowRef, watch, computed, watchEffect } from 'vue'; import type { ImageSettings } from './interface'; import { qrProps } from './interface'; @@ -146,9 +146,9 @@ export const QRCodeCanvas = defineComponent({ props: { ...qrProps(), level: String, bgColor: String, fgColor: String, marginSize: Number }, setup(props, { attrs, expose }) { const imgSrc = computed(() => props.imageSettings?.src); - const _canvas = ref(null); - const _image = ref(null); - const isImgLoaded = ref(false); + const _canvas = shallowRef(null); + const _image = shallowRef(null); + const isImgLoaded = shallowRef(false); expose({ toDataURL: (type?: string, quality?: any) => { return _canvas.value?.toDataURL(type, quality); diff --git a/components/segmented/src/segmented.tsx b/components/segmented/src/segmented.tsx index 2ecd3f7a0..48f65994b 100644 --- a/components/segmented/src/segmented.tsx +++ b/components/segmented/src/segmented.tsx @@ -1,4 +1,4 @@ -import { defineComponent, ref, computed } from 'vue'; +import { defineComponent, shallowRef, computed } from 'vue'; import type { ExtractPropTypes, FunctionalComponent } from 'vue'; import classNames from '../../_util/classNames'; import useConfigInject from '../../config-provider/hooks/useConfigInject'; @@ -119,8 +119,8 @@ export default defineComponent({ setup(props, { emit, slots, attrs }) { const { prefixCls, direction, size } = useConfigInject('segmented', props); const [wrapSSR, hashId] = useStyle(prefixCls); - const rootRef = ref(); - const thumbShow = ref(false); + const rootRef = shallowRef(); + const thumbShow = shallowRef(false); const segmentedOptions = computed(() => normalizeOptions(props.options)); const handleChange = (_event: ChangeEvent, val: SegmentedValue) => { diff --git a/components/table/hooks/useFilter/FilterDropdown.tsx b/components/table/hooks/useFilter/FilterDropdown.tsx index 476b434ba..3abc2402f 100644 --- a/components/table/hooks/useFilter/FilterDropdown.tsx +++ b/components/table/hooks/useFilter/FilterDropdown.tsx @@ -16,7 +16,7 @@ import type { import FilterDropdownMenuWrapper from './FilterWrapper'; import type { FilterState } from '.'; import { flattenKeys } from '.'; -import { computed, defineComponent, onBeforeUnmount, ref, shallowRef, watch } from 'vue'; +import { computed, defineComponent, onBeforeUnmount, shallowRef, watch } from 'vue'; import classNames from '../../../_util/classNames'; import useConfigInject from '../../../config-provider/hooks/useConfigInject'; import { useInjectSlots } from '../../context'; @@ -160,7 +160,7 @@ export default defineComponent>({ ); }); } - const visible = ref(false); + const visible = shallowRef(false); const filtered = computed( () => !!( @@ -227,7 +227,7 @@ export default defineComponent>({ // const onExpandChange = keys => (expandKeys.value = keys); const openKeys = shallowRef([]); - const openRef = ref(); + const openRef = shallowRef(); const onOpenChange = (keys: string[]) => { openRef.value = setTimeout(() => { @@ -242,7 +242,7 @@ export default defineComponent>({ clearTimeout(openRef.value); }); - const searchValue = ref(''); + const searchValue = shallowRef(''); const onSearch: EventHandler = e => { const { value } = e.target; searchValue.value = value; diff --git a/components/tabs/src/TabNavList/index.tsx b/components/tabs/src/TabNavList/index.tsx index 860aef00b..a9c7ceebd 100644 --- a/components/tabs/src/TabNavList/index.tsx +++ b/components/tabs/src/TabNavList/index.tsx @@ -19,7 +19,7 @@ import AddButton from './AddButton'; import type { Key } from '../../../_util/type'; import { objectType, functionType } from '../../../_util/type'; import type { ExtractPropTypes, PropType, CSSProperties } from 'vue'; -import { onBeforeUnmount, defineComponent, ref, watch, watchEffect, computed } from 'vue'; +import { shallowRef, onBeforeUnmount, defineComponent, watch, watchEffect, computed } from 'vue'; import PropTypes from '../../../_util/vue-types'; import useSyncState from '../hooks/useSyncState'; import useState from '../../../_util/hooks/useState'; @@ -73,10 +73,10 @@ export default defineComponent({ emits: ['tabClick', 'tabScroll'], setup(props, { attrs, slots }) { const { tabs, prefixCls } = useInjectTabs(); - const tabsWrapperRef = ref(); - const tabListRef = ref(); - const operationsRef = ref<{ $el: HTMLDivElement }>(); - const innerAddButtonRef = ref(); + const tabsWrapperRef = shallowRef(); + const tabListRef = shallowRef(); + const operationsRef = shallowRef<{ $el: HTMLDivElement }>(); + const innerAddButtonRef = shallowRef(); const [setRef, btnRefs] = useRefs(); const tabPositionTopOrBottom = computed( () => props.tabPosition === 'top' || props.tabPosition === 'bottom', @@ -105,8 +105,8 @@ export default defineComponent({ // ========================== Util ========================= const operationsHiddenClassName = computed(() => `${prefixCls.value}-nav-operations-hidden`); - const transformMin = ref(0); - const transformMax = ref(0); + const transformMin = shallowRef(0); + const transformMax = shallowRef(0); watchEffect(() => { if (!tabPositionTopOrBottom.value) { @@ -132,7 +132,7 @@ export default defineComponent({ }; // ========================= Mobile ======================== - const touchMovingRef = ref(); + const touchMovingRef = shallowRef(); const [lockAnimation, setLockAnimation] = useState(); const doLockAnimation = () => { @@ -226,8 +226,8 @@ export default defineComponent({ } }; - const visibleStart = ref(0); - const visibleEnd = ref(0); + const visibleStart = shallowRef(0); + const visibleEnd = shallowRef(0); watchEffect(() => { let unit: 'width' | 'height'; @@ -332,7 +332,7 @@ export default defineComponent({ const activeTabOffset = computed(() => tabOffsets.value.get(props.activeKey)); // Delay set ink style to avoid remove tab blink - const inkBarRafRef = ref(); + const inkBarRafRef = shallowRef(); const cleanInkBarRaf = () => { raf.cancel(inkBarRafRef.value); }; diff --git a/components/tabs/src/hooks/useRaf.ts b/components/tabs/src/hooks/useRaf.ts index 730d6bf54..39a026d46 100644 --- a/components/tabs/src/hooks/useRaf.ts +++ b/components/tabs/src/hooks/useRaf.ts @@ -1,10 +1,10 @@ import type { Ref } from 'vue'; -import { ref, onBeforeUnmount } from 'vue'; +import { shallowRef, onBeforeUnmount } from 'vue'; import raf from '../../../_util/raf'; export default function useRaf(callback: Callback) { - const rafRef = ref(); - const removedRef = ref(false); + const rafRef = shallowRef(); + const removedRef = shallowRef(false); function trigger(...args: any[]) { if (!removedRef.value) { @@ -28,8 +28,8 @@ type Callback = (ori: T) => T; export function useRafState( defaultState: T | (() => T), ): [Ref, (updater: Callback) => void] { - const batchRef = ref[]>([]); - const state: Ref = ref( + const batchRef = shallowRef[]>([]); + const state: Ref = shallowRef( typeof defaultState === 'function' ? (defaultState as any)() : defaultState, ); diff --git a/components/tag/index.tsx b/components/tag/index.tsx index bebe40270..d286c533c 100644 --- a/components/tag/index.tsx +++ b/components/tag/index.tsx @@ -1,5 +1,5 @@ import type { HTMLAttributes, App, PropType, ExtractPropTypes, Plugin, CSSProperties } from 'vue'; -import { ref, defineComponent, watchEffect, computed } from 'vue'; +import { shallowRef, defineComponent, watchEffect, computed } from 'vue'; import classNames from '../_util/classNames'; import PropTypes from '../_util/vue-types'; import CloseOutlined from '@ant-design/icons-vue/CloseOutlined'; @@ -45,7 +45,7 @@ const Tag = defineComponent({ const [wrapSSR, hashId] = useStyle(prefixCls); - const visible = ref(true); + const visible = shallowRef(true); // Warning for deprecated usage if (process.env.NODE_ENV !== 'production') { diff --git a/components/upload/UploadList/ListItem.tsx b/components/upload/UploadList/ListItem.tsx index 560b929e0..b7fcc2223 100644 --- a/components/upload/UploadList/ListItem.tsx +++ b/components/upload/UploadList/ListItem.tsx @@ -1,4 +1,4 @@ -import { computed, defineComponent, onBeforeUnmount, onMounted, ref, watch } from 'vue'; +import { computed, defineComponent, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'; import type { ExtractPropTypes, CSSProperties } from 'vue'; import EyeOutlined from '@ant-design/icons-vue/EyeOutlined'; import DeleteOutlined from '@ant-design/icons-vue/DeleteOutlined'; @@ -59,8 +59,8 @@ export default defineComponent({ inheritAttrs: false, props: listItemProps(), setup(props, { slots, attrs }) { - const showProgress = ref(false); - const progressRafRef = ref(); + const showProgress = shallowRef(false); + const progressRafRef = shallowRef(); onMounted(() => { progressRafRef.value = setTimeout(() => { showProgress.value = true; @@ -69,7 +69,7 @@ export default defineComponent({ onBeforeUnmount(() => { clearTimeout(progressRafRef.value); }); - const mergedStatus = ref(props.file?.status); + const mergedStatus = shallowRef(props.file?.status); watch( () => props.file?.status, status => { @@ -277,7 +277,7 @@ export default defineComponent({ ); return ( -
+
{itemRender ? itemRender({ originNode: item, diff --git a/components/upload/UploadList/index.tsx b/components/upload/UploadList/index.tsx index c1f2bba06..1768c479f 100644 --- a/components/upload/UploadList/index.tsx +++ b/components/upload/UploadList/index.tsx @@ -9,7 +9,14 @@ import type { ButtonProps } from '../../button'; import Button from '../../button'; import ListItem from './ListItem'; import type { HTMLAttributes } from 'vue'; -import { computed, defineComponent, getCurrentInstance, onMounted, ref, watchEffect } from 'vue'; +import { + computed, + defineComponent, + getCurrentInstance, + onMounted, + shallowRef, + watchEffect, +} from 'vue'; import { filterEmpty, initDefaultProps, isValidElement } from '../../_util/props-util'; import type { VueNode } from '../../_util/type'; import useConfigInject from '../../config-provider/hooks/useConfigInject'; @@ -38,7 +45,7 @@ export default defineComponent({ appendActionVisible: true, }), setup(props, { slots, expose }) { - const motionAppear = ref(false); + const motionAppear = shallowRef(false); const instance = getCurrentInstance(); onMounted(() => { motionAppear.value == true; diff --git a/components/vc-cascader/hooks/useSearchConfig.ts b/components/vc-cascader/hooks/useSearchConfig.ts index 950d29c00..742425187 100644 --- a/components/vc-cascader/hooks/useSearchConfig.ts +++ b/components/vc-cascader/hooks/useSearchConfig.ts @@ -1,11 +1,11 @@ import type { BaseCascaderProps, ShowSearchType } from '../Cascader'; import type { Ref } from 'vue'; -import { ref, watchEffect } from 'vue'; +import { ref, shallowRef, watchEffect } from 'vue'; import { warning } from '../../vc-util/warning'; // Convert `showSearch` to unique config export default function useSearchConfig(showSearch?: Ref) { - const mergedShowSearch = ref(false); + const mergedShowSearch = shallowRef(false); const mergedSearchConfig = ref({}); watchEffect(() => { if (!showSearch.value) { diff --git a/components/vc-dialog/Dialog.tsx b/components/vc-dialog/Dialog.tsx index 33ed64b27..7508f7d53 100644 --- a/components/vc-dialog/Dialog.tsx +++ b/components/vc-dialog/Dialog.tsx @@ -1,5 +1,5 @@ import type { PropType } from 'vue'; -import { defineComponent, onBeforeUnmount, ref, watch, watchEffect } from 'vue'; +import { defineComponent, onBeforeUnmount, shallowRef, watch, watchEffect } from 'vue'; import contains from '../vc-util/Dom/contains'; import type ScrollLocker from '../vc-util/Dom/scrollLocker'; import classNames from '../_util/classNames'; @@ -37,11 +37,11 @@ export default defineComponent({ }, ), setup(props, { attrs, slots }) { - const lastOutSideActiveElementRef = ref(); - const wrapperRef = ref(); - const contentRef = ref(); - const animatedVisible = ref(props.visible); - const ariaIdRef = ref(`vcDialogTitle${getUUID()}`); + const lastOutSideActiveElementRef = shallowRef(); + const wrapperRef = shallowRef(); + const contentRef = shallowRef(); + const animatedVisible = shallowRef(props.visible); + const ariaIdRef = shallowRef(`vcDialogTitle${getUUID()}`); // ========================= Events ========================= const onDialogVisibleChanged = (newVisible: boolean) => { @@ -76,8 +76,8 @@ export default defineComponent({ }; // >>> Content - const contentClickRef = ref(false); - const contentTimeoutRef = ref(); + const contentClickRef = shallowRef(false); + const contentTimeoutRef = shallowRef(); // We need record content click incase content popup out of dialog const onContentMouseDown: MouseEventHandler = () => { diff --git a/components/vc-drawer/src/DrawerChild.tsx b/components/vc-drawer/src/DrawerChild.tsx index 473fb69b6..1b9d4ef98 100644 --- a/components/vc-drawer/src/DrawerChild.tsx +++ b/components/vc-drawer/src/DrawerChild.tsx @@ -1,4 +1,12 @@ -import { Transition, defineComponent, onMounted, onUnmounted, nextTick, watch, ref } from 'vue'; +import { + Transition, + defineComponent, + onMounted, + onUnmounted, + nextTick, + watch, + shallowRef, +} from 'vue'; import classnames from '../../_util/classNames'; import KeyCode from '../../_util/KeyCode'; import omit from '../../_util/omit'; @@ -17,11 +25,11 @@ const DrawerChild = defineComponent({ props: drawerChildProps(), emits: ['close', 'handleClick', 'change'], setup(props, { emit, slots }) { - const contentWrapper = ref(); - const dom = ref(); - const maskDom = ref(); - const handlerDom = ref(); - const contentDom = ref(); + const contentWrapper = shallowRef(); + const dom = shallowRef(); + const maskDom = shallowRef(); + const handlerDom = shallowRef(); + const contentDom = shallowRef(); let levelDom = []; const drawerId = `drawer_id_${Number( (Date.now() + Math.random()) @@ -151,7 +159,7 @@ const DrawerChild = defineComponent({ emit('handleClick', e); }; - const canOpen = ref(false); + const canOpen = shallowRef(false); watch(dom, () => { nextTick(() => { canOpen.value = true; diff --git a/components/vc-image/src/Preview.tsx b/components/vc-image/src/Preview.tsx index cfccdb270..94d6dd7d0 100644 --- a/components/vc-image/src/Preview.tsx +++ b/components/vc-image/src/Preview.tsx @@ -4,7 +4,7 @@ import { onMounted, onUnmounted, reactive, - ref, + shallowRef, watch, cloneVNode, } from 'vue'; @@ -62,15 +62,15 @@ const Preview = defineComponent({ setup(props, { emit, attrs }) { const { rotateLeft, rotateRight, zoomIn, zoomOut, close, left, right } = reactive(props.icons); - const scale = ref(1); - const rotate = ref(0); + const scale = shallowRef(1); + const rotate = shallowRef(0); const [position, setPosition] = useFrameSetState<{ x: number; y: number; }>(initialPosition); const onClose = () => emit('close'); - const imgRef = ref(); + const imgRef = shallowRef(); const originPositionRef = reactive<{ originX: number; originY: number; @@ -82,7 +82,7 @@ const Preview = defineComponent({ deltaX: 0, deltaY: 0, }); - const isMoving = ref(false); + const isMoving = shallowRef(false); const groupContext = context.inject(); const { previewUrls, current, isPreviewGroup, setCurrent } = groupContext; const previewGroupCount = computed(() => previewUrls.value.size); @@ -94,7 +94,7 @@ const Preview = defineComponent({ const showLeftOrRightSwitches = computed( () => isPreviewGroup.value && previewGroupCount.value > 1, ); - const lastWheelZoomDirection = ref({ wheelDirection: 0 }); + const lastWheelZoomDirection = shallowRef({ wheelDirection: 0 }); const onAfterClose = () => { scale.value = 1; diff --git a/components/vc-image/src/PreviewGroup.tsx b/components/vc-image/src/PreviewGroup.tsx index 0a1eeb8dd..2e5fd26fe 100644 --- a/components/vc-image/src/PreviewGroup.tsx +++ b/components/vc-image/src/PreviewGroup.tsx @@ -1,5 +1,15 @@ import type { PropType, Ref, ComputedRef } from 'vue'; -import { ref, provide, defineComponent, inject, watch, reactive, computed, watchEffect } from 'vue'; +import { + ref, + shallowRef, + provide, + defineComponent, + inject, + watch, + reactive, + computed, + watchEffect, +} from 'vue'; import { type ImagePreviewType, mergeDefaultValue } from './Image'; import Preview from './Preview'; import type { PreviewProps } from './Preview'; @@ -43,7 +53,7 @@ export const context = { }, inject: () => { return inject(previewGroupContext, { - isPreviewGroup: ref(false), + isPreviewGroup: shallowRef(false), previewUrls: computed(() => new Map()), setPreviewUrls: () => {}, current: ref(null), @@ -161,7 +171,7 @@ const Group = defineComponent({ ); context.provide({ - isPreviewGroup: ref(true), + isPreviewGroup: shallowRef(true), previewUrls: canPreviewUrls, setPreviewUrls, current, diff --git a/components/vc-input/Input.tsx b/components/vc-input/Input.tsx index 97f790fb4..0028bca65 100644 --- a/components/vc-input/Input.tsx +++ b/components/vc-input/Input.tsx @@ -5,7 +5,7 @@ import { defineComponent, getCurrentInstance, nextTick, - ref, + shallowRef, watch, withDirectives, } from 'vue'; @@ -30,9 +30,9 @@ export default defineComponent({ inheritAttrs: false, props: inputProps(), setup(props, { slots, attrs, expose, emit }) { - const stateValue = ref(props.value === undefined ? props.defaultValue : props.value); - const focused = ref(false); - const inputRef = ref(); + const stateValue = shallowRef(props.value === undefined ? props.defaultValue : props.value); + const focused = shallowRef(false); + const inputRef = shallowRef(); watch( () => props.value, () => { diff --git a/components/vc-mentions/src/DropdownMenu.tsx b/components/vc-mentions/src/DropdownMenu.tsx index b254b7ee2..860235248 100644 --- a/components/vc-mentions/src/DropdownMenu.tsx +++ b/components/vc-mentions/src/DropdownMenu.tsx @@ -1,6 +1,6 @@ import Menu, { Item as MenuItem } from '../../menu'; import type { PropType } from 'vue'; -import { onBeforeUnmount, defineComponent, inject, ref } from 'vue'; +import { onBeforeUnmount, defineComponent, inject, shallowRef } from 'vue'; import type { OptionProps } from './Option'; import MentionsContextKey from './MentionsContext'; import Spin from '../../spin'; @@ -25,8 +25,8 @@ export default defineComponent({ onFocus = noop, loading, } = inject(MentionsContextKey, { - activeIndex: ref(), - loading: ref(false), + activeIndex: shallowRef(), + loading: shallowRef(false), }); let timeoutId: any; const onMousedown = (e: MouseEvent) => { diff --git a/components/vc-overflow/Overflow.tsx b/components/vc-overflow/Overflow.tsx index c7e18b09d..ac5445608 100644 --- a/components/vc-overflow/Overflow.tsx +++ b/components/vc-overflow/Overflow.tsx @@ -1,5 +1,5 @@ import type { CSSProperties, ExtractPropTypes, HTMLAttributes, PropType } from 'vue'; -import { computed, defineComponent, ref, watch } from 'vue'; +import { computed, defineComponent, shallowRef, watch } from 'vue'; import ResizeObserver from '../vc-resize-observer'; import classNames from '../_util/classNames'; import type { MouseEventHandler } from '../_util/EventInterface'; @@ -51,14 +51,14 @@ const Overflow = defineComponent({ setup(props, { attrs, emit, slots }) { const fullySSR = computed(() => props.ssr === 'full'); - const containerWidth = ref(null); + const containerWidth = shallowRef(null); const mergedContainerWidth = computed(() => containerWidth.value || 0); - const itemWidths = ref>(new Map()); - const prevRestWidth = ref(0); - const restWidth = ref(0); - const suffixWidth = ref(0); - const suffixFixedStart = ref(null); - const displayCount = ref(null); + const itemWidths = shallowRef>(new Map()); + const prevRestWidth = shallowRef(0); + const restWidth = shallowRef(0); + const suffixWidth = shallowRef(0); + const suffixFixedStart = shallowRef(null); + const displayCount = shallowRef(null); const mergedDisplayCount = computed(() => { if (displayCount.value === null && fullySSR.value) { @@ -68,7 +68,7 @@ const Overflow = defineComponent({ return displayCount.value || 0; }); - const restReady = ref(false); + const restReady = shallowRef(false); const itemPrefixCls = computed(() => `${props.prefixCls}-item`); diff --git a/components/vc-picker/hooks/usePickerInput.ts b/components/vc-picker/hooks/usePickerInput.ts index 80b616f40..9cf0cdefe 100644 --- a/components/vc-picker/hooks/usePickerInput.ts +++ b/components/vc-picker/hooks/usePickerInput.ts @@ -1,5 +1,5 @@ import type { ComputedRef, HTMLAttributes, Ref } from 'vue'; -import { onBeforeUnmount, onMounted, watch, ref, computed } from 'vue'; +import { onBeforeUnmount, onMounted, watch, shallowRef, computed } from 'vue'; import type { FocusEventHandler } from '../../_util/EventInterface'; import KeyCode from '../../_util/KeyCode'; import { addGlobalMousedownEvent, getTargetFromEvent } from '../utils/uiUtil'; @@ -30,18 +30,18 @@ export default function usePickerInput({ onFocus?: FocusEventHandler; onBlur?: FocusEventHandler; }): [ComputedRef, { focused: Ref; typing: Ref }] { - const typing = ref(false); - const focused = ref(false); + const typing = shallowRef(false); + const focused = shallowRef(false); /** * We will prevent blur to handle open event when user click outside, * since this will repeat trigger `onOpenChange` event. */ - const preventBlurRef = ref(false); + const preventBlurRef = shallowRef(false); - const valueChangedRef = ref(false); + const valueChangedRef = shallowRef(false); - const preventDefaultRef = ref(false); + const preventDefaultRef = shallowRef(false); const inputProps = computed(() => ({ onMousedown: () => { @@ -146,7 +146,7 @@ export default function usePickerInput({ watch(value, () => { valueChangedRef.value = true; }); - const globalMousedownEvent = ref(); + const globalMousedownEvent = shallowRef(); // Global click handler onMounted(() => { globalMousedownEvent.value = addGlobalMousedownEvent((e: MouseEvent) => { diff --git a/components/vc-select/BaseSelect.tsx b/components/vc-select/BaseSelect.tsx index ad87e4976..47fbb9f42 100644 --- a/components/vc-select/BaseSelect.tsx +++ b/components/vc-select/BaseSelect.tsx @@ -23,7 +23,7 @@ import { onBeforeUnmount, onMounted, provide, - ref, + shallowRef, toRefs, watch, watchEffect, @@ -269,17 +269,17 @@ export default defineComponent({ ? props.showSearch : multiple.value || props.mode === 'combobox', ); - const mobile = ref(false); + const mobile = shallowRef(false); onMounted(() => { mobile.value = isMobile(); }); const legacyTreeSelectContext = useInjectLegacySelectContext(); // ============================== Refs ============================== - const containerRef = ref(null); + const containerRef = shallowRef(null); const selectorDomRef = createRef(); - const triggerRef = ref(null); - const selectorRef = ref(null); - const listRef = ref(null); + const triggerRef = shallowRef(null); + const selectorRef = shallowRef(null); + const listRef = shallowRef(null); /** Used for component focused management */ const [mockFocused, setMockFocused, cancelSetMockFocused] = useDelayReset(); @@ -308,8 +308,8 @@ export default defineComponent({ // ============================== Open ============================== const initOpen = props.open !== undefined ? props.open : props.defaultOpen; - const innerOpen = ref(initOpen); - const mergedOpen = ref(initOpen); + const innerOpen = shallowRef(initOpen); + const mergedOpen = shallowRef(initOpen); const setInnerOpen = (val: boolean) => { innerOpen.value = props.open !== undefined ? props.open : val; mergedOpen.value = innerOpen.value; @@ -504,7 +504,7 @@ export default defineComponent({ // ========================== Focus / Blur ========================== /** Record real focus status */ - const focusRef = ref(false); + const focusRef = shallowRef(false); const onContainerFocus: FocusEventHandler = (...args) => { setMockFocused(true); @@ -592,7 +592,7 @@ export default defineComponent({ }; // ============================= Dropdown ============================== - const containerWidth = ref(null); + const containerWidth = shallowRef(null); const instance = getCurrentInstance(); const onPopupMouseEnter = () => { // We need force update here since popup dom is render async diff --git a/components/vc-select/Selector/MultipleSelector.tsx b/components/vc-select/Selector/MultipleSelector.tsx index 62c16675f..8daad360d 100644 --- a/components/vc-select/Selector/MultipleSelector.tsx +++ b/components/vc-select/Selector/MultipleSelector.tsx @@ -2,7 +2,7 @@ import TransBtn from '../TransBtn'; import type { InnerSelectorProps } from './interface'; import Input from './Input'; import type { Ref, PropType } from 'vue'; -import { computed, defineComponent, onMounted, ref, watch } from 'vue'; +import { computed, defineComponent, onMounted, shallowRef, watch } from 'vue'; import classNames from '../../_util/classNames'; import pickAttrs from '../../_util/pickAttrs'; import PropTypes from '../../_util/vue-types'; @@ -77,9 +77,9 @@ const SelectSelector = defineComponent({ inheritAttrs: false, props: props as any, setup(props) { - const measureRef = ref(); - const inputWidth = ref(0); - const focused = ref(false); + const measureRef = shallowRef(); + const inputWidth = shallowRef(0); + const focused = shallowRef(false); const legacyTreeSelectContext = useInjectLegacySelectContext(); const selectionPrefixCls = computed(() => `${props.prefixCls}-selection`); diff --git a/components/vc-select/Selector/SingleSelector.tsx b/components/vc-select/Selector/SingleSelector.tsx index 1fbed2373..c4eaa7464 100644 --- a/components/vc-select/Selector/SingleSelector.tsx +++ b/components/vc-select/Selector/SingleSelector.tsx @@ -1,7 +1,7 @@ import pickAttrs from '../../_util/pickAttrs'; import Input from './Input'; import type { InnerSelectorProps } from './interface'; -import { Fragment, computed, defineComponent, ref, watch } from 'vue'; +import { Fragment, computed, defineComponent, shallowRef, watch } from 'vue'; import PropTypes from '../../_util/vue-types'; import type { VueNode } from '../../_util/type'; import useInjectLegacySelectContext from '../../vc-tree-select/LegacyContext'; @@ -40,7 +40,7 @@ const props = { const SingleSelector = defineComponent({ name: 'SingleSelector', setup(props) { - const inputChanged = ref(false); + const inputChanged = shallowRef(false); const combobox = computed(() => props.mode === 'combobox'); const inputEditable = computed(() => combobox.value || props.showSearch); diff --git a/components/vc-select/hooks/useDelayReset.ts b/components/vc-select/hooks/useDelayReset.ts index ff1e0fcbc..3c0ec3001 100644 --- a/components/vc-select/hooks/useDelayReset.ts +++ b/components/vc-select/hooks/useDelayReset.ts @@ -1,5 +1,5 @@ import type { Ref } from 'vue'; -import { onMounted, ref } from 'vue'; +import { onMounted, shallowRef } from 'vue'; /** * Similar with `useLock`, but this hook will always execute last value. @@ -8,7 +8,7 @@ import { onMounted, ref } from 'vue'; export default function useDelayReset( timeout = 10, ): [Ref, (val: boolean, callback?: () => void) => void, () => void] { - const bool = ref(false); + const bool = shallowRef(false); let delay: any; const cancelLatest = () => { diff --git a/components/vc-slider/src/Handle.tsx b/components/vc-slider/src/Handle.tsx index 1bf6b6516..dc4e580af 100644 --- a/components/vc-slider/src/Handle.tsx +++ b/components/vc-slider/src/Handle.tsx @@ -1,5 +1,5 @@ import type { CSSProperties, PropType } from 'vue'; -import { computed, defineComponent, ref, onMounted, onBeforeUnmount } from 'vue'; +import { computed, defineComponent, shallowRef, onMounted, onBeforeUnmount } from 'vue'; import classNames from '../../_util/classNames'; import PropTypes from '../../_util/vue-types'; import addEventListener from '../../vc-util/Dom/addEventListener'; @@ -26,8 +26,8 @@ export default defineComponent({ onMousedown: { type: Function as PropType<(payload: MouseEvent) => void> }, }, setup(props, { attrs, emit, expose }) { - const clickFocused = ref(false); - const handle = ref(); + const clickFocused = shallowRef(false); + const handle = shallowRef(); const handleMouseUp = () => { if (document.activeElement === handle.value) { clickFocused.value = true; diff --git a/components/vc-table/Body/BodyRow.tsx b/components/vc-table/Body/BodyRow.tsx index 584166659..3691b7b42 100644 --- a/components/vc-table/Body/BodyRow.tsx +++ b/components/vc-table/Body/BodyRow.tsx @@ -2,7 +2,7 @@ import Cell from '../Cell'; import { getColumnsKey } from '../utils/valueUtil'; import type { CustomizeComponent, GetComponentProps, Key, GetRowKey } from '../interface'; import ExpandedRow from './ExpandedRow'; -import { computed, defineComponent, ref, watchEffect } from 'vue'; +import { computed, defineComponent, shallowRef, watchEffect } from 'vue'; import { useInjectTable } from '../context/TableContext'; import { useInjectBody } from '../context/BodyContext'; import classNames from '../../_util/classNames'; @@ -45,7 +45,7 @@ export default defineComponent>({ setup(props, { attrs }) { const tableContext = useInjectTable(); const bodyContext = useInjectBody(); - const expandRended = ref(false); + const expandRended = shallowRef(false); const expanded = computed(() => props.expandedKeys && props.expandedKeys.has(props.recordKey)); diff --git a/components/vc-table/Body/index.tsx b/components/vc-table/Body/index.tsx index 849935413..f1eec769a 100644 --- a/components/vc-table/Body/index.tsx +++ b/components/vc-table/Body/index.tsx @@ -5,7 +5,7 @@ import { getColumnsKey } from '../utils/valueUtil'; import MeasureCell from './MeasureCell'; import BodyRow from './BodyRow'; import useFlattenRecords from '../hooks/useFlattenRecords'; -import { defineComponent, ref, toRef } from 'vue'; +import { defineComponent, shallowRef, toRef } from 'vue'; import { useInjectResize } from '../context/ResizeContext'; import { useInjectTable } from '../context/TableContext'; import { useInjectBody } from '../context/BodyContext'; @@ -44,8 +44,8 @@ export default defineComponent>({ toRef(props, 'expandedKeys'), toRef(props, 'getRowKey'), ); - const startRow = ref(-1); - const endRow = ref(-1); + const startRow = shallowRef(-1); + const endRow = shallowRef(-1); let timeoutId: any; useProvideHover({ startRow, diff --git a/components/vc-table/Header/DragHandle.tsx b/components/vc-table/Header/DragHandle.tsx index 713a8260a..f280e2040 100644 --- a/components/vc-table/Header/DragHandle.tsx +++ b/components/vc-table/Header/DragHandle.tsx @@ -1,7 +1,14 @@ import addEventListenerWrap from '../../vc-util/Dom/addEventListener'; import type { EventHandler } from '../../_util/EventInterface'; import raf from '../../_util/raf'; -import { defineComponent, onUnmounted, computed, ref, watchEffect, getCurrentInstance } from 'vue'; +import { + defineComponent, + onUnmounted, + computed, + shallowRef, + watchEffect, + getCurrentInstance, +} from 'vue'; import type { PropType } from 'vue'; import devWarning from '../../vc-util/devWarning'; import type { ColumnType } from '../interface'; @@ -73,7 +80,7 @@ export default defineComponent({ }); const instance = getCurrentInstance(); let baseWidth = 0; - const dragging = ref(false); + const dragging = shallowRef(false); let rafId: number; const updateWidth = (e: HandleEvent) => { let pageX = 0; diff --git a/components/vc-table/context/HoverContext.tsx b/components/vc-table/context/HoverContext.tsx index fbb66f423..97ccf94cc 100644 --- a/components/vc-table/context/HoverContext.tsx +++ b/components/vc-table/context/HoverContext.tsx @@ -1,5 +1,5 @@ import type { InjectionKey, Ref } from 'vue'; -import { ref, inject, provide } from 'vue'; +import { shallowRef, inject, provide } from 'vue'; export interface HoverContextProps { startRow: Ref; @@ -14,8 +14,8 @@ export const useProvideHover = (props: HoverContextProps) => { export const useInjectHover = () => { return inject(HoverContextKey, { - startRow: ref(-1), - endRow: ref(-1), + startRow: shallowRef(-1), + endRow: shallowRef(-1), onHover() {}, } as HoverContextProps); }; diff --git a/components/vc-table/context/StickyContext.tsx b/components/vc-table/context/StickyContext.tsx index 63e202d55..42717f1ed 100644 --- a/components/vc-table/context/StickyContext.tsx +++ b/components/vc-table/context/StickyContext.tsx @@ -1,7 +1,7 @@ import isStyleSupport from '../../_util/styleChecker'; -import { onMounted, ref } from 'vue'; +import { onMounted, shallowRef } from 'vue'; -const supportSticky = ref(false); +const supportSticky = shallowRef(false); export const useProvideSticky = () => { onMounted(() => { supportSticky.value = supportSticky.value || isStyleSupport('position', 'sticky'); diff --git a/components/vc-table/stickyScrollBar.tsx b/components/vc-table/stickyScrollBar.tsx index 4f3967c78..a3ec1502b 100644 --- a/components/vc-table/stickyScrollBar.tsx +++ b/components/vc-table/stickyScrollBar.tsx @@ -7,6 +7,7 @@ import { onBeforeUnmount, onMounted, ref, + shallowRef, watch, } from 'vue'; import addEventListenerWrap from '../vc-util/Dom/addEventListener'; @@ -35,9 +36,9 @@ export default defineComponent({ emits: ['scroll'], setup(props, { emit, expose }) { const tableContext = useInjectTable(); - const bodyScrollWidth = ref(0); - const bodyWidth = ref(0); - const scrollBarWidth = ref(0); + const bodyScrollWidth = shallowRef(0); + const bodyWidth = shallowRef(0); + const scrollBarWidth = shallowRef(0); watchEffect( () => { bodyScrollWidth.value = props.scrollBodySizeInfo.scrollWidth || 0; @@ -48,7 +49,7 @@ export default defineComponent({ { flush: 'post' }, ); - const scrollBarRef = ref(); + const scrollBarRef = shallowRef(); const [scrollState, setScrollState] = useLayoutState({ scrollLeft: 0, @@ -60,7 +61,7 @@ export default defineComponent({ x: 0, }); - const isActive = ref(false); + const isActive = shallowRef(false); const onMouseUp: MouseEventHandler = () => { isActive.value = false; diff --git a/components/vc-tooltip/src/Tooltip.tsx b/components/vc-tooltip/src/Tooltip.tsx index 0339b2cc5..8b38754de 100644 --- a/components/vc-tooltip/src/Tooltip.tsx +++ b/components/vc-tooltip/src/Tooltip.tsx @@ -4,7 +4,7 @@ import { placements } from './placements'; import Content from './Content'; import { getPropsSlot } from '../../_util/props-util'; import type { CSSProperties, PropType } from 'vue'; -import { defineComponent, ref, watchEffect } from 'vue'; +import { defineComponent, shallowRef, watchEffect } from 'vue'; function noop() {} export default defineComponent({ compatConfig: { MODE: 3 }, @@ -39,7 +39,7 @@ export default defineComponent({ }, slots: ['arrowContent', 'overlay'], setup(props, { slots, attrs, expose }) { - const triggerDOM = ref(); + const triggerDOM = shallowRef(); const getPopupElement = () => { const { prefixCls, tipId, overlayInnerStyle } = props; @@ -67,8 +67,8 @@ export default defineComponent({ forcePopupAlign: () => triggerDOM.value?.forcePopupAlign(), }); - const destroyTooltip = ref(false); - const autoDestroy = ref(false); + const destroyTooltip = shallowRef(false); + const autoDestroy = shallowRef(false); watchEffect(() => { const { destroyTooltipOnHide } = props; if (typeof destroyTooltipOnHide === 'boolean') { diff --git a/components/vc-tree/MotionTreeNode.tsx b/components/vc-tree/MotionTreeNode.tsx index b2503919c..d3d9faa20 100644 --- a/components/vc-tree/MotionTreeNode.tsx +++ b/components/vc-tree/MotionTreeNode.tsx @@ -8,7 +8,7 @@ import { defineComponent, onBeforeUnmount, onMounted, - ref, + shallowRef, Transition, watch, } from 'vue'; @@ -31,9 +31,9 @@ export default defineComponent({ }, slots: ['title', 'icon', 'switcherIcon', 'checkable'], setup(props, { attrs, slots }) { - const visible = ref(true); + const visible = shallowRef(true); const context = useInjectTreeContext(); - const motionedRef = ref(false); + const motionedRef = shallowRef(false); const transitionProps = computed(() => { if (props.motion) { return props.motion; @@ -113,7 +113,6 @@ export default defineComponent({ return ( = {}; - const indent = ref(); + const indent = shallowRef(); const selectedKeys = shallowRef([]); const checkedKeys = shallowRef([]); const halfCheckedKeys = shallowRef([]); @@ -122,14 +121,14 @@ export default defineComponent({ ); const keyEntities = shallowRef({}); - const focused = ref(false); - const activeKey = ref(null); + const focused = shallowRef(false); + const activeKey = shallowRef(null); - const listChanging = ref(false); + const listChanging = shallowRef(false); const fieldNames = computed(() => fillFieldNames(props.fieldNames)); - const listRef = ref(); + const listRef = shallowRef(); let dragStartMousePosition = null; diff --git a/components/vc-tree/TreeNode.tsx b/components/vc-tree/TreeNode.tsx index ec78ebdb7..a0345b035 100644 --- a/components/vc-tree/TreeNode.tsx +++ b/components/vc-tree/TreeNode.tsx @@ -9,7 +9,7 @@ import { onMounted, onUpdated, reactive, - ref, + shallowRef, } from 'vue'; import { treeNodeProps } from './props'; import classNames from '../_util/classNames'; @@ -38,7 +38,7 @@ export default defineComponent({ )}instead`, ); - const dragNodeHighlight = ref(false); + const dragNodeHighlight = shallowRef(false); const context = useInjectTreeContext(); const { expandedKeysSet, @@ -74,7 +74,7 @@ export default defineComponent({ const dragOverGapBottom = eagerComputed(() => mergedTreeNodeProps.value.dragOverGapBottom); const pos = eagerComputed(() => mergedTreeNodeProps.value.pos); - const selectHandle = ref(); + const selectHandle = shallowRef(); const hasChildren = computed(() => { const { eventKey } = props; diff --git a/components/vc-trigger/Popup/PopupInner.tsx b/components/vc-trigger/Popup/PopupInner.tsx index 71c91291e..5699785f8 100644 --- a/components/vc-trigger/Popup/PopupInner.tsx +++ b/components/vc-trigger/Popup/PopupInner.tsx @@ -2,7 +2,15 @@ import type { AlignType } from '../interface'; import useVisibleStatus from './useVisibleStatus'; import useStretchStyle from './useStretchStyle'; import type { CSSProperties } from 'vue'; -import { computed, defineComponent, ref, toRef, Transition, watch, withModifiers } from 'vue'; +import { + computed, + defineComponent, + shallowRef, + toRef, + Transition, + watch, + withModifiers, +} from 'vue'; import type { RefAlign } from '../../vc-align/Align'; import Align from '../../vc-align/Align'; import { getMotion } from '../utils/motionUtil'; @@ -20,9 +28,9 @@ export default defineComponent({ props: innerProps, emits: ['mouseenter', 'mouseleave', 'mousedown', 'touchstart', 'align'], setup(props, { expose, attrs, slots }) { - const alignRef = ref(); - const elementRef = ref(); - const alignedClassName = ref(); + const alignRef = shallowRef(); + const elementRef = shallowRef(); + const alignedClassName = shallowRef(); // ======================= Measure ======================== const [stretchStyle, measureStretchStyle] = useStretchStyle(toRef(props, 'stretch')); @@ -31,7 +39,7 @@ export default defineComponent({ measureStretchStyle(props.getRootDomNode()); } }; - const visible = ref(false); + const visible = shallowRef(false); let timeoutId: any; watch( () => props.visible, @@ -52,7 +60,7 @@ export default defineComponent({ const [status, goNextStatus] = useVisibleStatus(visible, doMeasure); // ======================== Aligns ======================== - const prepareResolveRef = ref<(value?: unknown) => void>(); + const prepareResolveRef = shallowRef<(value?: unknown) => void>(); // `target` on `rc-align` can accept as a function to get the bind element or a point. // ref: https://www.npmjs.com/package/rc-align diff --git a/components/vc-trigger/Popup/index.tsx b/components/vc-trigger/Popup/index.tsx index bbd383507..58002248c 100644 --- a/components/vc-trigger/Popup/index.tsx +++ b/components/vc-trigger/Popup/index.tsx @@ -1,4 +1,4 @@ -import { defineComponent, ref, watch } from 'vue'; +import { defineComponent, shallowRef, watch } from 'vue'; import { popupProps } from './interface'; import Mask from './Mask'; import MobilePopupInner from './MobilePopupInner'; @@ -10,9 +10,9 @@ export default defineComponent({ inheritAttrs: false, props: popupProps, setup(props, { attrs, slots, expose }) { - const innerVisible = ref(false); - const inMobile = ref(false); - const popupRef = ref(); + const innerVisible = shallowRef(false); + const inMobile = shallowRef(false); + const popupRef = shallowRef(); watch( [() => props.visible, () => props.mobile], () => { diff --git a/components/vc-trigger/Popup/useStretchStyle.ts b/components/vc-trigger/Popup/useStretchStyle.ts index c808ced27..7a28801dd 100644 --- a/components/vc-trigger/Popup/useStretchStyle.ts +++ b/components/vc-trigger/Popup/useStretchStyle.ts @@ -1,11 +1,11 @@ import type { ComputedRef, CSSProperties, Ref } from 'vue'; -import { computed, ref } from 'vue'; +import { computed, shallowRef } from 'vue'; import type { StretchType } from '../interface'; export default ( stretch?: Ref, ): [ComputedRef, (element: HTMLElement) => void] => { - const targetSize = ref({ width: 0, height: 0 }); + const targetSize = shallowRef({ width: 0, height: 0 }); function measureStretch(element: HTMLElement) { targetSize.value = { diff --git a/components/vc-trigger/Popup/useVisibleStatus.ts b/components/vc-trigger/Popup/useVisibleStatus.ts index 799ae2edd..f30d81953 100644 --- a/components/vc-trigger/Popup/useVisibleStatus.ts +++ b/components/vc-trigger/Popup/useVisibleStatus.ts @@ -1,5 +1,5 @@ import type { Ref } from 'vue'; -import { onBeforeUnmount, ref, watch, onMounted } from 'vue'; +import { onBeforeUnmount, shallowRef, watch, onMounted } from 'vue'; import raf from '../../_util/raf'; /** @@ -22,9 +22,9 @@ export default ( visible: Ref, doMeasure: Func, ): [Ref, (callback?: () => void) => void] => { - const status = ref(null); - const rafRef = ref(); - const destroyRef = ref(false); + const status = shallowRef(null); + const rafRef = shallowRef(); + const destroyRef = shallowRef(false); function setStatus(nextStatus: PopupStatus) { if (!destroyRef.value) { status.value = nextStatus; diff --git a/components/vc-trigger/Trigger.tsx b/components/vc-trigger/Trigger.tsx index a593fbba8..e11af9a0e 100644 --- a/components/vc-trigger/Trigger.tsx +++ b/components/vc-trigger/Trigger.tsx @@ -1,5 +1,5 @@ import type { CSSProperties, HTMLAttributes, PropType } from 'vue'; -import { computed, defineComponent, inject, provide, ref } from 'vue'; +import { computed, defineComponent, inject, provide, shallowRef } from 'vue'; import PropTypes from '../_util/vue-types'; import contains from '../vc-util/Dom/contains'; import raf from '../_util/raf'; @@ -98,7 +98,7 @@ export default defineComponent({ return popupAlign; }); const { setPortal, popPortal } = useInjectTrigger(props.tryPopPortal); - const popupRef = ref(null); + const popupRef = shallowRef(null); const setPopupRef = val => { popupRef.value = val; }; @@ -111,7 +111,7 @@ export default defineComponent({ ), popupRef, setPopupRef, - triggerRef: ref(null), + triggerRef: shallowRef(null), align, focusTime: null, clickOutsideHandler: null, diff --git a/components/vc-virtual-list/List.tsx b/components/vc-virtual-list/List.tsx index f234077ed..94a0e4216 100644 --- a/components/vc-virtual-list/List.tsx +++ b/components/vc-virtual-list/List.tsx @@ -4,7 +4,6 @@ import { toRaw, onMounted, onUpdated, - ref, defineComponent, watchEffect, computed, @@ -140,9 +139,9 @@ const List = defineComponent({ }, { immediate: true }, ); - const componentRef = ref(); - const fillerInnerRef = ref(); - const scrollBarRef = ref(); // Hack on scrollbar to enable flash call + const componentRef = shallowRef(); + const fillerInnerRef = shallowRef(); + const scrollBarRef = shallowRef(); // Hack on scrollbar to enable flash call // =============================== Item Key =============================== const getKey = (item: Record) => { return itemKey.value(item); @@ -189,7 +188,7 @@ const List = defineComponent({ offset: undefined, }); - const offsetHeight = ref(0); + const offsetHeight = shallowRef(0); onMounted(() => { nextTick(() => { offsetHeight.value = fillerInnerRef.value?.offsetHeight || 0;