Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: check if 'btoa' exists for old IE versions #479

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/runtime/injectStylesIntoStyleTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function applyToTag(style, options, obj) {
style.removeAttribute('media');
}

if (sourceMap && btoa) {
if (sourceMap && typeof btoa !== 'undefined') {
Copy link
Member

Choose a reason for hiding this comment

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

btoa should be undefined for old IE, can you provide screenshot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Copy link
Contributor Author

@okchangwon okchangwon Aug 14, 2020

Choose a reason for hiding this comment

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

typeof should be used to check if global variables exist.

Copy link
Member

Choose a reason for hiding this comment

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

What is IE version? It is weird, because btoa should be false here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In IE9, btoa is undefined.
Or the following code is also good.

if (sourceMap && window.btoa) {

Copy link
Member

Choose a reason for hiding this comment

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

I am fine with typeof, weird, I can't reproduce

Copy link
Contributor Author

@okchangwon okchangwon Aug 14, 2020

Choose a reason for hiding this comment

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

I have created an example of a problematic code to reproduce the phenomenon.

<script>
if (btoa) {
  console.log("it's exist");
} else {
  console.log("it's not exist");
}
</script>

This code causes an error in IE9.

Please check the console window on this page.
http://okchangwon.xyz/naver/ie9-btoa

image

Copy link
Member

Choose a reason for hiding this comment

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

error from ie9-btoa package, not from style-loader

css += `\n/*# sourceMappingURL=data:application/json;base64,${btoa(
unescape(encodeURIComponent(JSON.stringify(sourceMap)))
)} */`;
Expand Down