From 99422df857e49c5dda416a0f14749f7aa599bd11 Mon Sep 17 00:00:00 2001 From: Hanif Koh Date: Wed, 16 Sep 2026 14:09:46 +0800 Subject: [PATCH] Restore Plugin HTML After a WebKit Reload Plugin dialog content is injected with SetPage, so on the WebKit backends a reload (context menu, keyboard shortcut or location.reload()) re-fetches the SetPage base URL instead of the injected document, and the plugin UI is gone for good: load_plugin_content() returned early once m_content_loaded was set. On GTK and macOS, re-inject the plugin HTML when a main-frame load arrives after the initial swap. m_own_page_load marks the load caused by our own SetPage so it is not mistaken for a reload, and a post-load error is left alone, as it only ever means a failed subresource. MSW is left out: WebView2 reloads NavigateToString content from its own history entry, so the page already survives a reload there, and the backend reports in-document navigation (a page setting location.hash) as a load, which re-injection would turn into a page wipe. --- src/slic3r/GUI/PluginWebDialog.cpp | 25 +++++++++++++++++++------ src/slic3r/GUI/PluginWebDialog.hpp | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/PluginWebDialog.cpp b/src/slic3r/GUI/PluginWebDialog.cpp index d89aac7270..b8e0a7756b 100644 --- a/src/slic3r/GUI/PluginWebDialog.cpp +++ b/src/slic3r/GUI/PluginWebDialog.cpp @@ -139,19 +139,32 @@ void PluginWebDialog::destroy_for_plugin(PluginWebDialog* dialog) void PluginWebDialog::on_bootstrap_event(wxWebViewEvent& event) { - // The first bootstrap load (or its error) triggers the swap to plugin HTML; - // the resulting plugin-page load is ignored (guarded by m_content_loaded). - load_plugin_content(); + // The first bootstrap load (or its error) triggers the swap to plugin HTML. + if (!m_content_loaded) + load_plugin_content(); +#ifndef __WXMSW__ + // WebKit reloads the SetPage base URL rather than the injected page, so a later main-frame + // load that is not our own SetPage is a browser reload, and the plugin HTML has to be put + // back. A post-load error only ever means a failed subresource. WebView2 reloads SetPage + // content from its own history entry, and reports in-document navigation as a load, so + // MSW needs neither the re-injection nor a guard against it. + else if (event.GetEventType() == wxEVT_WEBVIEW_LOADED) { + if (m_own_page_load) + m_own_page_load = false; + else + load_plugin_content(); + } +#endif event.Skip(); } void PluginWebDialog::load_plugin_content() { - if (m_content_loaded) - return; m_content_loaded = true; - if (wxWebView* wv = browser()) + if (wxWebView* wv = browser()) { + m_own_page_load = true; wv->SetPage(wxString::FromUTF8(m_html), web_base_url()); + } } void PluginWebDialog::on_script_message(const nlohmann::json& payload) diff --git a/src/slic3r/GUI/PluginWebDialog.hpp b/src/slic3r/GUI/PluginWebDialog.hpp index 05f77f5148..50dd276621 100644 --- a/src/slic3r/GUI/PluginWebDialog.hpp +++ b/src/slic3r/GUI/PluginWebDialog.hpp @@ -72,6 +72,7 @@ private: std::string m_html; bool m_content_loaded{false}; + bool m_own_page_load{false}; // a SetPage of the plugin HTML is in flight bool m_open{true}; bool m_close_fired{false}; std::optional m_result;