Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove IE11-specific code #4603

Merged
merged 2 commits into from
Dec 20, 2023
Merged

Remove IE11-specific code #4603

merged 2 commits into from
Dec 20, 2023

Conversation

Frank3K
Copy link
Contributor

@Frank3K Frank3K commented Dec 20, 2023

Description

While browsing through the code, I found some IE11-specific code. Since IE11 is not a supported browser anymore (by model-viewer's README), nor by three.js, I think this code can be refactored to more modern code. This change leads to a somewhat smaller bundle size.

Bundle size

File size after a npm run build:

File name Old size (byte) New size (byte) Size diff (byte) Size difference (%)
model-viewer-module-umd.js 811477 810695 -782 -0,10
model-viewer-module-umd.js.map 1824995 1822288 -2707 -0,15
model-viewer-module-umd.min.js 375008 374852 -156 -0,04
model-viewer-module-umd.min.js.map 1296291 1295330 -961 -0,07
model-viewer-module.js 849033 847786 -1247 -0,15
model-viewer-module.js.map 1833299 1830557 -2742 -0,15
model-viewer-module.min.js 396451 396295 -156 -0,04
model-viewer-module.min.js.map 1330861 1329425 -1436 -0,11
model-viewer-umd.js 1751653 1750943 -710 -0,04
model-viewer-umd.js.map 4288624 4285917 -2707 -0,06
model-viewer-umd.min.js 896545 896389 -156 -0,02
model-viewer-umd.min.js.map 2956094 2955163 -931 -0,03
model-viewer.d.ts 82362 82362 0 0,00
model-viewer.js 1818886 1817639 -1247 -0,07
model-viewer.js.map 4300191 4297449 -2742 -0,06
model-viewer.min.js 920632 920476 -156 -0,02
model-viewer.min.js.map 2986699 2985245 -1454 -0,05

Testing

npm run test succeeds on my local machine.

UMD bundles

In the rollup config I found this code:

const pluginsIE11 = [
...plugins,
commonjs(),
polyfill(['object.values/auto']),
cleanup({
// Ideally we'd also clean third_party/three, which saves
// ~45kb in filesize alone... but takes 2 minutes to build
include: ['lib/**'],
comments: 'none',
}),
];

If I understand correctly this is not just for IE11, but for any browser that does not support ES Modules. The specific lines were introduced in 92111b3. Since all modern / supported browsers support ES6 Modules (caniuse), I doubt if the UMD bundles are still required. I do not see any usage of the umd bundles in the repository itself (e.g. in the aforementioned unit test build).

Because I am not sure, I did not touch the rollup config.

Comment on lines -209 to -236
/**
* Returns the first key in a Map in iteration order.
*
* NOTE(cdata): This is necessary because IE11 does not implement iterator
* methods of Map, and polymer-build does not polyfill these methods for
* compatibility and performance reasons. This helper proposes that it is
* a reasonable compromise to sacrifice a very small amount of runtime
* performance in IE11 for the sake of code clarity.
*/
export const getFirstMapKey = <T = any, U = any>(map: Map<T, U>): T|null => {
if (map.keys != null) {
return map.keys().next().value || null;
}

let firstKey: T|null = null;

try {
map.forEach((_value: U, key: T, _map: Map<T, U>) => {
firstKey = key;
// Stop iterating the Map with forEach:
throw new Error();
});
} catch (_error) {
}

return firstKey;
};

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 method (containing IE11 specific code) was not used anymore.

Copy link
Collaborator

@elalish elalish left a comment

Choose a reason for hiding this comment

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

Excellent, thank you for the cleanup! I wouldn't be surprised if there are more of these lurking, though I try to remove them whenever I notice them.

@elalish elalish merged commit ff13ec1 into google:master Dec 20, 2023
3 checks passed
JL-Vidinoti pushed a commit to vidinoti/model-viewer that referenced this pull request Apr 22, 2024
* Remove unused method

* Refactor IE11-specific code

Since IE11 is not supported anymore.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants