From 6e57a0691ce295c3ee51daf6d2b055b38cb04b7c Mon Sep 17 00:00:00 2001 From: Isiah Meadows Date: Fri, 12 Jul 2019 16:27:24 -0400 Subject: [PATCH] Fix #2470 (#2471) --- api/router.js | 8 +++--- api/tests/test-router.js | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/api/router.js b/api/router.js index 365399cf..d224b4a6 100644 --- a/api/router.js +++ b/api/router.js @@ -189,9 +189,11 @@ module.exports = function($window, mountRedraw) { // Remove these so they don't get overwritten var attrs = {}, onclick, href assign(attrs, vnode.attrs) - attrs.component = null - attrs.options = null - attrs.key = null + // The first two are internal, but the rest are magic attributes + // that need censored to not screw up rendering. + attrs.component = attrs.options = attrs.key = attrs.oninit = + attrs.oncreate = attrs.onbeforeupdate = attrs.onupdate = + attrs.onbeforeremove = attrs.onremove = null // Do this now so we can get the most current `href` and `disabled`. // Those attributes may also be specified in the selector, and we diff --git a/api/tests/test-router.js b/api/tests/test-router.js index 8bbeed77..cec9c411 100644 --- a/api/tests/test-router.js +++ b/api/tests/test-router.js @@ -550,6 +550,64 @@ o.spec("route", function() { o(root.firstChild.firstChild.nodeValue).equals("text") }) + o("route.Link keeps magic attributes from being double-called", function() { + $window = browserMock(env) + var render = coreRenderer($window) + route = apiRouter(null, null) + route.prefix = prefix + root = $window.document.body + + var oninit = o.spy() + var oncreate = o.spy() + var onbeforeupdate = o.spy() + var onupdate = o.spy() + var onbeforeremove = o.spy() + var onremove = o.spy() + + render(root, m(route.Link, { + href: "/test", + oninit: oninit, + oncreate: oncreate, + onbeforeupdate: onbeforeupdate, + onupdate: onupdate, + onbeforeremove: onbeforeremove, + onremove: onremove, + }, "text")) + + o(oninit.callCount).equals(1) + o(oncreate.callCount).equals(1) + o(onbeforeupdate.callCount).equals(0) + o(onupdate.callCount).equals(0) + o(onbeforeremove.callCount).equals(0) + o(onremove.callCount).equals(0) + + render(root, m(route.Link, { + href: "/test", + oninit: oninit, + oncreate: oncreate, + onbeforeupdate: onbeforeupdate, + onupdate: onupdate, + onbeforeremove: onbeforeremove, + onremove: onremove, + }, "text")) + + o(oninit.callCount).equals(1) + o(oncreate.callCount).equals(1) + o(onbeforeupdate.callCount).equals(1) + o(onupdate.callCount).equals(1) + o(onbeforeremove.callCount).equals(0) + o(onremove.callCount).equals(0) + + render(root, []) + + o(oninit.callCount).equals(1) + o(oncreate.callCount).equals(1) + o(onbeforeupdate.callCount).equals(1) + o(onupdate.callCount).equals(1) + o(onbeforeremove.callCount).equals(1) + o(onremove.callCount).equals(1) + }) + o("route.Link can render other tag without routes or dom access", function() { $window = browserMock(env) var render = coreRenderer($window)