Skip to content

Commit 118f31a

Browse files
committed
Address feedback
1 parent 7cf7943 commit 118f31a

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

src/Components/Endpoints/src/DependencyInjection/RazorComponentsServiceCollectionExtensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics.CodeAnalysis;
5+
using System.Reflection.Metadata;
56
using Microsoft.AspNetCore.Components;
67
using Microsoft.AspNetCore.Components.Endpoints;
78
using Microsoft.AspNetCore.Components.Endpoints.DependencyInjection;
@@ -45,7 +46,10 @@ public static IRazorComponentsBuilder AddRazorComponents(this IServiceCollection
4546
// Endpoints
4647
services.TryAddSingleton<RazorComponentEndpointDataSourceFactory>();
4748
services.TryAddSingleton<RazorComponentEndpointFactory>();
48-
services.TryAddSingleton<HotReloadService>();
49+
if (MetadataUpdater.IsSupported)
50+
{
51+
services.TryAddSingleton<HotReloadService>();
52+
}
4953
services.TryAddScoped<IRazorComponentEndpointInvoker, RazorComponentEndpointInvoker>();
5054

5155
// Common services required for components server side rendering

src/Components/Web.JS/dist/Release/blazor.server.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/dist/Release/blazor.web.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/dist/Release/blazor.webview.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/src/Boot.Web.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { attachStreamingRenderingListener } from './Rendering/StreamingRendering
1818
import { attachProgressivelyEnhancedNavigationListener } from './Services/NavigationEnhancement';
1919
import { WebRootComponentManager } from './Services/WebRootComponentManager';
2020
import { attachComponentDescriptorHandler, registerAllComponentDescriptors } from './Rendering/DomMerging/DomSync';
21+
import { hasProgrammaticEnhancedNavigationHandler, performProgrammaticEnhancedNavigation } from './Services/NavigationUtils';
2122

2223
let started = false;
2324
const rootComponentManager = new WebRootComponentManager();
@@ -30,6 +31,14 @@ function boot(options?: Partial<WebStartOptions>) : Promise<void> {
3031
started = true;
3132

3233
Blazor._internal.loadWebAssemblyQuicklyTimeout = 3000;
34+
// Definedh ere to avoid inadvertently imported enhanced navigation
35+
// related APIs in WebAssembly or Blazor Server contexts.
36+
Blazor._internal.hotReloadApplied = () => {
37+
if (hasProgrammaticEnhancedNavigationHandler())
38+
{
39+
performProgrammaticEnhancedNavigation(location.href, false);
40+
}
41+
}
3342

3443
setCircuitOptions(options?.circuit);
3544
setWebAssemblyOptions(options?.webAssembly);

src/Components/Web.JS/src/GlobalExports.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { RootComponentsFunctions } from './Rendering/JSRootComponents';
1818
import { attachWebRendererInterop } from './Rendering/WebRendererInteropMethods';
1919
import { WebStartOptions } from './Platform/WebStartOptions';
2020
import { RuntimeAPI } from 'dotnet';
21-
import { hasProgrammaticEnhancedNavigationHandler, performProgrammaticEnhancedNavigation } from './Services/NavigationUtils';
2221

2322
// TODO: It's kind of hard to tell which .NET platform(s) some of these APIs are relevant to.
2423
// It's important to know this information when dealing with the possibility of mulitple .NET platforms being available.
@@ -87,8 +86,7 @@ interface IBlazor {
8786
// APIs invoked by hot reload
8887
applyHotReload?: (id: string, metadataDelta: string, ilDelta: string, pdbDelta: string | undefined) => void;
8988
getApplyUpdateCapabilities?: () => string;
90-
performProgrammaticEnhancedNavigation: (absoluteInternalHref: string, replace: boolean) => void;
91-
hasProgrammaticEnhancedNavigationHandler: () => boolean;
89+
hotReloadApplied?: () => void;
9290
}
9391
}
9492

@@ -106,9 +104,7 @@ export const Blazor: IBlazor = {
106104
InputFile,
107105
NavigationLock,
108106
getJSDataStreamChunk: getNextChunk,
109-
attachWebRendererInterop,
110-
performProgrammaticEnhancedNavigation,
111-
hasProgrammaticEnhancedNavigationHandler
107+
attachWebRendererInterop
112108
},
113109
};
114110

0 commit comments

Comments
 (0)