Skip to content

Commit 369fa19

Browse files
authored
Fix race when collapse element is unmounted before transition completes (#33)
Thank you very much! I'll release v1.3.5 right away.
1 parent 51502dc commit 369fa19

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/vue-collapsed/src/Collapse.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,13 @@ watch(isExpanded, (isExpanding) => {
168168
})
169169
170170
requestAnimationFrame(() => {
171+
if (!collapseRef.value) return
171172
/** If for any unknown edge case the scrollHeight === 0, abort transition and force expand */
172-
if (collapseRef.value!.scrollHeight === 0) return onExpanded()
173+
if (collapseRef.value.scrollHeight === 0) return onExpanded()
173174
174175
/** Set height to scrollHeight and trigger the transition. */
175176
176-
transitionStartScrollHeight = collapseRef.value!.scrollHeight
177+
transitionStartScrollHeight = collapseRef.value.scrollHeight
177178
178179
addStyles({
179180
...getTransitionProp(collapseRef),
@@ -203,6 +204,7 @@ watch(isExpanded, (isExpanding) => {
203204
if (collapseRef.value.scrollHeight === 0) return onCollapsed()
204205
205206
requestAnimationFrame(() => {
207+
if (!collapseRef.value) return
206208
/** Set height to baseHeight and trigger the transition. */
207209
addStyles({
208210
...baseHeightStyles.value,
@@ -228,6 +230,8 @@ watch(baseHeight, (newBaseHeight) => {
228230
// Transition events
229231
230232
function onTransitionEnd(e: TransitionEvent) {
233+
if (!collapseRef.value) return
234+
231235
if (e.target && e.target === collapseRef.value && e.propertyName === 'height') {
232236
/**
233237
* Reset styles to the initial style state,

0 commit comments

Comments
 (0)