-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Blaze: Uncaught Error: Must be attached #213
Comments
is there any workaround for this? |
Yes, see discussion here. |
Nice, I just ran into this for the first time today! |
I'm probably the last person still using Blaze, but for posterity I will add here that I encountered this error when I was using jQuery to get a field value for a method call, and solved it by making sure that I used the template.$ jQuery call instead. |
@rtcwp07 cheers man, could you please elaborate what you mean with "the template.$ jQuery call"? Thanks! |
Hello @dariovillalta , When you have an event handler the first argument is an event and second is instance of the template, so instead of using global 'click .my-button'(event, template) {
template.$('my-input').val()
} |
@dr-dimitru nice explaining, thank you so much! |
No update after 2 years? This keeps happening a lot (I use external libraries that are based on jquery)... |
I'm closing this issue because it's too old. If you think this issue is still relevant please open a new one. Why? We need to pay attention to all the open items so we should keep opened only items where people are involved. |
I think this is worth reopening @filipenevola as it's still happening a LOT and it would be a shame to lose all the history. It's already been evicted once. I don't see anything relating to jquery in the callstack for our project. The two most common call stacks I see are as follows:
|
I also recently saw this in my project. domrange.js:337 Uncaught Error: Must be attached
at Blaze._DOMRange.DOMRange.containsElement (domrange.js:337:11)
at Blaze._DOMRange.<anonymous> (view.js:891:25)
at HTMLButtonElement.<anonymous> (events.js:49:24)
at HTMLDivElement.dispatch (modules.js?hash=5a94ac1782b4de33da07a5edf5fbaede26f5d256:20544:27)
at HTMLDivElement.elemData.handle (modules.js?hash=5a94ac1782b4de33da07a5edf5fbaede26f5d256:20348:28) |
@distalx can you give an example of the selector you have renamed? |
@dr-dimitru Something like |
So @distalx , have you managed to get rid of this completely by renaming the button class or id in question. Our callstack is so vague I can't pin it down a particular selector to try this out but a huge majority of our ids and classnames have hyphens. |
@lynchem, it also seem odd to me. So I've put-together a reproduction for this issue. https://github.com/distalx/meteor-blaze-issue-213 I believe this error occurs when a parent and a child template both using a same selector-name. |
Maybe related PR: #366 |
So, I've dug deeper into this bug. If both the parent template and child template contain an event handler that triggers on an element that exists in both templates, it seems only natural for it to trigger twice. It triggers in the child component first then once again the parent. In the case of @distalx example repo, we get <template name="parent_template">
{{!-- The below button renders for specific case --}}
{{!-- that logic is not important for this reproduction --}}
<button type="button" class="go-back" name="button" hidden>
Go back
</button>
{{> Template.dynamic template=child_template}}
</template>
Template.parent_template.events({
'click .go-back'(event, instance) {
console.log("PARENT TEMPLATE")
event.preventDefault()
history.back()
},
}) <template name="child_template">
<button type="button" class="go-back" name="button">
Go back
</button>
</template>
Template.child_template.events({
'click .go-back'(event) {
console.log("CHILD TEMPLATE")
event.preventDefault();
FlowRouter.go('/')
}
}); I'm kind of confused as to how we can "solve" this, because the error is kind of right. You're double-triggering an event that destroys the view so of course it's gonna error in the second time. We can place a check here to detect this (regardless of how we do it) and exit the process but I'm unsure whether this is the best route because like I said it's not a bug per se. What if this is purposeful? A developer wants to double trigger an event on both the parent and child?? It's pretty weird. I really need your opinion guys. We may also modify this error so it's more telling of what's going on like Side note, but I've contacted @jankapunkt and once we fix this issue we can release 2.6.1. |
Sounds like the most appropriate solution |
Thank you Dimitry for chiming in. That's one vote down for editing the error message. I need more votes to decide on this. |
Oh wow, great work @distalx & @harryadel for debugging that 👏🏻 I think this coupled with what @jankapunkt has done in his PR will allow us to completely eliminate all the Must be Attached warnings 🥳 |
Now it outputs a more descriptive version: `${event} event triggerd with ${selector} on ${templateName} but associated view is not be found. Make sure the event doesn't destroy the view.` Fixes meteor#213
…fix #213 Merge pull request #376 from harryadel/view-must-be-attached-error Thanks to @harryadel
Migrating this over from meteor/meteor#2981.
(originally reported by @mitar)
See example project. When clicking on "Click Me" button, there is an uncaught Error:
Must be attached
.The text was updated successfully, but these errors were encountered: