-
Notifications
You must be signed in to change notification settings - Fork 795
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
bug: events lost when template separated out in another js file, view works #3194
Comments
Thanks for the issue! This issue has been labeled as |
FYI I added a possible explanation (and workaround) on the StackOverflow question. |
@tricki that is still adding template1,2,3 in same .js file. with functional component however each one has its own .js file that i can lazy load |
@tricki @rwaskiewicz is there a way to store templates in CDN somewhere, since this is JSX I am not sure if I can send it from backend, if so how can i achieve that? |
Stencil doesn't have the same functionality that React does when it comes to functional components, which I think may be a part of what we're seeing here. At the very least, I think this is a good candidate where we can improve the documentation around functional components. At the same time, the behavior we're seeing here (where |
Prerequisites
Stencil Version
2.11.0
Current Behavior
Interesting problem, so please read till the end. what I want to achieve is separating template in another js file and lazyload it when required. This same thing when done in React ecosystem works, but stencil doesn't!
I am having my tsx template in another .js file say
template-three.js has simple onClick which only alerts
when I try to call this method by importing in component-two.tsx like this
View renders, but event listners are not working :/, not even a simple alert :(. When I inspect, I don’t see any event attached to button.
however if same function I keep inside component class, it works :( !!!
check two different objects when template defined inside and outside component.

Can you tell me what I am doing wrong here.
I can’t keep templates in component only cause I have many UI’s for same logic.
So far, I didn't get any way on internet this answer doesn't help either
https://stackoverflow.com/questions/51984162/passing-custom-template-to-stencil-component
Expected Behavior
Events should get attached not just view.
Steps to Reproduce
written in description sample component and sample template. attached repo for triage.
Code Reproduction URL
/~https://github.com/pranav-js/triage-repo
Additional Information
React support separating templates out like this, not sure why stencil is loosing events. One thing I found is loss of $elem key in object returned probably by
h
The text was updated successfully, but these errors were encountered: