diff --git a/.changeset/few-crews-brake.md b/.changeset/few-crews-brake.md
new file mode 100644
index 00000000000..cf5cf50946e
--- /dev/null
+++ b/.changeset/few-crews-brake.md
@@ -0,0 +1,5 @@
+---
+"@smithy/middleware-stack": patch
+---
+
+check calls to external instances of middlewareStack
diff --git a/packages/middleware-stack/src/MiddlewareStack.spec.ts b/packages/middleware-stack/src/MiddlewareStack.spec.ts
index a5baa098072..962c5730d28 100644
--- a/packages/middleware-stack/src/MiddlewareStack.spec.ts
+++ b/packages/middleware-stack/src/MiddlewareStack.spec.ts
@@ -370,6 +370,22 @@ describe("MiddlewareStack", () => {
});
});
+ it("checks identifyOnResolve calls to external instances due to version mismatching", () => {
+ const newStack = constructStack();
+ const oldStack = constructStack();
+
+ delete (oldStack as any).identifyOnResolve;
+ oldStack.clone = () => oldStack;
+ oldStack.concat = (stack: S) => oldStack as S;
+ oldStack.applyToStack = () => void 0;
+
+ expect(oldStack.identifyOnResolve).toBeUndefined();
+ expect(() => {
+ newStack.concat(oldStack);
+ newStack.clone();
+ }).not.toThrow();
+ });
+
describe("use", () => {
it("should apply customizations from pluggables", async () => {
const stack = constructStack();
diff --git a/packages/middleware-stack/src/MiddlewareStack.ts b/packages/middleware-stack/src/MiddlewareStack.ts
index 30108b3e3ba..92f292ef83e 100644
--- a/packages/middleware-stack/src/MiddlewareStack.ts
+++ b/packages/middleware-stack/src/MiddlewareStack.ts
@@ -69,7 +69,7 @@ export const constructStack = (): M
//@ts-ignore
toStack.addRelativeTo(entry.middleware, { ...entry });
});
- toStack.identifyOnResolve(stack.identifyOnResolve());
+ toStack.identifyOnResolve?.(stack.identifyOnResolve());
return toStack;
};
@@ -239,7 +239,9 @@ export const constructStack = (): M
): MiddlewareStack => {
const cloned = cloneTo(constructStack());
cloned.use(from);
- cloned.identifyOnResolve(identifyOnResolve || cloned.identifyOnResolve() || from.identifyOnResolve());
+ cloned.identifyOnResolve(
+ identifyOnResolve || cloned.identifyOnResolve() || (from.identifyOnResolve?.() ?? false)
+ );
return cloned;
},