From ac48222ed7b497b13343ec79a234ba432ffd29e2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 14 Oct 2024 07:45:19 +0200 Subject: [PATCH] LibWeb: Recompute targetStep during "apply the history step" This is an ad-hoc change to account for the fact that we may run arbitrary code while waiting for the tasks in this function to complete. I don't have a way to reproduce it, but I've seen trouble caused by navigables disappearing, which causes the history step numbers to be disturbed. --- Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp index 7ffccdebb49..7f0b9219840 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp @@ -704,6 +704,10 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ if (navigable->has_been_destroyed()) continue; + // AD-HOC: We re-compute targetStep here, since it might have changed since the last time we computed it. + // This can happen if navigables are destroyed while we wait for tasks to complete. + target_step = get_the_used_step(step); + // 7. Let (scriptHistoryLength, scriptHistoryIndex) be the result of getting the history object length and index given traversable and targetStep. auto history_object_length_and_index = get_the_history_object_length_and_index(target_step); auto script_history_length = history_object_length_and_index.script_history_length;