Skip to content

Commit 20dd741

Browse files
Copilotilonatommy
andcommitted
Fix NotFoundSetOnFormSubmit_ResponseNotStarted_SSR test URL and enhance navigation timing
Co-authored-by: ilonatommy <[email protected]>
1 parent 3702136 commit 20dd741

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ function boot(options?: Partial<WebStartOptions>) : Promise<void> {
6565
},
6666
};
6767

68-
attachComponentDescriptorHandler(rootComponentManager);
69-
attachStreamingRenderingListener(options?.ssr, navigationEnhancementCallbacks);
70-
68+
// Initialize enhanced navigation as early as possible to prevent timing issues
7169
if (!options?.ssr?.disableDomPreservation) {
7270
attachProgressivelyEnhancedNavigationListener(navigationEnhancementCallbacks);
7371
}
7472

73+
attachComponentDescriptorHandler(rootComponentManager);
74+
attachStreamingRenderingListener(options?.ssr, navigationEnhancementCallbacks);
75+
7576
enableFocusOnNavigate(jsEventRegistry);
7677

7778
// Wait until the initial page response completes before activating interactive components.

src/Components/Web.JS/src/Services/NavigationEnhancement.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@ different bundles that only contain minimal content.
3535
const acceptHeader = 'text/html; blazor-enhanced-nav=on';
3636

3737
let currentEnhancedNavigationAbortController: AbortController | null;
38-
let navigationEnhancementCallbacks: NavigationEnhancementCallbacks;
38+
let navigationEnhancementCallbacks: Promise<NavigationEnhancementCallbacks>;
39+
let navigationEnhancementCallbacksResolver: (callbacks: NavigationEnhancementCallbacks) => void;
3940
let performingEnhancedPageLoad: boolean;
4041

42+
// Initialize the promise that will be resolved when callbacks are set
43+
navigationEnhancementCallbacks = new Promise<NavigationEnhancementCallbacks>((resolve) => {
44+
navigationEnhancementCallbacksResolver = resolve;
45+
});
46+
4147
// This gets initialized to the current URL when we load.
4248
// After that, it gets updated every time we successfully complete a navigation.
4349
let currentContentUrl = location.href;
@@ -57,7 +63,7 @@ export function hasNeverStartedAnyEnhancedPageLoad() {
5763
}
5864

5965
export function attachProgressivelyEnhancedNavigationListener(callbacks: NavigationEnhancementCallbacks) {
60-
navigationEnhancementCallbacks = callbacks;
66+
navigationEnhancementCallbacksResolver(callbacks);
6167
document.addEventListener('click', onDocumentClick);
6268
document.addEventListener('submit', onDocumentSubmit);
6369
window.addEventListener('popstate', onPopState);
@@ -201,8 +207,11 @@ export async function performEnhancedPageLoad(internalDestinationHref: string, i
201207
// Notify any interactive runtimes that an enhanced navigation is starting
202208
notifyEnhancedNavigationListeners(internalDestinationHref, interceptedLink);
203209

210+
// Wait for navigation enhancement callbacks to be initialized before proceeding
211+
const callbacks = await navigationEnhancementCallbacks;
212+
204213
// Notify handlers that enhanced navigation is starting
205-
navigationEnhancementCallbacks.enhancedNavigationStarted();
214+
callbacks.enhancedNavigationStarted();
206215

207216
// Now request the new page via fetch, and a special header that tells the server we want it to inject
208217
// framing boundaries to distinguish the initial document and each subsequent streaming SSR update.
@@ -305,7 +314,7 @@ export async function performEnhancedPageLoad(internalDestinationHref: string, i
305314
// For HTML responses, regardless of the status code, display it
306315
const parsedHtml = new DOMParser().parseFromString(initialContent, 'text/html');
307316
synchronizeDomContent(document, parsedHtml);
308-
navigationEnhancementCallbacks.documentUpdated();
317+
callbacks.documentUpdated();
309318
} else if (responseContentType?.startsWith('text/') && initialContent) {
310319
// For any other text-based content, we'll just display it, because that's what
311320
// would happen if this was a non-enhanced request.
@@ -344,7 +353,7 @@ export async function performEnhancedPageLoad(internalDestinationHref: string, i
344353
}
345354

346355
performingEnhancedPageLoad = false;
347-
navigationEnhancementCallbacks.enhancedNavigationCompleted();
356+
callbacks.enhancedNavigationCompleted();
348357

349358
// For non-GET requests, the destination has to be the same URL you're already on, or result in a redirection
350359
// (post/redirect/get). You're not allowed to POST to a different URL without redirecting, because then back/forwards

src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private void AssertNotFoundRendered_ResponseStarted_Or_POST(bool hasReExecutionM
205205
public void NotFoundSetOnFormSubmit_ResponseNotStarted_SSR(bool hasReExecutionMiddleware, bool hasCustomNotFoundPageSet)
206206
{
207207
string reexecution = hasReExecutionMiddleware ? "/reexecution" : "";
208-
string testUrl = $"{ServerPathBase}{reexecution}/post-not-found-ssr-streaming?useCustomNotFoundPage={hasCustomNotFoundPageSet}";
208+
string testUrl = $"{ServerPathBase}{reexecution}/post-not-found-ssr?useCustomNotFoundPage={hasCustomNotFoundPageSet}";
209209
Navigate(testUrl);
210210
Browser.FindElement(By.Id("not-found-form")).FindElement(By.TagName("button")).Click();
211211

0 commit comments

Comments
 (0)