|
|
|
@ -1,4 +1,6 @@ |
|
|
|
@implements IDisposable |
|
|
|
@inject IComponentBundleManager BundleManager |
|
|
|
@inject PersistentComponentState ApplicationState |
|
|
|
@if (ScriptFiles != null) |
|
|
|
{ |
|
|
|
foreach (var file in ScriptFiles) |
|
|
|
@ -8,6 +10,9 @@ |
|
|
|
} |
|
|
|
|
|
|
|
@code { |
|
|
|
|
|
|
|
private const string PrerenderedKey = "abp_script_prerendered"; |
|
|
|
|
|
|
|
[Parameter] |
|
|
|
public List<string>? WebAssemblyScriptFiles { get; set; } |
|
|
|
|
|
|
|
@ -16,18 +21,34 @@ |
|
|
|
|
|
|
|
private List<string>? ScriptFiles { get; set; } |
|
|
|
|
|
|
|
private PersistingComponentStateSubscription _persistingSubscription; |
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync() |
|
|
|
{ |
|
|
|
ScriptFiles = new List<string>(); |
|
|
|
|
|
|
|
if (!BundleName.IsNullOrWhiteSpace()) |
|
|
|
_persistingSubscription = ApplicationState.RegisterOnPersisting(Callback); |
|
|
|
if (!ApplicationState.TryTakeFromJson<string>(PrerenderedKey, out _)) |
|
|
|
{ |
|
|
|
ScriptFiles = (await BundleManager.GetScriptBundleFilesAsync(BundleName!)).ToList(); |
|
|
|
// We are in prerendering mode |
|
|
|
ScriptFiles = []; |
|
|
|
if (!BundleName.IsNullOrWhiteSpace()) |
|
|
|
{ |
|
|
|
ScriptFiles = (await BundleManager.GetScriptBundleFilesAsync(BundleName!)).ToList(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (OperatingSystem.IsBrowser() && WebAssemblyScriptFiles != null) |
|
|
|
else |
|
|
|
{ |
|
|
|
ScriptFiles.AddIfNotContains(WebAssemblyScriptFiles); |
|
|
|
if (OperatingSystem.IsBrowser() && WebAssemblyScriptFiles != null) |
|
|
|
{ |
|
|
|
ScriptFiles = WebAssemblyScriptFiles; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private Task Callback() |
|
|
|
{ |
|
|
|
ApplicationState.PersistAsJson(PrerenderedKey, PrerenderedKey); |
|
|
|
return Task.CompletedTask; |
|
|
|
} |
|
|
|
|
|
|
|
public void Dispose() => _persistingSubscription.Dispose(); |
|
|
|
} |
|
|
|
|