use of com.vaadin.flow.component.dependency.JavaScript in project flow by vaadin.
the class BootstrapHandlerDependenciesTest method assertJavaScriptElementInlined.
private void assertJavaScriptElementInlined(Element head, String expectedContents) {
List<Element> scriptsWithoutExpectedContents = head.getElementsByTag("script").stream().filter(element -> element.toString().contains(expectedContents)).collect(Collectors.toList());
assertThat("Expected to have only one inlined js element with contents = " + expectedContents, scriptsWithoutExpectedContents.size(), is(1));
Element inlinedElement = scriptsWithoutExpectedContents.get(0);
assertThat("The element should have correct js type attribute", inlinedElement.attr("type"), is("text/javascript"));
assertThat("Inlined js element should not have defer attribute", inlinedElement.attr("defer"), is(""));
assertThat("Inlined js element should not have src attribute", inlinedElement.attr("src"), is(""));
}
use of com.vaadin.flow.component.dependency.JavaScript in project flow by vaadin.
the class UIInternals method addFallbackDependencies.
private void addFallbackDependencies(DependencyInfo dependency) {
if (isFallbackChunkLoaded) {
return;
}
VaadinContext context = ui.getSession().getService().getContext();
FallbackChunk chunk = context.getAttribute(FallbackChunk.class);
if (chunk == null) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Fallback chunk is not available, skipping fallback dependencies load");
}
return;
}
Set<String> modules = chunk.getModules();
Set<CssImportData> cssImportsData = chunk.getCssImports();
if (modules.isEmpty() && cssImportsData.isEmpty()) {
getLogger().debug("Fallback chunk is empty, skipping fallback dependencies load");
return;
}
List<CssImport> cssImports = dependency.getCssImports();
List<JavaScript> javaScripts = dependency.getJavaScripts();
List<JsModule> jsModules = dependency.getJsModules();
if (jsModules.stream().map(JsModule::value).anyMatch(modules::contains)) {
loadFallbackChunk();
return;
}
if (javaScripts.stream().map(JavaScript::value).anyMatch(modules::contains)) {
loadFallbackChunk();
return;
}
if (cssImports.stream().map(this::buildData).anyMatch(cssImportsData::contains)) {
loadFallbackChunk();
return;
}
}
Aggregations