Merge pull request #11709 from storybookjs/fix/11602-hmr-not-working

FIX HMR
This commit is contained in:
Norbert de Langen 2020-07-29 10:53:32 +02:00 committed by GitHub
commit 9d2b53dac4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -16,6 +16,7 @@ beforeEach(() => {
hot: {
data: {},
dispose: (cb: (data: any) => void) => cbs.push(cb),
accept: jest.fn(),
},
} as unknown) as NodeModule;
});

View File

@ -230,14 +230,15 @@ export const loadCsf = ({
`Invalid module '${m}'. Did you forget to pass \`module\` as the second argument to \`configure\`"?`
);
}
if (m && m.hot && m.hot.dispose) {
({ previousExports = new Map() } = m.hot.data || {});
m.hot.dispose((data) => {
loaded = false;
// eslint-disable-next-line no-param-reassign
data.previousExports = previousExports;
});
m.hot.accept();
}
if (loaded) {
logger.warn('Unexpected loaded state. Did you call `load` twice?');