Closed claudiofelber closed 7 years ago
If you already know how to fix it, feel free to send a pull request! It would be much appreciated.
On Thu, Nov 3, 2016, 06:34 Claudio Felber notifications@github.com wrote:
Description
For every controller that has already been unloaded, the onunload handler is called again when another component is mounted (e.g. when the route changes). Steps to Reproduce
In the subsequent example do the following:
- Open the console
- Click on settings link
- Click on redraw a couple of times
- Click on home link
You will see multiple UNLOAD messages in the console, one for every controller that has been created and already (!) been unloaded.
<!DOCTYPE html>
Note: The random noise has been added to force the controller to be recreated. Fix
Extend the unload() function in order to have it remove onunload handlers from the unloaders array:
function unload(cached) { ... if (cached.controllers) { forEach(cached.controllers, function (controller) { if (isFunction(controller.onunload)) { controller.onunload({preventDefault: noop}) // Remove onunload handler from unloaders array for (var i = 0; i < unloaders.length; i++) { if (unloaders[i].handler == controller.onunload) { unloaders.splice(i, 1) break } } } }) } ... }
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lhorie/mithril.js/issues/1382, or mute the thread https://github.com/notifications/unsubscribe-auth/AERrBJx-3xmeoQyupxvyF3yh1m0TW3mJks5q6bivgaJpZM4KoMyc .
I wrote a simpler test case (with less noise ;P) here: https://jsbin.com/joyixep/edit?js,console,output
I tried to fix this in #1424 but couldn't because of what appears to be a bug in the v0.X test framework, Mithril itself, or an oversight on my part: in the test case, the subcomponent doesn't trigger onunload when it's removed directly. Any insight welcome.
Closing - last v0.2 release has been cut.
Description
For every controller that has already been unloaded, the onunload handler is called again when another component is mounted (e.g. when the route changes).
Steps to Reproduce
In the subsequent example do the following:
You will see multiple UNLOAD messages in the console, one for every controller that has been created and already (!) been unloaded.
Note: The random noise has been added to force the controller to be recreated.
Fix
Extend the unload() function in order to have it remove onunload handlers from the unloaders array: