fix(hazard_symbol): start fixing dual-package hazard symbol #436
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Dual Package Hazard with
Symbol.hasInstance
Status: Ready for Review
Problem
When a package is imported under both CommonJS and ESM, classes can be instantiated separately by each loader.
This causes
instanceof
checks to fail across boundaries, even when dealing with the same logical class.Solution
Each class was updated with:
A unique marker property attached to the instance.
A custom Symbol.hasInstance method that checks for the marker, ensuring instanceof works reliably across CJS/ESM boundaries.
`export class SomeClass {
private readonly _isSomeClass = true
static [Symbol.hasInstance](instance: unknown): boolean {
return !!(instance && (instance as any)._isSomeClass === true)
}
}`
Updated Classes
The fix has now been applied to all classes in the project:
./types/account.ts:20 — MultisigAccount
./types/account.ts:79 — SigningAccount
./types/app-arc56.ts:23 — Arc56Method
./types/app-client.ts:478 — AppClient
./types/app-client.ts:1794 — ApplicationClient
./types/app-manager.ts:98 — AppManager
./types/account-manager.ts:46 — AccountManager
./types/algorand-client-transaction-sender.ts:36 — AlgorandClientTransactionSender
./types/app-deployer.ts:112 — AppDeployer
./types/logic-error.ts:22 — LogicError
./types/client-manager.ts:48 — ClientManager
./types/algorand-client.ts:18 — AlgorandClient
./types/async-event-emitter.ts:5 — AsyncEventEmitter
./types/kmd-account-manager.ts:10 — KmdAccountManager
./types/algorand-client-transaction-creator.ts:8 — AlgorandClientTransactionCreator
./types/composer.ts:547 — TransactionComposer
./types/algo-http-client-with-retry.ts:6 — AlgoHttpClientWithRetry
./types/dispenser-client.ts:72 — TestNetDispenserApiClient
./types/config.ts:28 — UpdatableConfig
./types/amount.ts:4 — AlgoAmount
./types/asset-manager.ts:138 — AssetManager
./types/app-factory.ts:170 — AppFactory
./testing/test-logger.ts:8 — TestLogger
./testing/transaction-logger.ts:12 — TransactionLogger
./util.ts:25 — UnsafeConversionError
Tests
Added dual-package-hazard.spec.ts to validate cross-module instanceof between CJS and ESM.