Skip to content

Commit

Permalink
fix resource destroy problem
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Dec 23, 2022
1 parent 78e3b77 commit 16851d9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"@fullcalendar/core": "~6.0.1",
"@fullcalendar/daygrid": "~6.0.1",
"@fullcalendar/interaction": "~6.0.1",
"@fullcalendar/resource": "~6.0.1",
"@fullcalendar/resource-timeline": "~6.0.1",
"@vue/test-utils": "^1.0.3",
"babel-loader": "^8.1.0",
"concurrently": "^5.3.0",
Expand Down
10 changes: 9 additions & 1 deletion src/TransportContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const TransportContainer = Vue.extend({

mounted() {
replaceEl(this.$el, this.inPlaceOf)

// insurance for if Preact recreates and reroots inPlaceOf element
;(this.inPlaceOf as HTMLElement).style.display = 'none'

this.reportEl(this.$el)
},

Expand All @@ -37,7 +41,11 @@ const TransportContainer = Vue.extend({
},

beforeDestroy() {
dummyContainer.removeChild(this.inPlaceOf)
// protect against Preact recreating and rerooting inPlaceOf element
if (this.inPlaceOf.parentNode === dummyContainer) {
dummyContainer.removeChild(this.inPlaceOf)
}

this.reportEl(null)
}
})
Expand Down
40 changes: 40 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mount as _mount } from '@vue/test-utils'
import FullCalendar from '../dist/index.js'
import dayGridPlugin from '@fullcalendar/daygrid'
import interactionPlugin from '@fullcalendar/interaction'
import resourceTimelinePlugin from '@fullcalendar/resource-timeline'
import Vue from 'vue'


Expand Down Expand Up @@ -606,6 +607,45 @@ it('slot rendering reacts to bound parent state', async () => {
})


// https://github.com/fullcalendar/fullcalendar/issues/7105 (but for vue2)
describe('with resource-timeline view', () => {
it('doesn\'t throw any errors when removing a resource', async () => {
let wrapper = mount({
components: {
FullCalendar,
},
template: `
<FullCalendar ref='calendar' :options='calendarOptions'>
<template v-slot:resourceLabelContent="arg">
<b>{{ arg.resource.title }}</b>
</template>
</FullCalendar>
`,
data() {
return {
calendarOptions: {
plugins: [resourceTimelinePlugin],
initialView: 'resourceTimelineWeek',
resources: [{ id: 'a', title: 'a' }]
}
}
},
methods: {
removeResource() {
const calendarApi = this.$refs.calendar.getApi()
const resource = calendarApi.getResourceById('a')
resource.remove()
}
}
})

await Vue.nextTick()
wrapper.vm.removeResource() // TODO: have test fail if any error is thrown
await Vue.nextTick()
})
})


// FullCalendar options utils

function buildEvents(length, timed) {
Expand Down

0 comments on commit 16851d9

Please sign in to comment.