-
Notifications
You must be signed in to change notification settings - Fork 596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Choo v5 / v6 onload handlers on root node not called when navigating #490
Comments
If I understand it correctly, this is a typical nanomorph/morphdom issue… when you navigate between routes, the diffing algorithm compares… before: It sees that the element that exists is already a I don't know what the best approach for your problem is this but I hope this helps explain why it doesn't work! |
@bengourley Thanks for elaborating. I'm aware of this behavior, but still crashed into this and got confused. It should somehow be handled or highlighted by Choo, I think. |
If you set unique IDs on the nodes, it'll treat it as a new node and onload will fire correctly On 9 May 2017 09:57, Maximilian Antoni <[email protected]> wrote:@bengourley Thanks for elaborating. I'm aware of this behavior, but still crashed into this and got confused. It should somehow be handled or highlighted by Choo, I think.
—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or mute the thread.
|
No, setting unique IDs on the nodes does not help. Actually, the Here is a minimal Choo app to illustrate the issue: var html = require('choo/html')
var choo = require('choo')
var app = choo()
function onloadA() {
console.log('onload A')
}
function onloadB() {
console.log('onload B')
}
app.route('/a', function (state, emit) {
return html`<div onload=${onloadA} id="a"><a href="/b">Go to B</a></div>`
})
app.route('/b', function (state, emit) {
return html`<div onload=${onloadB} id="b"><a href="/a">Go to A</a></div>`
})
document.body.appendChild(app.start()) Save as |
Actually, if you look at the DOM changes when navigating between |
I just hit this too and can confirm the issue. Edit: Speculated about using |
Think this is related - we need to change this (:
choojs/nanomorph#63
…On Mon, May 15, 2017 at 1:51 PM Nick Williams ***@***.***> wrote:
I just hit this too and can confirm the issue. Looking at the nanomorph
code I spotted another workaround that seems to work, setting unique values
for data-onloadid on your root elements, which is slightly nicer than
setting it on a child element (as that can require creating one just for
the purpose).
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#490 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACWlegP8kaEm_tFVSt9eae9BWFexptn0ks5r6DxGgaJpZM4NU-m6>
.
|
choojs/nanomorph#63 will land in choo v6 ✨ |
I had another look with Choo 6.0 and Choo 6.5. Now none of the |
@mantoni yeah, we removed it entirely — this was a breaking change in Does that make sense? |
Makes sense. It's at least consistent now. However, I'd personally think this is a common thing to try when playing with Choo. How about adding an assertion? |
What do you mean by assertion? Where would it go?
…On Mon, Oct 23, 2017 at 1:27 PM Maximilian Antoni ***@***.***> wrote:
Makes sense. It's at least consistent now. However, I'd personally think
this is a common thing to try when playing with Choo. How about adding an
assertion?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#490 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACWleptRE5azZh0lmmo2ryKEQf9pfubAks5svHgrgaJpZM4NU-m6>
.
|
I‘m mean that Choo should throw if you’re using |
@mantoni please check you're running the latest bel; I made sure to remove it in a major version a couple of months ago. There's valid use cases for an |
@yoshuawuyts Thanks for the pointer. Took me a while to find out why my code is still working 😅 Turns out I'm always going through Closing issue since it's by design. However, I'm not sure how I'm supposed to migrate my codebase once |
Short reply as it's late, but check out:
- https://github.com/choojs/nanocomponent
- #593
…On Mon, Oct 30, 2017 at 8:44 PM Maximilian Antoni ***@***.***> wrote:
@yoshuawuyts <https://github.com/yoshuawuyts> Thanks for the pointer.
Took me a while to find out why my code is still working 😅
Turns out I'm always going through yo-yoify and never hit bel directly.
The onload feature was not removed from yo-yoify (yet).
Closing issue since it's by design. However, I'm not sure how I'm supposed
to migrate my codebase once onload stops working. I depend heavily on
this feature and using the on-load library is not as convenient 🤔
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#490 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACWlelyj91xuEToGZdhwotz2AbJ-XzdSks5sxicWgaJpZM4NU-m6>
.
|
Steps to reproduce behavior
Create two pages:
/foo
with root<div>
/bar
with root<div onload=${myHandler}>
Expected behavior
Navigating from
/foo
to/bar
triggers theonload
handlerActual behavior
The
onload
handler is not triggered upon navigation. It is triggered when loading the/bar
page initially though.Workaround
Attaching the
onload
handler to a child node fixes the issue.The workaround is simple enough to apply. If this is tricky to solve, I think an assertion would also do.
The text was updated successfully, but these errors were encountered: