Skip to content

Commit eb685f9

Browse files
committed
fix: bind methods for MSWPlugin to prevent method loss during plugin loading
1 parent f4e8055 commit eb685f9

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

apps/console/src/mocks/browser.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,22 @@ export async function startMockServer() {
4949
await kernel.use(new AppPlugin(appConfig))
5050

5151
// MSW Plugin (intercepts network requests)
52-
await kernel.use(new MSWPlugin({
52+
const mswPlugin = new MSWPlugin({
5353
enableBrowser: true,
5454
baseUrl: '/api/v1',
5555
logRequests: true
56-
}));
56+
});
57+
58+
// WORKAROUND: ObjectRuntime's PluginLoader spreads the plugin object ({ ...plugin }),
59+
// which strips methods from class instances (prototype methods).
60+
// We must bind 'init' and 'start' as own properties.
61+
const fixedMswPlugin = {
62+
...mswPlugin,
63+
init: mswPlugin.init.bind(mswPlugin),
64+
start: mswPlugin.start ? mswPlugin.start.bind(mswPlugin) : undefined
65+
};
66+
67+
await kernel.use(fixedMswPlugin);
5768

5869
await kernel.bootstrap();
5970

0 commit comments

Comments
 (0)