Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't delete _i18n in beforeDestroy #880

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ export default {
self._localeWatcher()
delete self._localeWatcher
}

self._i18n = null
})
}
}
2 changes: 0 additions & 2 deletions test/unit/component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ describe('component translation', () => {
assert.strictEqual(subChild2.textContent, 'sub-child2')

vm.$destroy()
}).then(() => {
assert(vm.$i18n === null)
}).then(done)
})
})
18 changes: 18 additions & 0 deletions test/unit/issues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,4 +693,22 @@ describe('issues', () => {
assert.strictEqual(vm.$te('message.empty'), true)
})
})

describe('#879', () => {
it('$t should not throw when invoked on a destroyed component', async () => {
const vm = new Vue({
i18n: new VueI18n({ locale: 'en' }),
methods: {
test: async function () {
// Long running async method that terminates after the component is destroyed.
await new Promise((resolve) => setTimeout(resolve, 50))
this.$t('anything')
}
}
})
const promise = vm.test() // invocation before being destroyed
vm.$destroy()
await promise // should not throw
})
})
})