AI-native design editor. Open-source Figma alternative.
fix: keep Safari's tabs on their own documents after a few switches (#1300)
Danila Poyarkov59956f826fbc
diff --git a/changes/1300/fixed.md b/changes/1300/fixed.mdnew file mode 100644index 000000000..6157b73a9--- /dev/null+++ b/changes/1300/fixed.md@@ -0,0 +1 @@+- Safari keeps each tab on its own document; after a few tab switches, every tab showed the canvas and layers of the tab before it.diff --git a/packages/vue/src/canvas/surface/gl-surface.ts b/packages/vue/src/canvas/surface/gl-surface.tsindex 3e4e3b226..26660dd80 100644--- a/packages/vue/src/canvas/surface/gl-surface.ts+++ b/packages/vue/src/canvas/surface/gl-surface.ts@@ -34,6 +34,23 @@ function parkingHandle(ck: CanvasKit): GLHandle | null {return handle}+/** Makes the parking context current, so CanvasKit lets go of the one it held. */+function park(ck: CanvasKit): void {+ const parking = parkingHandle(ck)+ if (!parking) return+ try {+ ck.MakeGrContext(parking)?.delete()+ } catch {+ // A browser drops a page's oldest WebGL contexts once it holds too many, as WebKit does after+ // a few tabs, and reports it only later; the parking context is the oldest, so it is the one+ // gone, and CanvasKit fails on it. A new parking context takes its place.+ ck.deleteContext(parking)+ parkingHandles.delete(ck)+ const replacement = parkingHandle(ck)+ if (replacement) ck.MakeGrContext(replacement)?.delete()+ }+}+/*** Unregisters a canvas's WebGL context from CanvasKit. `deleteContext` leaves CanvasKit holding* the last current context, which keeps the canvas, and every component its element reaches,@@ -47,9 +64,7 @@ export function releaseWebGLContext(const context = canvas ? (canvas.getContext('webgl2') ?? canvas.getContext('webgl')) : nullconst wasCurrent = context !== null && Reflect.get(ck, 'ctx') === contextck.deleteContext(handle)- if (!wasCurrent) return- const parking = parkingHandle(ck)- if (parking) ck.MakeGrContext(parking)?.delete()+ if (wasCurrent) park(ck)}export function sizeCanvas(