Skip to content

Commit d7f9bd2

Browse files
committed
fix: support vue 3.4
1 parent 4ed2868 commit d7f9bd2

File tree

6 files changed

+36
-30
lines changed

6 files changed

+36
-30
lines changed

components/_util/PortalWrapper.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
onMounted,
88
onBeforeUnmount,
99
onUpdated,
10-
getCurrentInstance,
1110
nextTick,
1211
computed,
1312
} from 'vue';
@@ -61,6 +60,7 @@ export default defineComponent({
6160
const container = shallowRef<HTMLElement>();
6261
const componentRef = shallowRef();
6362
const rafId = shallowRef<number>();
63+
const triggerUpdate = shallowRef(1);
6464
const defaultContainer = canUseDom() && document.createElement('div');
6565
const removeCurrentContainer = () => {
6666
// Portal will remove from `parentNode`.
@@ -106,8 +106,6 @@ export default defineComponent({
106106
attachToParent();
107107
});
108108

109-
const instance = getCurrentInstance();
110-
111109
useScrollLocker(
112110
computed(() => {
113111
return (
@@ -155,7 +153,7 @@ export default defineComponent({
155153
nextTick(() => {
156154
if (!attachToParent()) {
157155
rafId.value = raf(() => {
158-
instance.update();
156+
triggerUpdate.value += 1;
159157
});
160158
}
161159
});
@@ -177,7 +175,7 @@ export default defineComponent({
177175
getOpenCount: () => openCount,
178176
getContainer,
179177
};
180-
if (forceRender || visible || componentRef.value) {
178+
if (triggerUpdate.value && (forceRender || visible || componentRef.value)) {
181179
portal = (
182180
<Portal
183181
getContainer={getContainer}

components/affix/index.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ const Affix = defineComponent({
176176
affixStyle: undefined,
177177
placeholderStyle: undefined,
178178
});
179-
currentInstance.update();
180179
// Test if `updatePosition` called
181180
if (process.env.NODE_ENV === 'test') {
182181
emit('testUpdatePosition');
@@ -256,7 +255,7 @@ const Affix = defineComponent({
256255
const { prefixCls } = useConfigInject('affix', props);
257256
const [wrapSSR, hashId] = useStyle(prefixCls);
258257
return () => {
259-
const { affixStyle, placeholderStyle } = state;
258+
const { affixStyle, placeholderStyle, status } = state;
260259
const className = classNames({
261260
[prefixCls.value]: affixStyle,
262261
[hashId.value]: true,
@@ -271,7 +270,7 @@ const Affix = defineComponent({
271270
]);
272271
return wrapSSR(
273272
<ResizeObserver onResize={updatePosition}>
274-
<div {...restProps} {...attrs} ref={placeholderNode}>
273+
<div {...restProps} {...attrs} ref={placeholderNode} data-measure-status={status}>
275274
{affixStyle && <div style={placeholderStyle} aria-hidden="true" />}
276275
<div class={className} ref={fixedNode} style={affixStyle}>
277276
{slots.default?.()}

components/modal/confirm.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const confirm = (config: ModalFuncProps) => {
2828
if (confirmDialogInstance) {
2929
// destroy
3030
vueRender(null, container as any);
31-
confirmDialogInstance.component.update();
3231
confirmDialogInstance = null;
3332
}
3433
const triggerCancel = args.some(param => param && param.triggerCancel);

components/upload/UploadList/index.tsx

+24-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import Button from '../../button';
1010
import ListItem from './ListItem';
1111
import type { HTMLAttributes } from 'vue';
1212
import {
13+
triggerRef,
14+
watch,
1315
computed,
1416
defineComponent,
15-
getCurrentInstance,
1617
onMounted,
1718
shallowRef,
1819
watchEffect,
@@ -46,15 +47,26 @@ export default defineComponent({
4647
}),
4748
setup(props, { slots, expose }) {
4849
const motionAppear = shallowRef(false);
49-
const instance = getCurrentInstance();
5050
onMounted(() => {
5151
motionAppear.value == true;
5252
});
53+
const mergedItems = shallowRef([]);
54+
watch(
55+
() => props.items,
56+
(val = []) => {
57+
mergedItems.value = val.slice();
58+
},
59+
{
60+
immediate: true,
61+
deep: true,
62+
},
63+
);
5364
watchEffect(() => {
5465
if (props.listType !== 'picture' && props.listType !== 'picture-card') {
5566
return;
5667
}
57-
(props.items || []).forEach((file: InternalUploadFile) => {
68+
let hasUpdate = false;
69+
(props.items || []).forEach((file: InternalUploadFile, index) => {
5870
if (
5971
typeof document === 'undefined' ||
6072
typeof window === 'undefined' ||
@@ -69,11 +81,17 @@ export default defineComponent({
6981
if (props.previewFile) {
7082
props.previewFile(file.originFileObj as File).then((previewDataUrl: string) => {
7183
// Need append '' to avoid dead loop
72-
file.thumbUrl = previewDataUrl || '';
73-
instance.update();
84+
const thumbUrl = previewDataUrl || '';
85+
if (thumbUrl !== file.thumbUrl) {
86+
mergedItems.value[index].thumbUrl = thumbUrl;
87+
hasUpdate = true;
88+
}
7489
});
7590
}
7691
});
92+
if (hasUpdate) {
93+
triggerRef(mergedItems);
94+
}
7795
});
7896

7997
// ============================= Events =============================
@@ -177,7 +195,6 @@ export default defineComponent({
177195
listType,
178196
locale,
179197
isImageUrl: isImgUrl,
180-
items = [],
181198
showPreviewIcon,
182199
showRemoveIcon,
183200
showDownloadIcon,
@@ -190,6 +207,7 @@ export default defineComponent({
190207
appendActionVisible,
191208
} = props;
192209
const appendActionDom = appendAction?.();
210+
const items = mergedItems.value;
193211
return (
194212
<TransitionGroup {...transitionGroupProps.value} tag="div">
195213
{items.map(file => {

components/vc-input/Input.tsx

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
// base 0.0.1-alpha.7
2-
import type { VNode } from 'vue';
3-
import {
4-
onMounted,
5-
defineComponent,
6-
getCurrentInstance,
7-
nextTick,
8-
shallowRef,
9-
watch,
10-
withDirectives,
11-
} from 'vue';
2+
import type { ComponentPublicInstance, VNode } from 'vue';
3+
import { onMounted, defineComponent, nextTick, shallowRef, watch, withDirectives } from 'vue';
124
import classNames from '../_util/classNames';
135
import type { ChangeEvent, FocusEventHandler } from '../_util/EventInterface';
146
import omit from '../_util/omit';
@@ -33,6 +25,7 @@ export default defineComponent({
3325
const stateValue = shallowRef(props.value === undefined ? props.defaultValue : props.value);
3426
const focused = shallowRef(false);
3527
const inputRef = shallowRef<HTMLInputElement>();
28+
const rootRef = shallowRef<ComponentPublicInstance>();
3629
watch(
3730
() => props.value,
3831
() => {
@@ -80,7 +73,6 @@ export default defineComponent({
8073
const triggerChange = (e: Event) => {
8174
emit('change', e);
8275
};
83-
const instance = getCurrentInstance();
8476
const setValue = (value: string | number, callback?: Function) => {
8577
if (stateValue.value === value) {
8678
return;
@@ -90,7 +82,7 @@ export default defineComponent({
9082
} else {
9183
nextTick(() => {
9284
if (inputRef.value.value !== stateValue.value) {
93-
instance.update();
85+
rootRef.value?.$forceUpdate();
9486
}
9587
});
9688
}
@@ -245,6 +237,7 @@ export default defineComponent({
245237
<BaseInput
246238
{...rest}
247239
{...attrs}
240+
ref={rootRef}
248241
prefixCls={prefixCls}
249242
inputElement={getInputElement()}
250243
handleReset={handleReset}

components/vc-select/BaseSelect.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import type { ScrollConfig, ScrollTo } from '../vc-virtual-list/List';
1919
import {
2020
computed,
2121
defineComponent,
22-
getCurrentInstance,
2322
onBeforeUnmount,
2423
onMounted,
2524
provide,
@@ -606,10 +605,10 @@ export default defineComponent({
606605

607606
// ============================= Dropdown ==============================
608607
const containerWidth = shallowRef<number>(null);
609-
const instance = getCurrentInstance();
608+
// const instance = getCurrentInstance();
610609
const onPopupMouseEnter = () => {
611610
// We need force update here since popup dom is render async
612-
instance.update();
611+
// instance.update();
613612
};
614613
onMounted(() => {
615614
watch(

0 commit comments

Comments
 (0)