diff --git a/mithril.js b/mithril.js index 91a0f5c1..2c750b29 100644 --- a/mithril.js +++ b/mithril.js @@ -240,7 +240,7 @@ var m = (function app(window, undefined) { var controllerConstructors = [], controllers = [] while (data.view) { var controllerConstructor = (data.controller || {}).$original || data.controller || function() {} - var controllerIndex = cached.controllerConstructors ? cached.controllerConstructors.indexOf(controllerConstructor) : -1 + var controllerIndex = m.redraw.strategy() == "diff" && cached.controllerConstructors ? cached.controllerConstructors.indexOf(controllerConstructor) : -1 var controller = controllerIndex > -1 ? cached.controllers[controllerIndex] : new (data.controller || function() {}) var key = data && data.attrs && data.attrs.key data = pendingRequests == 0 || cached ? data.view(controller) : {tag: "placeholder"} diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index d1fa84ab..0552e1ef 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1033,6 +1033,48 @@ function testMithril(mock) { return !unloaded && found.id === "a" }) + test(function() { + //https://github.com/lhorie/mithril.js/issues/555 + var root = mock.document.createElement("div") + var MyComponent = { + controller: function(args) { + this.name = args.name; + }, + view: function(ctrl) { + return m('div', ctrl.name); + } + } + var FooPage = { + view: function() { + return m('div', [ + m('a[href=/]', {config: m.route}, 'foo'), + m('a[href=/bar]', {config: m.route}, 'bar'), + m.component(MyComponent, {name: 'Jane'}) + ]); + } + }; + var BarPage = { + view: function() { + return m('div', [ + m('a[href=/]', {config: m.route}, 'foo'), + m('a[href=/bar]', {config: m.route}, 'bar'), + m.component(MyComponent, {name: 'Bob'}) + ]); + } + }; + m.route(root, '/', { + '/': FooPage, + '/bar': BarPage + }) + + mock.requestAnimationFrame.$resolve() + + m.route("/bar") + + mock.requestAnimationFrame.$resolve() + + return root.childNodes[0].childNodes[2].childNodes[0].nodeValue == "Bob" + }) m.redraw.strategy(undefined) //teardown for m.mount tests //m.withAttr