unoplatform/uno · error · Error

The staged content was released when the download was trigge

Error message

The staged content was released when the download was triggered.

What it means

Thrown by NativeChunkedBuffer.throwIfReleased when _released is true. The buffer is released (line 158) inside the download trigger flow after its chunks have been written to a Blob or OPFS file and a download URL created. Once released, the buffer's content has been handed off and any further write/read is invalid — the internal _chunks array has been cleared.

Source

Thrown at src/Uno.UWP/ts/Windows/Storage/Streams/NativeChunkedBuffer.ts:258

				remaining -= n;
			}
			return new Blob(parts);
		}

		private static async tryGetDownloadDirectoryAsync(): Promise<FileSystemDirectoryHandle> {
			try {
				const root = await navigator.storage.getDirectory();
				return await root.getDirectoryHandle(NativeChunkedBuffer.DownloadFolderName, { create: true });
			}
			catch (e) {
				return null;
			}
		}


		private throwIfReleased(): void {
			if (this._released) {
				throw new Error("The staged content was released when the download was triggered.");
			}
		}

		private ensureCapacity(bytes: number): void {
			const chunkSize = NativeChunkedBuffer._chunkSize;
			const requiredChunks = Math.ceil(bytes / chunkSize);
			while (this._chunks.length < requiredChunks) {
				this._chunks.push(new Uint8Array(chunkSize));
			}
		}
	}
}

View on GitHub (pinned to 0418340488)

Solutions

  1. Do not write to or re-download from a buffer after triggerDownload has been called — create a new buffer for each download.
  2. Ensure all data is fully written before invoking the download trigger.
  3. Check the buffer lifecycle: if the managed code closes the stream before the download, sequence the operations so writes complete first.

Example fix

// before: reuse buffer after download
buffer.triggerDownload('file.bin');
buffer.write(data); // _released === true → throws

// after: create a new buffer for each download
buffer.triggerDownload('file.bin');
const next = new NativeChunkedBuffer();
next.write(data);
Defensive patterns

Strategy: validation

Validate before calling

// Before writing, check the buffer hasn't been released by a download
if ((buffer as any)._released) {
    // create a new buffer instead of writing to a released one
    return new NativeChunkedBuffer();
}

Try / catch

try {
    buffer.write(data);
} catch (e) {
    if (e.message.includes('released')) {
        // download already triggered — create a new buffer
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling any write or append method on the NativeChunkedBuffer after triggerDownload has already executed (which sets _released = true and clears _chunks), or attempting a second download from the same buffer instance.

Common situations: Reusing the same IOutputStream/buffer for multiple downloads without creating a new buffer; a race where data is still being written when the download is triggered; calling WriteAsync after the stream was closed and the download fired.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/2cbb93f9997d9d8b. Report an issue: GitHub.