Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Set "typeofs: false" to prevent mangling typeofs by uglify #439

Merged
merged 2 commits into from
Aug 1, 2018

Conversation

lxe
Copy link
Contributor

@lxe lxe commented Jul 22, 2018

typeofs: true (default) transforms typeof foo == "undefined" into foo === void 0.

This mangles mapbox-gl creating an error when used alongside with window global mangling:

webpack-contrib/uglifyjs-webpack-plugin#189

@lxe
Copy link
Contributor Author

lxe commented Jul 23, 2018

cc @vicapow

Copy link
Contributor

@KevinGrandon KevinGrandon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Would it be possible to add a unit test which illustrates where this would cause a problem? It would be great to ensure that we don't break this again in the future.

@@ -505,6 +505,13 @@ function getConfig({target, env, dir, watch, cover}) {
parallel: true, // default from webpack
uglifyOptions: {
compress: {
// typeofs: true (default) transforms typeof foo == "undefined" into foo === void 0.

// This mangles mapbox-gl creating an error when used alongside with window global mangling:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to not mention project-specific bugs, and probably avoid links to websites not accessible to the public within the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is generically reproducible... I want to get the static server to run though... see slack :)

@vicapow
Copy link
Contributor

vicapow commented Jul 23, 2018

Do you have other compile configuration tests we can use as an example?

@KevinGrandon
Copy link
Contributor

Do you have other compile configuration tests we can use as an example?

It depends on the behavior of what happens if there was an error. It sounds like this possibly exhibits as a node.js runtime error? If we can add a fixture with logic that reproduces this to the fixtures directory, we should be able to add a test like the following which ensures SSR works:

const {stdout} = await run(entry, {stdio: 'pipe'});
const testContent = JSON.parse(stdout);
t.ok(
testContent.dynamicContent.includes('loaded dynamic import'),
'dynamic import is executed'
);

Alternatively, if you help us create a minimal repo which reproduces the issue, we can incorporate it as a fixture with test. Maybe on top of yarn create fusion-app for example.

@lxe
Copy link
Contributor Author

lxe commented Jul 23, 2018

Yes I can reproduce this generically. I'll add a "unit" test.

// typeofs: true (default) transforms typeof foo == "undefined" into foo === void 0.

// This mangles mapbox-gl creating an error when used alongside with window global mangling:
// https://jeng.uberinternal.com/browse/WPT-1185
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this

@mlmorg
Copy link

mlmorg commented Jul 23, 2018

Supposedly this was fixed in the latest mapbox-gl: mapbox/mapbox-gl-js#6956. Can we simply stop using the old versions?

@vicapow
Copy link
Contributor

vicapow commented Jul 23, 2018

Good catch @mlmorg i agree we should just update the dep if this is fixed upstream.

@lxe
Copy link
Contributor Author

lxe commented Jul 23, 2018

Supposedly this was fixed in the latest mapbox-gl: mapbox/mapbox-gl-js#6956. Can we simply stop using the old versions?

This is still an issue unrelated to mapbox specifically, (but manifests itself there). People will be using older versions of mapbox and fusion in the wild, and it should be able to be compatible with these sort of cases.

Besides, uglification changes like there won't affect the bundle size much

KevinGrandon
KevinGrandon previously approved these changes Jul 31, 2018
Copy link
Contributor

@KevinGrandon KevinGrandon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I am ok taking these changes in favor of correctness. I was unable to figure out what kind of code causes an error in Fusion, latest mapbox-gl seems to work fine. It's highly possible that this will break without a test in the future though.

KevinGrandon
KevinGrandon previously approved these changes Jul 31, 2018
KevinGrandon
KevinGrandon previously approved these changes Jul 31, 2018
@KevinGrandon KevinGrandon changed the title Uglify: set "typeofs: false" to prevent mangling typeofs by uglify Set "typeofs: false" to prevent mangling typeofs by uglify Aug 1, 2018
@KevinGrandon KevinGrandon merged commit 0293723 into fusionjs:master Aug 1, 2018
@AlexMSmithCA AlexMSmithCA mentioned this pull request Aug 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants