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

Library import pollute / override JS global URL namespace. #666

Open
midori0507 opened this issue Aug 17, 2020 · 0 comments
Open

Library import pollute / override JS global URL namespace. #666

midori0507 opened this issue Aug 17, 2020 · 0 comments

Comments

@midori0507
Copy link

midori0507 commented Aug 17, 2020

If you use SSR (serverside rendering). window will be undefined.

Which this line

var URL = window.URL;

will set the var URL to undefined, cause window.URL is undefined.

After that:

This line

if (typeof URL === 'undefined') {

check and realize URL is undefined (cause you set it in the line above). And try to fallback by setting it with a mock-URL object
Later, global namespace is replace with this mocked URL.

Issues:

  • This is really bad if you have SSR, you override global WHATWG URL with your mock URL object. Any call for example new URL() will show URL is not a constructor, cause you override it with your mock.

Suggestion:

  • Move everything related to URL to use WHATWG URL, vanilla support from Nodejs v6 / 7. Will work on both client and server side.
  • Dont mock and override global, not a good practice in js
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

No branches or pull requests

1 participant