From 9f2cc54738bbdd167082cd443090c9a7e09de67a Mon Sep 17 00:00:00 2001 From: shibao Date: Fri, 4 Mar 2022 22:56:52 -0500 Subject: [PATCH] fix maintain attrs hook --- assets/js/maintain_attrs.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/assets/js/maintain_attrs.js b/assets/js/maintain_attrs.js index f4ff238..439d263 100644 --- a/assets/js/maintain_attrs.js +++ b/assets/js/maintain_attrs.js @@ -2,7 +2,10 @@ // update. https://github.com/phoenixframework/phoenix_live_view/issues/1011 export default { - attrs () { return this.el.getAttribute('data-attrs').split(', ') }, + attrs() { + const attrs = this.el.getAttribute('data-attrs'); + if (attrs) { return attrs.split(', '); } else { return []; } + }, beforeUpdate () { this.prevAttrs = this.attrs().map(name => [name, this.el.getAttribute(name)]) }, updated () { this.prevAttrs.forEach(([name, val]) => this.el.setAttribute(name, val)) } }