From 6f2b87c1698cbb52183e3f446b5acc9c98a9dad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20G=C3=B3mez=20V=C3=A1squez?= Date: Thu, 8 Mar 2018 11:52:52 +0100 Subject: [PATCH 1/2] Clear Interval if the component doesn't have the $el property Using the vuelidate plugin creates components that do not have an $el property, but still have _hasMetaInfo set to true, which results in the setInterval never being cleared. There may be other plugins that create similar components. Changing the line to if (this.$el && this.$el.offsetParent !== null) return would resolve this issue. --- src/shared/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/plugin.js b/src/shared/plugin.js index a493dcc..1649348 100644 --- a/src/shared/plugin.js +++ b/src/shared/plugin.js @@ -87,7 +87,7 @@ export default function VueMeta (Vue, options = {}) { if (this._hasMetaInfo) { // Wait that element is hidden before refreshing meta tags (to support animations) const interval = setInterval(() => { - if (this.$el.offsetParent !== null) return + if (this.$el && this.$el.offsetParent !== null) return clearInterval(interval) batchID = batchUpdate(batchID, () => this.$meta().refresh()) }, 50) From 1eb85b310a6dca57a83a8f16556d7caa8a3df71a Mon Sep 17 00:00:00 2001 From: Paul Gascou-Vaillancourt Date: Tue, 13 Mar 2018 12:02:42 -0400 Subject: [PATCH 2/2] Add tests for src/shared/plugins.js --- test/plugin.spec.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/plugin.spec.js diff --git a/test/plugin.spec.js b/test/plugin.spec.js new file mode 100644 index 0000000..aa8d080 --- /dev/null +++ b/test/plugin.spec.js @@ -0,0 +1,33 @@ +import Vue from 'vue' +import VueMeta from '../src/shared/plugin' +import { + VUE_META_KEY_NAME, + VUE_META_ATTRIBUTE, + VUE_META_SERVER_RENDERED_ATTRIBUTE, + VUE_META_TAG_LIST_ID_KEY_NAME +} from '../src/shared/constants' + +describe('plugin', () => { + Vue.use(VueMeta, { + keyName: VUE_META_KEY_NAME, + attribute: VUE_META_ATTRIBUTE, + ssrAttribute: VUE_META_SERVER_RENDERED_ATTRIBUTE, + tagIDKeyName: VUE_META_TAG_LIST_ID_KEY_NAME + }) + + it('adds $meta() to Vue prototype', () => { + const instance = new Vue() + expect(instance.$meta).to.be.a('function') + }) + + it('components have _hasMetaInfo set to true', () => { + const Component = Vue.component('test-component', { + template: '
Test
', + [VUE_META_KEY_NAME]: { + title: 'helloworld' + } + }) + const vm = new Vue(Component).$mount() + expect(vm._hasMetaInfo).to.equal(true) + }) +})