Skip to content

Commit 0e3e7e0

Browse files
fix(modal, tooltips, popovers): remove no longer needed nextTick delay when updating content in transporter portal (closes #4589) (#4604)
* chore: remove nextTick delay in BootstrapVue transporter portal * Update transporter.spec.js * Update modal.spec.js * Update modal.spec.js * Update modal.spec.js * Update modal.spec.js * Update modal.spec.js * Update modal.spec.js * Update modal.spec.js * Update modal.spec.js * Update modal.spec.js * Update modal.spec.js * Update transporter.js Co-authored-by: Jacob Müller <jacob.mueller.elz@gmail.com>
1 parent 4f33e16 commit 0e3e7e0

File tree

3 files changed

+18
-30
lines changed

3 files changed

+18
-30
lines changed

src/components/modal/modal.spec.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ describe('modal', () => {
8686
})
8787

8888
expect(wrapper.isVueInstance()).toBe(true)
89+
8990
await waitNT(wrapper.vm)
9091

9192
expect(wrapper.isEmpty()).toBe(true)
@@ -103,6 +104,7 @@ describe('modal', () => {
103104
})
104105

105106
expect(wrapper.isVueInstance()).toBe(true)
107+
106108
await waitNT(wrapper.vm)
107109

108110
expect(wrapper.isEmpty()).toBe(true)
@@ -127,9 +129,6 @@ describe('modal', () => {
127129
})
128130

129131
expect(wrapper.isVueInstance()).toBe(true)
130-
await waitNT(wrapper.vm)
131-
await waitRAF()
132-
await waitNT(wrapper.vm)
133132
await waitRAF()
134133

135134
// Main outer wrapper (has z-index, etc)... The stacker <div>
@@ -186,11 +185,6 @@ describe('modal', () => {
186185
})
187186

188187
expect(wrapper.isVueInstance()).toBe(true)
189-
await waitNT(wrapper.vm)
190-
await waitRAF()
191-
await waitNT(wrapper.vm)
192-
await waitRAF()
193-
await waitNT(wrapper.vm)
194188
await waitRAF()
195189

196190
expect(wrapper.isEmpty()).toBe(true)
@@ -208,10 +202,6 @@ describe('modal', () => {
208202
// Destroy modal
209203
wrapper.destroy()
210204

211-
await waitNT(wrapper.vm)
212-
await waitRAF()
213-
await waitNT(wrapper.vm)
214-
await waitRAF()
215205
await waitNT(wrapper.vm)
216206
await waitRAF()
217207

@@ -235,10 +225,7 @@ describe('modal', () => {
235225
})
236226

237227
expect(wrapper.isVueInstance()).toBe(true)
238-
await waitNT(wrapper.vm)
239-
await waitRAF()
240-
await waitNT(wrapper.vm)
241-
await waitRAF()
228+
242229
await waitNT(wrapper.vm)
243230
await waitRAF()
244231

@@ -268,8 +255,6 @@ describe('modal', () => {
268255
await waitRAF()
269256
await waitNT(wrapper.vm)
270257
await waitRAF()
271-
await waitNT(wrapper.vm)
272-
await waitRAF()
273258

274259
expect($modal.attributes('aria-hidden')).toBeDefined()
275260
expect($modal.attributes('aria-hidden')).toEqual('true')
@@ -293,7 +278,6 @@ describe('modal', () => {
293278
})
294279

295280
expect(wrapper.isVueInstance()).toBe(true)
296-
await waitNT(wrapper.vm)
297281

298282
// Modal title
299283
const $title = wrapper.find('.modal-title')
@@ -441,6 +425,7 @@ describe('modal', () => {
441425

442426
// Try and close modal (but we prevent it)
443427
$close.trigger('click')
428+
await waitNT(wrapper.vm)
444429
expect(trigger).toEqual('headerclose')
445430
expect(evt).toBeInstanceOf(BvModalEvent)
446431

@@ -457,6 +442,7 @@ describe('modal', () => {
457442
trigger = null
458443
evt = null
459444
$close.trigger('click')
445+
await waitNT(wrapper.vm)
460446
expect(trigger).toEqual('headerclose')
461447
expect(evt).toBeInstanceOf(BvModalEvent)
462448

@@ -522,6 +508,7 @@ describe('modal', () => {
522508

523509
// Try and close modal (but we prevent it)
524510
$ok.trigger('click')
511+
await waitNT(wrapper.vm)
525512
expect(trigger).toEqual('ok')
526513

527514
await waitNT(wrapper.vm)
@@ -536,6 +523,7 @@ describe('modal', () => {
536523
cancelHide = false
537524
trigger = null
538525
$cancel.trigger('click')
526+
await waitNT(wrapper.vm)
539527
expect(trigger).toEqual('cancel')
540528

541529
await waitNT(wrapper.vm)
@@ -593,6 +581,7 @@ describe('modal', () => {
593581

594582
// Try and close modal via ESC
595583
$modal.trigger('keydown.esc')
584+
await waitNT(wrapper.vm)
596585
expect(trigger).toEqual('esc')
597586

598587
await waitNT(wrapper.vm)
@@ -651,6 +640,7 @@ describe('modal', () => {
651640

652641
// Try and close modal via click out
653642
$modal.trigger('click')
643+
await waitNT(wrapper.vm)
654644
expect(trigger).toEqual('backdrop')
655645

656646
await waitNT(wrapper.vm)
@@ -1211,14 +1201,12 @@ describe('modal', () => {
12111201
// Try and set focusin on external button
12121202
$button.trigger('focusin')
12131203
await waitNT(wrapper.vm)
1214-
await waitNT(wrapper.vm)
12151204
expect(document.activeElement).not.toBe($button.element)
12161205
expect(document.activeElement).toBe($content.element)
12171206

12181207
// Try and set focusin on external button
12191208
$button.trigger('focus')
12201209
await waitNT(wrapper.vm)
1221-
await waitNT(wrapper.vm)
12221210
expect(document.activeElement).not.toBe($button.element)
12231211
expect(document.activeElement).toBe($content.element)
12241212

@@ -1235,7 +1223,6 @@ describe('modal', () => {
12351223
$bottomTrap.trigger('focusin')
12361224
$bottomTrap.trigger('focus')
12371225
await waitNT(wrapper.vm)
1238-
await waitNT(wrapper.vm)
12391226
expect(document.activeElement).not.toBe($bottomTrap.element)
12401227
expect(document.activeElement).not.toBe($content.element)
12411228
// The close (x) button (first tabable in modal) should be focused
@@ -1254,7 +1241,6 @@ describe('modal', () => {
12541241
$topTrap.trigger('focusin')
12551242
$topTrap.trigger('focus')
12561243
await waitNT(wrapper.vm)
1257-
await waitNT(wrapper.vm)
12581244
expect(document.activeElement).not.toBe($topTrap.element)
12591245
expect(document.activeElement).not.toBe($bottomTrap.element)
12601246
expect(document.activeElement).not.toBe($content.element)

src/utils/transporter.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ export const BTransporterSingle = /*#__PURE__*/ Vue.extend({
9595
this.mountTarget()
9696
},
9797
updated() {
98-
// Placed in a nextTick to ensure that children have completed
99-
// updating before rendering in the target
100-
this.$nextTick(() => {
101-
this.updateTarget()
102-
})
98+
// We need to make sure that all children have completed updating
99+
// before rendering in the target
100+
// `vue-simple-portal` has the this in a `$nextTick()`,
101+
// while `portal-vue` doesn't
102+
// Just trying to see if the `$nextTick()` delay is required or not
103+
// Since all slots in Vue 2.6.x are always functions
104+
this.updateTarget()
103105
},
104106
beforeDestroy() {
105107
this.unmountTarget()

src/utils/transporter.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('utils/transporter component', () => {
3939
})
4040

4141
expect(wrapper.isVueInstance()).toBe(true)
42-
await waitNT(wrapper.vm)
42+
4343
await waitNT(wrapper.vm)
4444

4545
expect(wrapper.element.nodeType).toBe(Node.COMMENT_NODE)
@@ -54,7 +54,7 @@ describe('utils/transporter component', () => {
5454
expect(target.parentElement).toBe(document.body)
5555

5656
wrapper.destroy()
57-
await waitNT(wrapper.vm)
57+
5858
await waitNT(wrapper.vm)
5959

6060
expect(target.parentElement).toEqual(null)

0 commit comments

Comments
 (0)