From a815e55e88749d60f9729b83dc6b9fc0e9e0569c Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Mon, 11 Nov 2019 17:55:09 +0800 Subject: [PATCH] Merge pull request #8773 from donaldpipowitch/fix-8294-source-loader Source-loader: Warn if applied to non-stories file --- lib/source-loader/package.json | 1 + lib/source-loader/src/client/preview.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/source-loader/package.json b/lib/source-loader/package.json index 5b540b028346..94c3619fd980 100644 --- a/lib/source-loader/package.json +++ b/lib/source-loader/package.json @@ -29,6 +29,7 @@ }, "dependencies": { "@storybook/addons": "5.2.7", + "@storybook/client-logger": "5.2.7", "@storybook/router": "5.2.7", "core-js": "^3.0.1", "estraverse": "^4.2.0", diff --git a/lib/source-loader/src/client/preview.js b/lib/source-loader/src/client/preview.js index 7a03d3f576bd..05491f18cf8b 100644 --- a/lib/source-loader/src/client/preview.js +++ b/lib/source-loader/src/client/preview.js @@ -1,4 +1,5 @@ import addons from '@storybook/addons'; +import { logger } from '@storybook/client-logger'; import { STORY_EVENT_ID } from './events'; const getLocation = (context, locationsMap) => locationsMap[context.id]; @@ -13,6 +14,14 @@ function sendEvent( prefix, idsToFrameworks ) { + if (!context || !context.id || !context.kind || !context.story) { + logger.warn( + '@storybook/source-loader was applied to a file which does not contain a story. Please check your webpack configuration and make sure to apply @storybook/source-loader only to files containg stories. Related file:' + ); + logger.warn(source); + return; + } + const channel = addons.getChannel(); const currentLocation = getLocation(context, locationsMap);