Skip to content

Commit 3485351

Browse files
committed
fix: use duck typing to fix production bundle errors on left book club
1 parent d74ea7c commit 3485351

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

frontend/core/loader.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
Application,
3-
Controller,
4-
ControllerConstructor,
5-
} from "@hotwired/stimulus";
1+
import { Application, ControllerConstructor } from "@hotwired/stimulus";
62
import StimulusControllerResolver from "stimulus-controller-resolver";
73

84
/**
@@ -16,7 +12,7 @@ export function startApp(...modules: AsyncModuleMap[]) {
1612
const allModules: AsyncModuleMap = Object.assign(
1713
{},
1814
EXPORTED_MODULES,
19-
...modules
15+
...modules,
2016
);
2117

2218
const resolver = createAsyncControllerResolver(allModules);
@@ -38,20 +34,25 @@ const createAsyncControllerResolver = (pathMap: AsyncModuleMap) => {
3834
}
3935

4036
return [];
41-
})
37+
}),
4238
);
4339

4440
return async (key: string) => {
4541
const module = await identifierMap[key]?.();
4642
if (!module) {
4743
throw Error(
48-
`Controller not found: ${key}. Have you named the file ${key}-controller.ts?`
44+
`Controller not found: ${key}. Have you named the file ${key}-controller.ts?`,
4945
);
5046
}
5147

52-
if (!module.default || !(module.default.prototype instanceof Controller)) {
48+
if (
49+
!module.default ||
50+
typeof module.default !== "function" ||
51+
typeof module.default.prototype.connect !== "function" ||
52+
typeof module.default.prototype.disconnect !== "function"
53+
) {
5354
throw Error(
54-
`Module ${key} should have as its default export a subclass of Controller`
55+
`Module ${key} should have as its default export a subclass of Controller`,
5556
);
5657
}
5758

0 commit comments

Comments
 (0)