Skip to content

Fix NotFoundSetOnFormSubmit_ResponseNotStarted_SSR test and enhanced navigation timing issue #62541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Components/Web.JS/src/Boot.Web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ function boot(options?: Partial<WebStartOptions>) : Promise<void> {
},
};

attachComponentDescriptorHandler(rootComponentManager);
attachStreamingRenderingListener(options?.ssr, navigationEnhancementCallbacks);

if (!options?.ssr?.disableDomPreservation) {
attachProgressivelyEnhancedNavigationListener(navigationEnhancementCallbacks);
}

attachComponentDescriptorHandler(rootComponentManager);
attachStreamingRenderingListener(options?.ssr, navigationEnhancementCallbacks);

enableFocusOnNavigate(jsEventRegistry);

// Wait until the initial page response completes before activating interactive components.
Expand Down
19 changes: 19 additions & 0 deletions src/Components/Web.JS/src/Services/NavigationEnhancement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ const acceptHeader = 'text/html; blazor-enhanced-nav=on';
let currentEnhancedNavigationAbortController: AbortController | null;
let navigationEnhancementCallbacks: NavigationEnhancementCallbacks;
let performingEnhancedPageLoad: boolean;
let navigationEnhancementCallbacksPromise: Promise<NavigationEnhancementCallbacks> | null = null;
let navigationEnhancementCallbacksResolver: ((callbacks: NavigationEnhancementCallbacks) => void) | null = null;

// This gets initialized to the current URL when we load.
// After that, it gets updated every time we successfully complete a navigation.
let currentContentUrl = location.href;

// Initialize the promise for waiting for navigation enhancement callbacks
navigationEnhancementCallbacksPromise = new Promise<NavigationEnhancementCallbacks>((resolve) => {
navigationEnhancementCallbacksResolver = resolve;
});

export interface NavigationEnhancementCallbacks {
enhancedNavigationStarted: () => void;
documentUpdated: () => void;
Expand All @@ -58,6 +65,14 @@ export function hasNeverStartedAnyEnhancedPageLoad() {

export function attachProgressivelyEnhancedNavigationListener(callbacks: NavigationEnhancementCallbacks) {
navigationEnhancementCallbacks = callbacks;

// Resolve the promise so any waiting performEnhancedPageLoad calls can proceed
if (navigationEnhancementCallbacksResolver) {
navigationEnhancementCallbacksResolver(callbacks);
navigationEnhancementCallbacksResolver = null;
navigationEnhancementCallbacksPromise = null;
}

document.addEventListener('click', onDocumentClick);
document.addEventListener('submit', onDocumentSubmit);
window.addEventListener('popstate', onPopState);
Expand Down Expand Up @@ -195,6 +210,10 @@ function onDocumentSubmit(event: SubmitEvent) {
export async function performEnhancedPageLoad(internalDestinationHref: string, interceptedLink: boolean, fetchOptions?: RequestInit, treatAsRedirectionFromMethod?: 'get' | 'post', changeUrl: boolean = true) {
performingEnhancedPageLoad = true;

if (!navigationEnhancementCallbacks && navigationEnhancementCallbacksPromise) {
navigationEnhancementCallbacks = await navigationEnhancementCallbacksPromise;
}

// First, stop any preceding enhanced page load
currentEnhancedNavigationAbortController?.abort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private void AssertNotFoundRendered_ResponseStarted_Or_POST(bool hasReExecutionM
public void NotFoundSetOnFormSubmit_ResponseNotStarted_SSR(bool hasReExecutionMiddleware, bool hasCustomNotFoundPageSet)
{
string reexecution = hasReExecutionMiddleware ? "/reexecution" : "";
string testUrl = $"{ServerPathBase}{reexecution}/post-not-found-ssr-streaming?useCustomNotFoundPage={hasCustomNotFoundPageSet}";
string testUrl = $"{ServerPathBase}{reexecution}/post-not-found-ssr?useCustomNotFoundPage={hasCustomNotFoundPageSet}";
Navigate(testUrl);
Browser.FindElement(By.Id("not-found-form")).FindElement(By.TagName("button")).Click();

Expand Down
Loading