From fba3b0d34f16d07daf9618d6dd96c82ba719f789 Mon Sep 17 00:00:00 2001 From: Stuart Clark Date: Tue, 1 Aug 2023 10:01:15 +1000 Subject: [PATCH] fix: resolve issue remounting civictheme javascript (#96) * chore(#9): improve node library setup/teardown * chore(#93): improve node library setup/teardown * chore: fix lint issues --- src/components/MenuItem.vue | 19 +++++++++++++++---- src/components/Popover.vue | 12 ++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/components/MenuItem.vue b/src/components/MenuItem.vue index 728fb13..a609c8a 100644 --- a/src/components/MenuItem.vue +++ b/src/components/MenuItem.vue @@ -106,16 +106,27 @@ export default { isFlyout: ({ type }) => type === 'flyout', }, - created() { - // @TODO - Do this elsewhere? + mounted() { try { - if (process.client && this.isCollapsible) require('civictheme/components/00-base/collapsible/collapsible') - if (process.client && this.isFlyout) require('civictheme/components/00-base/flyout/flyout') + if (this.isCollapsible) { + delete require.cache[require.resolve('civictheme/components/00-base/collapsible/collapsible')] + require('civictheme/components/00-base/collapsible/collapsible') + } + + if (this.isFlyout) { + delete require.cache[require.resolve('civictheme/components/00-base/flyout/flyout')] + require('civictheme/components/00-base/flyout/flyout') + } } catch(e) { // eslint-disable-next-line console.error(e) } + }, + + beforeDestroy() { + if (this.isCollapsible) delete require.cache[require.resolve('civictheme/components/00-base/collapsible/collapsible')] + if (this.isFlyout) delete require.cache[require.resolve('civictheme/components/00-base/flyout/flyout')] } } diff --git a/src/components/Popover.vue b/src/components/Popover.vue index 4f9d604..4b8c5b1 100644 --- a/src/components/Popover.vue +++ b/src/components/Popover.vue @@ -9,6 +9,7 @@ {{ trigger }} @@ -42,14 +43,21 @@ export default { } }, - created() { + mounted() { try { - if (process.client) require('civictheme/components/00-base/collapsible/collapsible') + if (this.$el) { + delete require.cache[require.resolve('civictheme/components/00-base/collapsible/collapsible')] + require('civictheme/components/00-base/collapsible/collapsible') + } } catch(e) { // eslint-disable-next-line console.error(e) } + }, + + beforeDestroy() { + delete require.cache[require.resolve('civictheme/components/00-base/collapsible/collapsible')] } }