From 17bcbd7dbca8577067c7de014552b84d43b7f505 Mon Sep 17 00:00:00 2001 From: Ian McNally Date: Mon, 31 Jul 2017 12:46:23 -0400 Subject: [PATCH 1/3] Fix: reacts urlForAssets loading non js,css files --- app/react/src/server/iframe.html.js | 16 ++++++++++++---- app/react/src/server/iframe.html.test.js | 10 ++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/react/src/server/iframe.html.js b/app/react/src/server/iframe.html.js index 2aeb77f6e92c..e48bdeb086cd 100644 --- a/app/react/src/server/iframe.html.js +++ b/app/react/src/server/iframe.html.js @@ -1,5 +1,7 @@ import url from 'url'; +const getExtensionForFilename = filename => /.+\.(\w+)$/.exec(filename)[1]; + // assets.preview will be: // - undefined // - string e.g. 'static/preview.9adbb5ef965106be1cc3.bundle.js' @@ -21,7 +23,6 @@ export const urlsFromAssets = assets => { css: [], }; - const re = /.+\.(\w+)$/; Object.keys(assets) // Don't load the manager script in the iframe .filter(key => key !== 'manager') @@ -30,9 +31,16 @@ export const urlsFromAssets = assets => { if (!Array.isArray(assetList)) { assetList = [assetList]; } - assetList.filter(assetUrl => re.exec(assetUrl)[1] !== 'map').forEach(assetUrl => { - urls[re.exec(assetUrl)[1]].push(assetUrl); - }); + assetList + .filter(assetUrl => { + const extension = getExtensionForFilename(assetUrl); + const isMap = extension === 'map'; + const isSupportedExtension = Boolean(urls[extension]); + return isSupportedExtension && !isMap; + }) + .forEach(assetUrl => { + urls[getExtensionForFilename(assetUrl)].push(assetUrl); + }); }); return urls; diff --git a/app/react/src/server/iframe.html.test.js b/app/react/src/server/iframe.html.test.js index 34cfc2e67669..b57e2b9bba04 100644 --- a/app/react/src/server/iframe.html.test.js +++ b/app/react/src/server/iframe.html.test.js @@ -18,4 +18,14 @@ describe('server.urlsFromAssets', () => { css: ['static/preview.y.css'], }); }); + + it('should not return non-js or non-css assets', () => { + const fixture = { + 'some-thing.svg': 'some-thing.svg', + }; + expect(urlsFromAssets(fixture)).toEqual({ + js: [], + css: [], + }); + }); }); From 69086196bdf711e40d34a982b6591b597894e5d3 Mon Sep 17 00:00:00 2001 From: Ian McNally Date: Sun, 13 Aug 2017 23:08:26 -0400 Subject: [PATCH 2/3] Fix: support non-css or js assets in vue iframe --- app/vue/src/server/iframe.html.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/vue/src/server/iframe.html.js b/app/vue/src/server/iframe.html.js index 85d41e6f6402..645e93a4f8ea 100644 --- a/app/vue/src/server/iframe.html.js +++ b/app/vue/src/server/iframe.html.js @@ -1,5 +1,7 @@ import url from 'url'; +const getExtensionForFilename = filename => /.+\.(\w+)$/.exec(filename)[1]; + // assets.preview will be: // - undefined // - string e.g. 'static/preview.9adbb5ef965106be1cc3.bundle.js' @@ -21,17 +23,27 @@ const urlsFromAssets = assets => { css: [], }; - const re = /.+\.(\w+)$/; Object.keys(assets) // Don't load the manager script in the iframe .filter(key => key !== 'manager') .forEach(key => { - const asset = assets[key]; + let asset = assets[key]; if (typeof asset === 'string') { - urls[re.exec(asset)[1]].push(asset); + urls[getExtensionForFilename(asset)].push(asset); } else { - const assetUrl = asset.find(u => re.exec(u)[1] !== 'map'); - urls[re.exec(assetUrl)[1]].push(assetUrl); + if (!Array.isArray(asset)) { + asset = [asset]; + } + asset + .filter(assetUrl => { + const extension = getExtensionForFilename(assetUrl); + const isMap = extension === 'map'; + const isSupportedExtension = Boolean(urls[extension]); + return isSupportedExtension && !isMap; + }) + .forEach(assetUrl => { + urls[getExtensionForFilename(assetUrl)].push(assetUrl); + }); } }); From c8951305fb6c8afcbb7edad39ec3be412d83d2ab Mon Sep 17 00:00:00 2001 From: Duncan Beevers Date: Sun, 13 Aug 2017 11:17:06 -0700 Subject: [PATCH 3/3] Remove double styling for inline stories --- addons/info/src/components/Story.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/addons/info/src/components/Story.js b/addons/info/src/components/Story.js index 70983aea7b53..232381ca3452 100644 --- a/addons/info/src/components/Story.js +++ b/addons/info/src/components/Story.js @@ -127,9 +127,7 @@ export default class Story extends React.Component { return (
{this._renderInlineHeader()} -
- {this._renderStory()} -
+ {this._renderStory()}
{this._getInfoContent()}