|
9 | 9 | --> |
10 | 10 |
|
11 | 11 | <link rel="import" href="../lib/async.html"> |
| 12 | +<link rel="import" href="../lib/settings.html"> |
12 | 13 | <link rel="import" href="../lib/debounce.html"> |
13 | 14 |
|
14 | 15 | <script> |
|
454 | 455 |
|
455 | 456 | }); |
456 | 457 |
|
| 458 | + /* |
| 459 | + We patch importHref under the CE polyfill for 2 separate reasons: |
| 460 | + (1) performance optimization: CE registrations upgrade the entire document |
| 461 | + tree including imports. Therefore if an import is loaded every element |
| 462 | + registered will upgrade the entire doc tree. This is $ and is optimized |
| 463 | + via batching to occur once at startup (before WebComponentsReady). We |
| 464 | + override importHref here so that we can batch upgrades until after the |
| 465 | + import has loded, leveraging the same batching optimization. |
| 466 | + (2) the CE polyfill upgrades elements in HI in the wrong order. They upgrade |
| 467 | + after all scripts in the import have run rather than being interleaved with |
| 468 | + them. Therefore, any script that depends on a previous custom element in |
| 469 | + the import will fail. By deferring upgrades until after async imports load |
| 470 | + we reduce the chance of a problem because upgrade time dependencies are |
| 471 | + no longer an issue. (e.g. `dom-module` is a registration time dependency |
| 472 | + when `lazyRegister` is not used and it is specially handled in `dom-module`; |
| 473 | + `custom-style` is an upgrade time dependency native css properties are used). |
| 474 | +
|
| 475 | + */ |
| 476 | + if (!Polymer.Settings.useNativeCustomElements) { |
| 477 | + var importHref = Polymer.Base.importHref; |
| 478 | + Polymer.Base.importHref = function(href, onload, onerror, optAsync) { |
| 479 | + CustomElements.ready = false; |
| 480 | + var loadFn = function(e) { |
| 481 | + CustomElements.upgradeDocumentTree(document); |
| 482 | + CustomElements.ready = true; |
| 483 | + if (onload) { |
| 484 | + return onload.call(this, e); |
| 485 | + } |
| 486 | + } |
| 487 | + return importHref.call(this, href, loadFn, onerror, optAsync); |
| 488 | + } |
| 489 | + } |
| 490 | + |
457 | 491 | })(); |
458 | 492 | </script> |
0 commit comments