mirror of
https://github.com/quartz-community/graph.git
synced 2026-07-22 02:50:25 +00:00
fix: handle WebGL context loss on navigation and strip base path for non-root domains
- Wrap PixiJS app.destroy() in try/catch so cleanup completes even when WebGL context is lost during SPA navigation, preventing empty graph - Strip base path from URL-derived slugs so content index keys match on non-root deployments (e.g. user.github.io/quartz)
This commit is contained in:
parent
2536c6a5db
commit
05bf33de90
5 changed files with 29 additions and 16 deletions
6
dist/components/index.js
vendored
6
dist/components/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/components/index.js.map
vendored
2
dist/components/index.js.map
vendored
File diff suppressed because one or more lines are too long
6
dist/index.js
vendored
6
dist/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,12 +1,23 @@
|
|||
// @ts-nocheck
|
||||
import {
|
||||
removeAllChildren,
|
||||
getBasePath,
|
||||
getFullSlugFromUrl,
|
||||
simplifySlug,
|
||||
resolveBasePath,
|
||||
} from "@quartz-community/utils";
|
||||
|
||||
(function () {
|
||||
function getSlugFromUrl() {
|
||||
var slug = getFullSlugFromUrl();
|
||||
var base = getBasePath();
|
||||
if (base && slug.startsWith(base.replace(/^\//, ""))) {
|
||||
slug = slug.slice(base.replace(/^\//, "").length);
|
||||
if (slug.startsWith("/")) slug = slug.slice(1);
|
||||
}
|
||||
return slug;
|
||||
}
|
||||
|
||||
function loadScript(src) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var script = document.createElement("script");
|
||||
|
|
@ -579,7 +590,13 @@ import {
|
|||
return function () {
|
||||
stopAnimation = true;
|
||||
simulation.stop();
|
||||
app.destroy(true);
|
||||
try {
|
||||
app.destroy(true);
|
||||
} catch (e) {
|
||||
// PixiJS may throw if WebGL context was already lost (e.g. during SPA navigation).
|
||||
// Swallow the error so cleanup completes and the graph can re-render.
|
||||
console.warn("[Graph] PixiJS destroy failed (WebGL context likely lost):", e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -629,7 +646,7 @@ import {
|
|||
|
||||
function showGlobalGraph() {
|
||||
cleanupGlobal();
|
||||
var currentSlug = getFullSlugFromUrl();
|
||||
var currentSlug = getSlugFromUrl();
|
||||
for (var i = 0; i < globalContainers.length; i++) {
|
||||
var container = globalContainers[i];
|
||||
container.classList.add("active");
|
||||
|
|
@ -664,7 +681,7 @@ import {
|
|||
function renderLocal() {
|
||||
cleanupLocal();
|
||||
var thisGeneration = ++currentRenderGeneration;
|
||||
var slug = getFullSlugFromUrl();
|
||||
var slug = getSlugFromUrl();
|
||||
addToVisited(slug);
|
||||
|
||||
var localContainers = document.querySelectorAll(".graph-container");
|
||||
|
|
@ -684,7 +701,7 @@ import {
|
|||
}
|
||||
|
||||
function handleNav(e) {
|
||||
var slug = e.detail ? e.detail.url : getFullSlugFromUrl();
|
||||
var slug = e.detail ? e.detail.url : getSlugFromUrl();
|
||||
addToVisited(simplifySlug(slug));
|
||||
|
||||
renderLocal();
|
||||
|
|
@ -744,10 +761,10 @@ import {
|
|||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
handleNav({ detail: { url: getFullSlugFromUrl() } });
|
||||
handleNav({ detail: { url: getSlugFromUrl() } });
|
||||
});
|
||||
} else {
|
||||
handleNav({ detail: { url: getFullSlugFromUrl() } });
|
||||
handleNav({ detail: { url: getSlugFromUrl() } });
|
||||
}
|
||||
document.addEventListener("nav", handleNav);
|
||||
document.addEventListener("render", handleNav);
|
||||
|
|
|
|||
Loading…
Reference in a new issue