From bdf2c0397ebe7071eade74151e973b0415af8a48 Mon Sep 17 00:00:00 2001 From: Reece Browne Date: Thu, 4 Sep 2025 10:43:15 +0100 Subject: [PATCH] Fix invocation error --- frontend/src/types/fileContext.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/frontend/src/types/fileContext.ts b/frontend/src/types/fileContext.ts index 76b197e3b..e55ef3df8 100644 --- a/frontend/src/types/fileContext.ts +++ b/frontend/src/types/fileContext.ts @@ -102,15 +102,23 @@ export function createStirlingFile(file: File, id?: FileId): StirlingFile { const fileId = id || createFileId(); const quickKey = createQuickKey(file); - // Create a new object that inherits from the File instance - // This preserves all File methods and properties while avoiding binding issues - const stirlingFile = Object.assign( - Object.create(Object.getPrototypeOf(file)), // Proper prototype chain - file, // Copy all properties (enumerable and non-enumerable) - { fileId, quickKey } // Add our custom properties - ) as StirlingFile; + // Use Object.defineProperty to add properties while preserving the original File object + // This maintains proper method binding and avoids "Illegal invocation" errors + Object.defineProperty(file, 'fileId', { + value: fileId, + writable: false, + enumerable: true, + configurable: false + }); + + Object.defineProperty(file, 'quickKey', { + value: quickKey, + writable: false, + enumerable: true, + configurable: false + }); - return stirlingFile; + return file as StirlingFile; } // Extract FileIds from StirlingFile array