scratchfoundation/scratch-storage

Can't load gzip SVG assets when importing scratch-storage into another project

joshlory opened this issue · 0 comments

I'm running into a problem where all the dependencies are already inlined when importing scratch-storage into a project. For got this leads to a build that has unzipResponse inlined, even though it's not supported in the browser.

I think the problem is that got is getting inlined as a "devDependency" for the Node.js target. When the built scratch-storage npm package is run in the browser, got is hitting a codepath that isn't supported for web.

Expected Behavior

Loading a SVG from a server with gzip compression enabled shouldn't throw an error.

Actual Behavior

I get an exception: Uncaught TypeError: Cannot read property 'bind' of undefined and the asset fails to load.

screen shot 2017-08-04 at 3 41 50 pm

Steps to Reproduce

Sample code:

import Storage from 'scratch-storage';

const storage = new Storage();
const assetType = storage.AssetType.ImageVector;
storage.addWebSource([assetType], asset => `/s/${asset.assetId}.${asset.dataFormat}`);
storage.load(assetType, '09dc888b0b7df19f70d81588ae73420e').then(/* ... */);

I'm seeing this fail in the browser when /s/09dc888b0b7df19f70d81588ae73420e.svg is returned with Content-Encoding: gzip.

Operating System and Browser

Mac OS 10.12.5
Chrome 60.0.3112.90