@gmickel/gno 1.30.1 → 1.30.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -47,11 +47,10 @@ type LoadOwnership = {
47
47
  /**
48
48
  * Load a PDF document from a same-origin asset URL.
49
49
  *
50
- * Teardown ownership (I3-04): loadingTask.destroy() owns the transport for a
51
- * load that never handed a proxy to the viewer. Once the proxy is viewer-owned,
52
- * we destroy the proxy exactly once and do not also call loadingTask.destroy.
53
- * documentDestroy is emitted exactly once per successfully loaded viewer
54
- * instance, never for rejected/never-loaded attempts.
50
+ * Teardown ownership (I3-04): loadingTask.destroy() owns the transport for the
51
+ * entire load lifecycle. documentDestroy is emitted exactly once per
52
+ * successfully loaded viewer instance, never for rejected/never-loaded
53
+ * attempts.
55
54
  */
56
55
  export function usePdfDocument(
57
56
  url: string | null,
@@ -125,29 +124,12 @@ export function usePdfDocument(
125
124
 
126
125
  /**
127
126
  * Idempotent teardown for this load.
128
- * - Never-loaded / rejected: destroy loading task only; no documentDestroy.
129
- * - Viewer-owned success: destroy proxy once + documentDestroy once.
130
- * - Stale late-resolved orphan (never viewer-owned): destroy proxy only.
127
+ * - Always destroy the loading task exactly once.
128
+ * - Emit documentDestroy only for a viewer-owned success.
129
+ * - A stale late resolution needs no separate proxy cleanup: the loading
130
+ * task already owns and destroys its transport.
131
131
  */
132
- const teardown = (opts?: {
133
- orphanProxy?: PDFDocumentProxy | null;
134
- reason: "cleanup" | "stale-orphan";
135
- }): void => {
136
- if (ownership.tornDown && !opts?.orphanProxy) {
137
- return;
138
- }
139
-
140
- if (opts?.orphanProxy && opts.reason === "stale-orphan") {
141
- // Resolved after we already tore down the load attempt — destroy the
142
- // orphan proxy only; never emit documentDestroy (never viewer-owned).
143
- try {
144
- void opts.orphanProxy.destroy();
145
- } catch {
146
- // ignore
147
- }
148
- return;
149
- }
150
-
132
+ const teardown = (): void => {
151
133
  if (ownership.tornDown) {
152
134
  return;
153
135
  }
@@ -157,33 +139,23 @@ export function usePdfDocument(
157
139
  ownership.viewerDoc = null;
158
140
 
159
141
  if (viewerDoc) {
160
- // Viewer owned the proxy: destroy it once. Do not also destroy the
161
- // loading task (that would double-destroy the same transport).
162
- try {
163
- void viewerDoc.destroy();
164
- } catch {
165
- // ignore
166
- }
167
142
  if (!ownership.destroyMetricEmitted) {
168
143
  ownership.destroyMetricEmitted = true;
169
144
  metrics.recordDocumentDestroy({ docId: ownership.docId });
170
145
  }
171
- return;
172
146
  }
173
147
 
174
- // Never handed a proxy to the viewer — loading task owns the transport.
175
148
  try {
176
- void ownership.task.destroy();
149
+ void ownership.task.destroy().catch(() => undefined);
177
150
  } catch {
178
151
  // ignore
179
152
  }
180
- // No documentDestroy for never-loaded / rejected attempts.
181
153
  };
182
154
 
183
155
  loadingTask.promise
184
156
  .then(async (pdf) => {
185
157
  if (isStale()) {
186
- teardown({ orphanProxy: pdf, reason: "stale-orphan" });
158
+ teardown();
187
159
  return;
188
160
  }
189
161
  ownership.viewerDoc = pdf;
@@ -203,14 +175,14 @@ export function usePdfDocument(
203
175
  setDoc(null);
204
176
  setNumPages(0);
205
177
  setFirstPageReady(false);
206
- teardown({ reason: "cleanup" });
178
+ teardown();
207
179
  });
208
180
 
209
181
  return () => {
210
182
  if (ownershipRef.current === ownership) {
211
183
  ownershipRef.current = null;
212
184
  }
213
- teardown({ reason: "cleanup" });
185
+ teardown();
214
186
  };
215
187
  }, [url, retryToken, getDocument, classifyPdfError, getPdfMetrics]);
216
188
 
@@ -1 +0,0 @@
1
- 7f28a8daa50eec43dcd95d5af91002a5e25cd87682ff7c99905af8c9f3457b24 gno-browser-clipper-v1.30.1.zip