-
Notifications
You must be signed in to change notification settings - Fork 83
Description
🐛 Bug Description
In commit 7aa5c28 ("Remove events queries from SDK #745"), the Event class was deleted from src/api/event.ts, but two references to it were accidentally left behind in src/api/aptos.ts:
Line 121 - Interface extension includes Event
Line 163 - Mixin call applyMixin(Aptos, Event, "event")
Since there is no import for Event, these references resolve to the global browser Event constructor. This works in browsers and Node.js 15+, but React Native lacks a global Event class, causing:
ReferenceError: Property 'Event' doesn't exist
How to reproduce
You can prove the Aptos class extends the global Event class via an orphaned Mixin by building the SDK and running the below script:
/**
* Test script to validate that Aptos client is NOT extending
* the global Event class (which would be a bug)
*
* Run with: node test-rn-compat.mjs
*/
console.log("Checking if SDK incorrectly extends global Event class...\n");
const sdk = await import("./dist/esm/index.mjs");
const aptos = new sdk.Aptos();
// Check if Aptos prototype has methods from global Event
// These are actual methods on Event.prototype
const eventMethods = ['stopPropagation', 'preventDefault', 'stopImmediatePropagation', 'composedPath', 'initEvent'];
const hasGlobalEventMethods = eventMethods.some(
method => typeof aptos[method] === 'function'
);
if (hasGlobalEventMethods) {
console.log("FAILED: Aptos client has global Event methods mixed in!");
console.log("Found methods:", eventMethods.filter(m => typeof aptos[m] === 'function'));
process.exit(1);
} else {
console.log("SUCCESS: Aptos client does NOT extend global Event class");
}
You'll get the printout: FAILED: Aptos client has global Event methods mixed in!
You can further test this by removing the global Event class:
/**
* Test script to simulate React Native environment
* (which lacks the global Event class)
*
* Run with: node test-rn-compat.mjs
*/
// Save original Event
const originalEvent = globalThis.Event;
// Simulate React Native by removing global Event
delete globalThis.Event;
console.log("Global Event exists:", typeof globalThis.Event !== "undefined");
console.log("Attempting to import SDK...\n");
try {
// Dynamic import to test after Event is removed
const sdk = await import("./dist/esm/index.mjs");
console.log("SUCCESS: SDK loaded without errors!");
console.log("Aptos class available:", typeof sdk.Aptos === "function");
} catch (error) {
console.log("FAILED:", error.message);
} finally {
// Restore Event
globalThis.Event = originalEvent;
}
You will get FAILED:
Expected Behavior
System information
System details:
-
Typescript SDK Version:
5.1.5 -
Platform (e.g. Node, browser, etc.)
v20.18.0