Skip to content

Commit 85af9e5

Browse files
committed
Fix useModelMigration in async components
It was using getCurrentInstance() which, as I understand it, isn't part of vue's public API anymore and isn't guaranteed to work in every situation.
1 parent e30c702 commit 85af9e5

File tree

19 files changed

+44
-46
lines changed

19 files changed

+44
-46
lines changed

src/components/NcActionCheckbox/NcActionCheckbox.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ export default {
139139
'update:model-value',
140140
],
141141

142-
setup() {
143-
const model = useModelMigration('checked', 'update:checked')
142+
setup(props, {emit}) {
143+
const model = useModelMigration(props, emit, 'checked', 'update:checked')
144144
return {
145145
model,
146146
}

src/components/NcActionInput/NcActionInput.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ export default {
416416
'update:model-value',
417417
],
418418

419-
setup() {
420-
const model = useModelMigration('value', 'update:value')
419+
setup(props, {emit}) {
420+
const model = useModelMigration(props, emit, 'value', 'update:value')
421421
return {
422422
model,
423423
}

src/components/NcActionRadio/NcActionRadio.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ export default {
158158
'change',
159159
],
160160

161-
setup(props) {
161+
setup(props, {emit}) {
162162
if (typeof props.modelValue === 'boolean') {
163163
Vue.util.warn('[NcActionRadio] Boolean type of `modelValue` is deprecated and will be removed in next versions')
164164
}
165165

166-
const model = useModelMigration('checked', 'update:checked')
166+
const model = useModelMigration(props, emit, 'checked', 'update:checked')
167167
return {
168168
model,
169169
}

src/components/NcActionTextEditable/NcActionTextEditable.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ export default {
166166
'submit',
167167
],
168168

169-
setup() {
170-
const model = useModelMigration('value', 'update:value')
169+
setup(props, {emit}) {
170+
const model = useModelMigration(props, emit, 'value', 'update:value')
171171
return {
172172
model,
173173
isRtl,

src/components/NcCheckboxRadioSwitch/NcCheckboxRadioSwitch.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,8 @@ export default {
477477
'update:model-value',
478478
],
479479

480-
setup() {
481-
const model = useModelMigration('checked', 'update:checked')
480+
setup(props, {emit}) {
481+
const model = useModelMigration(props, emit, 'checked', 'update:checked')
482482
return {
483483
model,
484484
}

src/components/NcColorPicker/NcColorPicker.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ export default {
318318
'input',
319319
],
320320

321-
setup() {
322-
const model = useModelMigration('value', 'update:value', true)
321+
setup(props, {emit}) {
322+
const model = useModelMigration(props, emit, 'value', 'update:value', true)
323323
return {
324324
model,
325325
}

src/components/NcDateTimePicker/NcDateTimePicker.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ export default {
302302
'update:timezone-id',
303303
],
304304

305-
setup() {
306-
const model = useModelMigration('value', 'update:value')
305+
setup(props, {emit}) {
306+
const model = useModelMigration(props, emit, 'value', 'update:value')
307307
return {
308308
model,
309309
timezoneDialogHeaderId: `timezone-dialog-header-${GenRandomId()}`,

src/components/NcDateTimePickerNative/NcDateTimePickerNative.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ export default {
218218
'update:model-value',
219219
],
220220

221-
setup() {
222-
const model = useModelMigration('value', 'input')
221+
setup(props, {emit}) {
222+
const model = useModelMigration(props, emit, 'value', 'input')
223223
return {
224224
model,
225225
}

src/components/NcInputField/NcInputField.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ export default {
272272
'trailing-button-click',
273273
],
274274

275-
setup() {
276-
const model = useModelMigration('value', 'update:value', true)
275+
setup(props, {emit}) {
276+
const model = useModelMigration(props, emit, 'value', 'update:value', true)
277277
return {
278278
model,
279279
}

src/components/NcPasswordField/NcPasswordField.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ export default {
248248
'update:model-value',
249249
],
250250

251-
setup() {
252-
const model = useModelMigration('value', 'update:value')
251+
setup(props, {emit}) {
252+
const model = useModelMigration(props, emit, 'value', 'update:value')
253253
return {
254254
model,
255255
}

src/components/NcRichContenteditable/NcRichContenteditable.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,9 @@ export default {
438438
'smart-picker-submit',
439439
],
440440

441-
setup() {
441+
setup(props, {emit}) {
442442
const uid = GenRandomId(5)
443-
const model = useModelMigration('value', 'update:value', true)
443+
const model = useModelMigration(props, emit, 'value', 'update:value', true)
444444
return {
445445
model,
446446
// Constants

src/components/NcSelect/NcSelect.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -990,12 +990,12 @@ export default {
990990
'update:model-value',
991991
],
992992

993-
setup() {
993+
setup(props, {emit}) {
994994
const clickableArea = Number.parseInt(window.getComputedStyle(document.body).getPropertyValue('--default-clickable-area'))
995995
const gridBaseLine = Number.parseInt(window.getComputedStyle(document.body).getPropertyValue('--default-grid-baseline'))
996996
const avatarSize = clickableArea - 2 * gridBaseLine
997997

998-
const model = useModelMigration('value', 'input')
998+
const model = useModelMigration(props, emit, 'value', 'input')
999999

10001000
return {
10011001
avatarSize,

src/components/NcSelectTags/NcSelectTags.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ export default {
293293
' ',
294294
],
295295

296-
setup() {
297-
const model = useModelMigration('value', 'input')
296+
setup(props, {emit}) {
297+
const model = useModelMigration(props, emit, 'value', 'input')
298298
const noop = () => {}
299299
return {
300300
model,

src/components/NcSettingsInputText/NcSettingsInputText.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ export default {
133133
'change',
134134
],
135135

136-
setup() {
137-
const model = useModelMigration('value', 'update:value')
136+
setup(props, {emit}) {
137+
const model = useModelMigration(props, emit, 'value', 'update:value')
138138
return {
139139
model,
140140
}

src/components/NcSettingsSelectGroup/NcSettingsSelectGroup.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ export default {
137137
'update:model-value',
138138
'error',
139139
],
140-
setup() {
141-
const model = useModelMigration('value', 'input')
140+
setup(props, {emit}) {
141+
const model = useModelMigration(props, emit, 'value', 'input')
142142
return {
143143
model,
144144
}

src/components/NcTextArea/NcTextArea.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ export default {
267267
'update:model-value',
268268
],
269269

270-
setup() {
271-
const model = useModelMigration('value', 'update:value', true)
270+
setup(props, {emit}) {
271+
const model = useModelMigration(props, emit, 'value', 'update:value', true)
272272
return {
273273
model,
274274
}

src/components/NcTextField/NcTextField.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ export default {
226226
'update:model-value',
227227
],
228228

229-
setup() {
230-
const model = useModelMigration('value', 'update:value')
229+
setup(props, {emit}) {
230+
const model = useModelMigration(props, emit, 'value', 'update:value')
231231
return {
232232
model,
233233
}

src/components/NcTimezonePicker/NcTimezonePicker.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ export default {
101101
/** Same as update:modelValue for Vue 2 compatibility */
102102
'update:model-value',
103103
],
104-
setup() {
105-
const model = useModelMigration('value', 'input')
104+
setup(props, {emit}) {
105+
const model = useModelMigration(props, emit, 'value', 'input')
106106
return {
107107
model,
108108
}

src/composables/useModelMigration.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,26 @@ import Vue, { getCurrentInstance, computed } from 'vue'
1212
* @param {boolean} required - If the prop is required
1313
* @return {import('vue').WritableComputedRef} - model proxy
1414
*/
15-
export function useModelMigration(oldModelName, oldModelEvent, required = false) {
16-
const vm = getCurrentInstance()!.proxy
17-
18-
if (required && vm.$props[oldModelName] === undefined && vm.$props.modelValue === undefined) {
15+
export function useModelMigration(props, emit, oldModelName, oldModelEvent, required = false) {
16+
if (required && props[oldModelName] === undefined && props.modelValue === undefined) {
1917
Vue.util.warn(`Missing required prop: "modelValue" or old "${oldModelName}"`)
2018
}
2119

2220
const model = computed({
2321
get() {
24-
if (vm.$props[oldModelName] !== undefined) {
25-
return vm.$props[oldModelName]
22+
if (props[oldModelName] !== undefined) {
23+
return props[oldModelName]
2624
}
27-
return vm.$props.modelValue
25+
return props.modelValue
2826
},
2927

3028
set(value) {
3129
// New nextcloud-vue v9 event
32-
vm.$emit('update:modelValue', value)
30+
emit('update:modelValue', value)
3331
// Vue 2 fallback for kebab-case event names in templates (recommended by Vue 3 style guide)
34-
vm.$emit('update:model-value', value)
32+
emit('update:model-value', value)
3533
// Old nextcloud-vue v8 event
36-
vm.$emit(oldModelEvent, value)
34+
emit(oldModelEvent, value)
3735
},
3836
})
3937

0 commit comments

Comments
 (0)