From ce7995966d76f0769b11c6aec2333a1b429caa2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=97=9E=E5=AD=90=E5=86=8D?= Date: Wed, 12 Jan 2022 10:36:10 +0800 Subject: [PATCH] Fixed first render js bug Solve the problem that when the page is rendered for the first time and JS is executed, the reference to the JS file has not been successful, and the page is abnormally wrong --- Oqtane.Client/Modules/ModuleBase.cs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Oqtane.Client/Modules/ModuleBase.cs b/Oqtane.Client/Modules/ModuleBase.cs index f3f06aee..5b93c3c5 100644 --- a/Oqtane.Client/Modules/ModuleBase.cs +++ b/Oqtane.Client/Modules/ModuleBase.cs @@ -46,22 +46,19 @@ namespace Oqtane.Modules // base lifecycle method for handling JSInterop script registration - protected override async Task OnAfterRenderAsync(bool firstRender) + protected override async Task OnInitializedAsync() { - if (firstRender) + if (Resources != null && Resources.Exists(item => item.ResourceType == ResourceType.Script)) { - if (Resources != null && Resources.Exists(item => item.ResourceType == ResourceType.Script)) + var scripts = new List(); + foreach (Resource resource in Resources.Where(item => item.ResourceType == ResourceType.Script && item.Declaration != ResourceDeclaration.Global)) { - var scripts = new List(); - foreach (Resource resource in Resources.Where(item => item.ResourceType == ResourceType.Script && item.Declaration != ResourceDeclaration.Global)) - { - scripts.Add(new { href = resource.Url, bundle = resource.Bundle ?? "", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "" }); - } - if (scripts.Any()) - { - var interop = new Interop(JSRuntime); - await interop.IncludeScripts(scripts.ToArray()); - } + scripts.Add(new { href = resource.Url, bundle = resource.Bundle ?? "", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "" }); + } + if (scripts.Any()) + { + var interop = new Interop(JSRuntime); + await interop.IncludeScripts(scripts.ToArray()); } } }