diff --git a/src/block.ts b/src/block.ts index 95cb2cb..123cb12 100644 --- a/src/block.ts +++ b/src/block.ts @@ -81,7 +81,18 @@ export class Block { node = next } } else { - this.template.parentNode!.removeChild(this.template) + try { + // Possibly related to https://github.com/vuejs/petite-vue/discussions/188 , but at times (not always predictable, so not + // sure what markup/order causes issue) a simple v-for="o in model.searchResultsResources" would cause an error when reactivity + // was changing for searchResultsResources from an array with values to an empty array, parentNode was occasionally null. + if (this.template.isConnected) { + this.template.parentNode!.removeChild(this.template) + } + } catch (error) { + console.log("petite-vue: Unable to remove template"); + console.log(error); + console.log(this.template); + } } this.teardown() } diff --git a/src/directives/bind.ts b/src/directives/bind.ts index 814c882..b444897 100644 --- a/src/directives/bind.ts +++ b/src/directives/bind.ts @@ -8,7 +8,7 @@ import { camelize } from '@vue/shared' -const forceAttrRE = /^(spellcheck|draggable|form|list|type)$/ +const forceAttrRE = /^(spellcheck|draggable|form|list|type|onclick)$/ export const bind: Directive = ({ el, @@ -20,7 +20,8 @@ export const bind: Directive = ({ let prevValue: any // record static class - if (arg === 'class') { + // Update: Was checking if arg==="class", but that was false if bind to { class: }, so just storing no matter what for later use + if (el.className) { el._class = el.className } diff --git a/src/walk.ts b/src/walk.ts index f996461..708c391 100644 --- a/src/walk.ts +++ b/src/walk.ts @@ -121,6 +121,7 @@ const processDirective = ( let dir: Directive let arg: string | undefined let modifiers: Record | undefined + const attrName = raw; // modifiers raw = raw.replace(modifierRE, (_, m) => { @@ -143,7 +144,7 @@ const processDirective = ( if (dir) { if (dir === bind && arg === 'ref') dir = ref applyDirective(el, dir, exp, ctx, arg, modifiers) - el.removeAttribute(raw) + el.removeAttribute(attrName) } else if (import.meta.env.DEV) { console.error(`unknown custom directive ${raw}.`) }