Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

'WeakMap' is undefined #210

Closed
rafaelmaiolla opened this issue Feb 20, 2015 · 10 comments
Closed

'WeakMap' is undefined #210

rafaelmaiolla opened this issue Feb 20, 2015 · 10 comments

Comments

@rafaelmaiolla
Copy link

The commit in this revision b44664e has caused the problem.

MutationOberserve code requires the WeakMap to be defined.

@addyosmani
Copy link
Member

Can you provide details about what build (full or -lite) and browser you are experiencing this issue with?

@rafaelmaiolla
Copy link
Author

It is the lite build on IE9, but will probably have the same issue on IE10.

The revision I added in the first comment may not be the problem. I think the problem actually started in this one a49aaee

@addyosmani
Copy link
Member

We don't officially support IE9, per the browser compatibility matrix in the README. Are you able to repro this issue in IE10?

@rafaelmaiolla
Copy link
Author

The problem is reproducible on IE10 too.

@adidahiya
Copy link

I'm seeing this problem as well, but only when running mocha tests via phantomJS. Simply including webcomponents-lite.js throws the error Can't find variable: WeakMap in phantom. Downgrading to v0.5.4 fixed the problem.

@mereskin-zz
Copy link
Contributor

Same here, in Safari 7 on iOs 7

@Jeff17Robbins
Copy link

build-lite.json pulls in MutationObserver (which uses WeakMap) before it pulls in HTMLImport (which defines WeakMap on browsers that lack it.)

The prebuilt webcomponents-lite.js version 0.5.5 (available through a link on the homepage https://github.com/webcomponents/webcomponentsjs/archive/0.5.5.zip ), as a result of this build order, has this problem of using WeakMap at line 55 before defining it starting at line 353.

This commit seems to have caused this breaking change:
b44664e

However, if MutationObserver now really does need to be ahead of HTMLImport, then perhaps we need WeakMap pulled in as part of build-lite.json and have HTMLImport stop pulling it in?

https://github.com/webcomponents/webcomponentsjs/blob/master/src/WebComponents/build-lite.json
[
"build/boot.js",
"../MutationObserver/MutationObserver.js",
"../HTMLImports/build.json",
"../CustomElements/build.json",
"../Template/Template.js",
"unresolved.js"
]

@paulie4
Copy link

paulie4 commented Mar 2, 2015

Since HTMLImports/build.json and CustomElements/build.json are both including their "../WeakMap/WeakMap.js" dependency, why don't you move the "../MutationObserver/MutationObserver.js" dependency into each of those and out of build-lite.json? Of course, it will need to go after "../WeakMap/WeakMap.js".

@paulie4
Copy link

paulie4 commented Mar 9, 2015

I just noticed that ShadowDOM has its own MutationObserver.js polyfill (used by the non-lite webcomponents), so the "../MutationObserver/MutationObserver.js" dependency should not move into the common HTMLImports/build.json and CustomElements/build.json files. I tested adding the "../WeakMap/WeakMap.js" dependency directly into src/WebComponents/build-lite.json, right before "../MutationObserver/MutationObserver.js", and it correctly doesn't affect anything else except for fixing this issue by moving the WeakMap polyfill code before the dependent MutationObserver polyfill code. This is a simple change, but if you'd like, I could create a pull request for it. src/WebComponents/build-lite.json would look like this:

[
  "build/boot.js",
  "../URL/URL.js",
  "../WeakMap/WeakMap.js",
  "../MutationObserver/MutationObserver.js",
  "../HTMLImports/build.json",
  "../CustomElements/build.json",
  "../Template/Template.js",
  "unresolved.js"
]

@TimvdLippe
Copy link
Contributor

Thanks for the issue. It has been a great while since this issue was opened. Sadly, this issue misses a live reproduction with the most recent version of the webcomponents polyfill for us to be able to debug and potentially fix. Versions 1 of the polyfills fix a large amount of issues, probably including this one as well.

Please see the CONTRIBUTING.md for guidelines on filing issues. You can start from this jsBin template as a starting point and link it in the issue template under "Live Demo".

Feel free to file a new issue following these instructions if you can still reproduce this issue with versions 1 of the polyfills. Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants