diff --git a/code/modules/tgui/tgui.dm b/code/modules/tgui/tgui.dm index 3499e05512a..333646719e8 100644 --- a/code/modules/tgui/tgui.dm +++ b/code/modules/tgui/tgui.dm @@ -32,6 +32,8 @@ var/list/initial_data /// The static data used to initialize the UI. var/list/initial_static_data + /// Holder for the json string, that is sent during the initial update + var/_initial_update /// The status/visibility of the UI. var/status = UI_INTERACTIVE /// Topic state used to determine status/interactability. @@ -118,7 +120,7 @@ // Replace template tokens with important UI data // NOTE: Intentional \ref usage; tgui datums can't/shouldn't // be tagged, so this is an effective unwrap - html = replacetextEx(html, "\[ref]", "\ref[src]") + html = replacetextEx(html, "\[tgui:ref]", "\ref[src]") // Open the window. user << browse(html, "window=[window_id];can_minimize=0;auto_format=0;[window_size][have_title_bar]") @@ -128,10 +130,17 @@ // be tagged, so this is an effective unwrap winset(user, window_id, "on-close=\"uiclose \ref[src]\"") - if(!initial_data) + // Pre-fetch initial state while browser is still loading in + // another thread + if(!initial_data) { initial_data = src_object.ui_data(user) - if(!initial_static_data) + } + if(!initial_static_data) { initial_static_data = src_object.ui_static_data(user) + } + _initial_update = url_encode(get_json( + initial_data, + initial_static_data)) SStgui.on_open(src) @@ -232,9 +241,7 @@ switch(action) if("tgui:initialize") - user << output( - url_encode(get_json(initial_data, initial_static_data)), - "[window_id].browser:initialize") + user << output(_initial_update, "[window_id].browser:update") initialized = TRUE if("tgui:view") if(params["screen"]) diff --git a/tgui/packages/tgui/index.js b/tgui/packages/tgui/index.js index 4cf8841e527..818158f0958 100644 --- a/tgui/packages/tgui/index.js +++ b/tgui/packages/tgui/index.js @@ -115,16 +115,12 @@ const setupApp = () => { }); // Subscribe for bankend updates - window.update = window.initialize = stateJson => { + window.update = stateJson => { // NOTE: stateJson can be an object only if called manually from console. // This is useful for debugging tgui in proper browsers, like Chrome. const state = typeof stateJson === 'string' ? parseStateJson(stateJson) : stateJson; - // Set window ref if it was not defined inline on the page - if (!window.__ref__) { - window.__ref__ = state?.config?.ref; - } // Backend update dispatches a store action store.dispatch(backendUpdate(state)); }; diff --git a/tgui/packages/tgui/public/tgui.html b/tgui/packages/tgui/public/tgui.html index 849cf7b73fc..cb363a98c55 100644 --- a/tgui/packages/tgui/public/tgui.html +++ b/tgui/packages/tgui/public/tgui.html @@ -3,18 +3,20 @@
- + + +