Skip to content

Commit

Permalink
Adds syncInitialRender setting
Browse files Browse the repository at this point in the history
This separates the behavior from `legacyOptimizations`. Performs synchronous initial rendering under ShadyDOM when this flag is set.
  • Loading branch information
Steven Orvell committed Jan 31, 2019
1 parent fc7858c commit d4857ec
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/mixins/element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
*/
import '../utils/boot.js';

import { rootPath, strictTemplatePolicy, allowTemplateFromDomModule, legacyOptimizations } from '../utils/settings.js';
import { rootPath, strictTemplatePolicy, allowTemplateFromDomModule, legacyOptimizations, syncInitialRender } from '../utils/settings.js';
import { dedupingMixin } from '../utils/mixin.js';
import { stylesFromTemplate, stylesFromModuleImports } from '../utils/style-gather.js';
import { pathFromUrl, resolveCss, resolveUrl } from '../utils/resolve-url.js';
Expand Down Expand Up @@ -659,7 +659,7 @@ export const ElementMixin = dedupingMixin(base => {
n.attachShadow({mode: 'open'});
}
n.shadowRoot.appendChild(dom);
if (legacyOptimizations && window.ShadyDOM) {
if (syncInitialRender && window.ShadyDOM) {
ShadyDOM.flushInitial(n.shadowRoot);
}
return n.shadowRoot;
Expand Down
18 changes: 18 additions & 0 deletions lib/utils/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,22 @@ export let legacyOptimizations = false;
*/
export const setLegacyOptimizations = function(useLegacyOptimizations) {
legacyOptimizations = useLegacyOptimizations;
};

/**
* Setting to perform initial rendering synchronously when running under ShadyDOM.
* This matches the behavior of Polymer 1.
*/
export let syncInitialRender = false;

/**
* Sets `syncInitialRender` globally for all elements to enable synchronous
* initial rendering.
*
* @param {boolean} useSyncInitialRender enable or disable synchronous initial
* rendering globally.
* @return {void}
*/
export const setSyncInitialRender = function(useSyncInitialRender) {
syncInitialRender = useSyncInitialRender;
};
2 changes: 1 addition & 1 deletion test/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
'unit/shady-events.html',
'unit/shady-content.html',
'unit/shady-dynamic.html',
'unit/shady-dynamic.html?legacyOptimizations',
'unit/shady-dynamic.html?syncInitialRender=true',
'unit/styling-scoped.html',
'unit/styling-cross-scope-var.html',
'unit/styling-cross-scope-apply.html',
Expand Down
10 changes: 5 additions & 5 deletions test/unit/shady-dynamic.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
};
</script>
<script type="module">
import {setLegacyOptimizations} from '../../lib/utils/settings.js';
window.legacyOptimizations = Boolean(window.location.search.match('legacyOptimizations'));
setLegacyOptimizations(window.legacyOptimizations);
import {setSyncInitialRender} from '../../lib/utils/settings.js';
window.syncInitialRender = Boolean(window.location.search.match('syncInitialRender'));
setSyncInitialRender(window.syncInitialRender);
</script>
<script src="../../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script src="wct-browser-config.js"></script>
Expand Down Expand Up @@ -1331,8 +1331,8 @@
document.body.removeChild(re);
});

test('initial distribution is synchronous when `legacyOptimizations` is true', function() {
if (!window.legacyOptimizations) {
test('initial distribution is synchronous when `syncInitialRender` is true', function() {
if (!window.syncInitialRender) {
this.skip();
}
const el = document.createElement('x-test');
Expand Down

0 comments on commit d4857ec

Please sign in to comment.