Skip to content
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

Importing JavaScript - It seems the two methods of doing so cannot be combined #6223

Closed
markhm opened this issue Aug 10, 2019 · 2 comments
Closed

Comments

@markhm
Copy link

markhm commented Aug 10, 2019

When importing JavaScript files to a Vaadin Component, as described here:

https://vaadin.com/docs/v13/flow/importing-dependencies/tutorial-importing.html,

it was noteworthy, that it does not seem possible to combine the @javascript("http://d3js.org/d3.v3.min.js) tag at class definition with loading the other JavaScript file via: page.addJavaScript("js/tree_example.js");. In this case, as I experienced, the d3 library is not loaded, or at least its contents is not accessible.

Not clear if this is a bug, but I wanted to mention it.

@juhopiirainen juhopiirainen transferred this issue from vaadin/platform Aug 12, 2019
@project-bot project-bot bot added this to Inbox - needs triage in OLD Vaadin Flow ongoing work (Vaadin 10+) Aug 12, 2019
@juhopiirainen
Copy link

Moving the issue to the Flow team.

@caalador
Copy link
Contributor

Hi.

The problem is that the page.addJavaScript is exeuted befor the @javascript as the page.add will be sent in the bootstrap response and will be added before the annotated javascript.

The correct way to use JS import is to only use one way of importing.

If you would want to use the given way of mixing then the tree_example.js should start with polling until d3 is available e.g.

 const poller = () => {
     if (d3) {
         window.alert(d3.selectAll("p").length);
     } else {
         setTimeout(poller, 10);
     }
 };

I'll close this ticket as we have nothing to do for it as both ways correctly load the external script.

OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from Inbox - needs triage to Done - pending release Aug 15, 2019
@caalador caalador added this to the Abandoned milestone Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
OLD Vaadin Flow ongoing work (Vaadin ...
  
Done - pending release
Development

No branches or pull requests

3 participants