-
Notifications
You must be signed in to change notification settings - Fork 123
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
Javascript doesn't work client-side #299
Comments
Hi @damienbidaud6 - how does your package.json looks like? If you need static resources, you need to declare the folders in the component spec. Example: https://github.com/matteofigus/oc-components-examples/blob/master/static-image/package.json#L14 |
I have add the folder in the static field like you can see:
|
Uhm ok that seems ok. Other thing to check, in your component are you using the staticPath parameter to build the url? Here is a step to use a static resource step by step: https://github.com/opentable/oc/wiki/Advanced-operations#add-image-in-the-view-template If all seems still good to you, are you able in case to share the code? |
I think have the same thing here my server.js
and my template.html
|
@damienbidaud6 I can't reprodue. Created a test repo to see if I'm doing something different? |
I have modified and push the index.js and the app.js for have a situation closer to what I have and when I try to select the input he is not found but when I use the same selector in the chrome commande line it select the input. |
Ok, I think I now understand 👍 So, when you have 2 files like that and you do server-side rendering, execution is going to happen as soon as the files are downloaded, but the order is going to be guaranteed to be the right one. When doing the client-side rendering, you may have a race condition for having file 2 downloaded and executed before file 1. To solve that, we usually follow one of those 3 approaches:
In my experience, 1) is good for doing something simple, but when you start having multiple components in the page something like 2-3) is required. Hopefully this clarifies 👍 |
I still can't reproduce. Just to double check, you tried the latest version I pushed here? In case you did, are you able to upload there the real version of the app.js? |
have you done an |
yes and I have check if something was using the port 3000 |
It's ok I try with sudo and it's work |
if you can make the project private I will push my app.js |
@damienbidaud6 done ;) |
I have push it |
they are only the first 2 input who have the js who work well the rest I have not interaction for example the button across the input of type number should increment or decrement the number and it does nothing but in a normal page it work well |
All right, I think I managed to reproduce! I think it may be something with the react chain of events. I'll look at it tomorrow with some fresh eyes and I'll let you know 👍 Thanks for being patient :) |
Ok, I think I now understand the problem 🎉 In the original files I see some points where there is a check for Now...when I put a So, I did something like that and worked with Chrome: window.oc = window.oc || {};
oc.cmd = oc.cmd || [];
oc.cmd.push(function(){
oc.require("{{path}}js/index.js", function(){
oc.require("{{path}}js/app.js", function(){
var DOMContentLoaded_event = document.createEvent("Event");
DOMContentLoaded_event.initEvent("DOMContentLoaded", true, true);
window.document.dispatchEvent(DOMContentLoaded_event);
});
});
}); Now - I think the problem is either in the I updated the private repository with the hack so that you can have a look @damienbidaud6 |
That's great thanks a lot for the help. I will look for change the And again thanks for the help. |
Hey, Pleasure! 👍 Let me know how it goes. Should I close this issue now? |
Yes I thing it's good. |
Hi,
I have a javascript file in my static ressources when I use it server-side or in local without open-component it work perfectly, but when I use the same component client-side the js is not executed and I don't have a error message in the console.
So my question is do they are limitation for the static ressources or a configuration issue who can block my js code the be executed client side?
thanks
The text was updated successfully, but these errors were encountered: