From 818fd2fb43dc09bd22e7384210fc2e7e17a64788 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Mon, 5 Jun 2023 22:00:02 -0400 Subject: [PATCH] fix JavaScript injection issue on first render for Resources defined in IModule and ITheme --- Oqtane.Client/UI/ThemeBuilder.razor | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Oqtane.Client/UI/ThemeBuilder.razor b/Oqtane.Client/UI/ThemeBuilder.razor index 2b185b83..dc03e12e 100644 --- a/Oqtane.Client/UI/ThemeBuilder.razor +++ b/Oqtane.Client/UI/ThemeBuilder.razor @@ -96,30 +96,30 @@ { await InjectScripts(PageState.Page.BodyContent, ResourceLocation.Body); } + } - if (PageState.Page.Resources != null && PageState.Page.Resources.Exists(item => item.ResourceType == ResourceType.Script)) + if (PageState.Page.Resources != null && PageState.Page.Resources.Exists(item => item.ResourceType == ResourceType.Script)) + { + var interop = new Interop(JSRuntime); + var scripts = new List(); + var inline = 0; + foreach (Resource resource in PageState.Page.Resources.Where(item => item.ResourceType == ResourceType.Script && item.Level != ResourceLevel.Site)) { - var interop = new Interop(JSRuntime); - var scripts = new List(); - var inline = 0; - foreach (Resource resource in PageState.Page.Resources.Where(item => item.ResourceType == ResourceType.Script && item.Level != ResourceLevel.Site)) + if (!string.IsNullOrEmpty(resource.Url)) { - if (!string.IsNullOrEmpty(resource.Url)) - { - var url = (resource.Url.Contains("://")) ? resource.Url : PageState.Alias.BaseUrl + resource.Url; - scripts.Add(new { href = url, bundle = resource.Bundle ?? "", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", es6module = resource.ES6Module, location = resource.Location.ToString().ToLower() }); - } - else - { - inline += 1; - await interop.IncludeScript(GetType().Namespace.ToLower() + inline.ToString(), "", "", "", resource.Content, resource.Location.ToString().ToLower()); - } + var url = (resource.Url.Contains("://")) ? resource.Url : PageState.Alias.BaseUrl + resource.Url; + scripts.Add(new { href = url, bundle = resource.Bundle ?? "", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", es6module = resource.ES6Module, location = resource.Location.ToString().ToLower() }); } - if (scripts.Any()) + else { - await interop.IncludeScripts(scripts.ToArray()); + inline += 1; + await interop.IncludeScript(GetType().Namespace.ToLower() + inline.ToString(), "", "", "", resource.Content, resource.Location.ToString().ToLower()); } } + if (scripts.Any()) + { + await interop.IncludeScripts(scripts.ToArray()); + } } }