From 02c22c18942e481f770f6f3c080eecd9cd60a3f1 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Fri, 5 Jan 2024 11:49:57 -0500 Subject: [PATCH] improved rendering optimization --- Oqtane.Client/Modules/HtmlText/Index.razor | 2 +- Oqtane.Client/Modules/ModuleBase.cs | 5 +++++ Oqtane.Client/Themes/ContainerBase.cs | 6 +++++- Oqtane.Client/UI/ContainerBuilder.razor | 7 ++++++- Oqtane.Client/UI/ModuleInstance.razor | 7 ++++++- Oqtane.Client/UI/PageState.cs | 8 +------- Oqtane.Client/UI/Pane.razor | 3 +++ Oqtane.Client/UI/SiteRouter.razor | 4 ++-- Oqtane.Shared/Models/Module.cs | 2 +- 9 files changed, 30 insertions(+), 14 deletions(-) diff --git a/Oqtane.Client/Modules/HtmlText/Index.razor b/Oqtane.Client/Modules/HtmlText/Index.razor index b02ee9ff..91efe2bb 100644 --- a/Oqtane.Client/Modules/HtmlText/Index.razor +++ b/Oqtane.Client/Modules/HtmlText/Index.razor @@ -21,7 +21,7 @@ { try { - if (PageState.RenderModuleInstance(ModuleState)) + if (ShouldRender()) { var htmltext = await HtmlTextService.GetHtmlTextAsync(ModuleState.ModuleId); if (htmltext != null) diff --git a/Oqtane.Client/Modules/ModuleBase.cs b/Oqtane.Client/Modules/ModuleBase.cs index 9825a334..79c00367 100644 --- a/Oqtane.Client/Modules/ModuleBase.cs +++ b/Oqtane.Client/Modules/ModuleBase.cs @@ -113,6 +113,11 @@ namespace Oqtane.Modules } } + protected override bool ShouldRender() + { + return PageState.RenderId == ModuleState.RenderId; + } + // path method public string ModulePath() diff --git a/Oqtane.Client/Themes/ContainerBase.cs b/Oqtane.Client/Themes/ContainerBase.cs index a35c1478..d05f3610 100644 --- a/Oqtane.Client/Themes/ContainerBase.cs +++ b/Oqtane.Client/Themes/ContainerBase.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components; using Oqtane.Models; namespace Oqtane.Themes @@ -8,5 +8,9 @@ namespace Oqtane.Themes [CascadingParameter] protected Module ModuleState { get; set; } + protected override bool ShouldRender() + { + return PageState.RenderId == ModuleState.RenderId; + } } } diff --git a/Oqtane.Client/UI/ContainerBuilder.razor b/Oqtane.Client/UI/ContainerBuilder.razor index 4d895570..1607ea18 100644 --- a/Oqtane.Client/UI/ContainerBuilder.razor +++ b/Oqtane.Client/UI/ContainerBuilder.razor @@ -30,6 +30,11 @@ [Parameter] public Module ModuleState { get; set; } + protected override bool ShouldRender() + { + return PageState.RenderId == ModuleState.RenderId; + } + protected override void OnInitialized() { ((INotifyPropertyChanged)SiteState.Properties).PropertyChanged += PropertyChanged; @@ -52,7 +57,7 @@ _useadminborder = false; } - if (PageState.RenderModuleInstance(ModuleState)) + if (ShouldRender()) { ComponentType = Type.GetType(container) ?? Type.GetType(Constants.DefaultContainer); } diff --git a/Oqtane.Client/UI/ModuleInstance.razor b/Oqtane.Client/UI/ModuleInstance.razor index 7c45a106..6bffb143 100644 --- a/Oqtane.Client/UI/ModuleInstance.razor +++ b/Oqtane.Client/UI/ModuleInstance.razor @@ -48,10 +48,15 @@ else private ModuleMessage ModuleMessage { get; set; } + protected override bool ShouldRender() + { + return PageState.RenderId == ModuleState.RenderId; + } + protected override void OnParametersSet() { _message = ""; - if (PageState.RenderModuleInstance(ModuleState)) + if (ShouldRender()) { if (!string.IsNullOrEmpty(ModuleState.ModuleType)) { diff --git a/Oqtane.Client/UI/PageState.cs b/Oqtane.Client/UI/PageState.cs index 86c3d5a1..7de88d96 100644 --- a/Oqtane.Client/UI/PageState.cs +++ b/Oqtane.Client/UI/PageState.cs @@ -23,6 +23,7 @@ namespace Oqtane.UI public string RemoteIPAddress { get; set; } public string ReturnUrl { get; set; } public bool IsInternalNavigation { get; set; } + public Guid RenderId { get; set; } public List Pages { @@ -36,12 +37,5 @@ namespace Oqtane.UI { get { return Site.Languages; } } - - - // determines if the PageState matches the ModuleState for component rendering purposes - public bool RenderModuleInstance(Module ModuleState) - { - return Page.PageId == ModuleState.PageId && (ModuleId == -1 || ModuleId == ModuleState.ModuleId) && Action == ModuleState.Action; - } } } diff --git a/Oqtane.Client/UI/Pane.razor b/Oqtane.Client/UI/Pane.razor index ed487f24..3c35ffac 100644 --- a/Oqtane.Client/UI/Pane.razor +++ b/Oqtane.Client/UI/Pane.razor @@ -45,6 +45,9 @@ else { foreach (Module module in PageState.Modules.Where(item => item.PageId == PageState.Page.PageId)) { + // set renderid - this allows the framework to determine which components should be rendered when PageState changes + module.RenderId = PageState.RenderId; + var pane = module.Pane; if (module.ModuleId == PageState.ModuleId && PageState.Action != Constants.DefaultAction) { diff --git a/Oqtane.Client/UI/SiteRouter.razor b/Oqtane.Client/UI/SiteRouter.razor index b538afb1..692e7e6d 100644 --- a/Oqtane.Client/UI/SiteRouter.razor +++ b/Oqtane.Client/UI/SiteRouter.razor @@ -289,7 +289,8 @@ VisitorId = VisitorId, RemoteIPAddress = SiteState.RemoteIPAddress, ReturnUrl = returnurl, - IsInternalNavigation = _isInternalNavigation + IsInternalNavigation = _isInternalNavigation, + RenderId = Guid.NewGuid() }; OnStateChange?.Invoke(_pagestate); @@ -508,7 +509,6 @@ } module.PaneModuleIndex = paneindex[module.Pane.ToLower()]; - module.Action = action; // container fallback if (string.IsNullOrEmpty(module.ContainerType)) diff --git a/Oqtane.Shared/Models/Module.cs b/Oqtane.Shared/Models/Module.cs index 49c35ded..832afe69 100644 --- a/Oqtane.Shared/Models/Module.cs +++ b/Oqtane.Shared/Models/Module.cs @@ -86,7 +86,7 @@ namespace Oqtane.Models [NotMapped] public int PaneModuleCount { get; set; } [NotMapped] - public string Action { get; set; } + public Guid RenderId { get; set; } #endregion