Skip to content

Commit

Permalink
improve generation of unique tab IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Oct 15, 2024
1 parent 9fd61dd commit 09ab101
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions nicegui/static/nicegui.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ function createRandomUUID() {
}
}

const TAB_ID =
!sessionStorage.__nicegui_tab_id || sessionStorage.__nicegui_tab_closed === "false"
? (sessionStorage.__nicegui_tab_id = createRandomUUID())
: sessionStorage.__nicegui_tab_id;
sessionStorage.__nicegui_tab_closed = "false";
window.onbeforeunload = function () {
sessionStorage.__nicegui_tab_closed = "true";
};

function createApp(elements, options) {
replaceUndefinedAttributes(elements, 0);
return (app = Vue.createApp({
Expand All @@ -319,12 +328,7 @@ function createApp(elements, options) {
window.did_handshake = false;
const messageHandlers = {
connect: () => {
let tabId = sessionStorage.getItem("__nicegui_tab_id");
if (!tabId) {
tabId = createRandomUUID();
sessionStorage.setItem("__nicegui_tab_id", tabId);
}
window.socket.emit("handshake", { client_id: window.clientId, tab_id: tabId }, (ok) => {
window.socket.emit("handshake", { client_id: window.clientId, tab_id: TAB_ID }, (ok) => {
if (!ok) {
console.log("reloading because handshake failed for clientId " + window.clientId);
window.location.reload();
Expand Down

0 comments on commit 09ab101

Please sign in to comment.