diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp index e0d87112858..ad6a9b30f60 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp @@ -587,11 +587,15 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ }); } + main_thread_event_loop().spin_processing_tasks_with_source_until(Task::Source::NavigationAndTraversal, [&] { + return changing_navigable_continuations.size() + completed_change_jobs == total_change_jobs; + }); + // 13. Let navigablesThatMustWaitBeforeHandlingSyncNavigation be an empty set. Vector> navigables_that_must_wait_before_handling_sync_navigation; // 14. While completedChangeJobs does not equal totalChangeJobs: - while (completed_change_jobs != total_change_jobs) { + while (!changing_navigable_continuations.is_empty()) { // NOTE: Synchronous navigations that are intended to take place before this traversal jump the queue at this point, // so they can be added to the correct place in traversable's session history entries before this traversal // potentially unloads their document. More details can be found here (https://html.spec.whatwg.org/multipage/browsing-the-web.html#sync-navigation-steps-queue-jumping-examples) @@ -617,17 +621,6 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ } } - // AD-HOC: Since currently populate_session_history_entry_document does not run in parallel - // we call spin_until to interrupt execution of this function and let document population - // to complete. - main_thread_event_loop().spin_processing_tasks_with_source_until(Task::Source::NavigationAndTraversal, [&] { - return !changing_navigable_continuations.is_empty() || completed_change_jobs == total_change_jobs; - }); - - if (changing_navigable_continuations.is_empty()) { - continue; - } - // 2. Let changingNavigableContinuation be the result of dequeuing from changingNavigableContinuations. auto changing_navigable_continuation = changing_navigable_continuations.dequeue(); @@ -703,6 +696,10 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ } } + main_thread_event_loop().spin_processing_tasks_with_source_until(Task::Source::NavigationAndTraversal, [&] { + return completed_change_jobs == total_change_jobs; + }); + // 15. Let totalNonchangingJobs be the size of nonchangingNavigablesThatStillNeedUpdates. auto total_non_changing_jobs = non_changing_navigables_that_still_need_updates.size();