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

Globally hide dom-{bind,if,repeat} elements with legacyOptmizations on #5548

Merged
merged 1 commit into from
May 30, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions lib/elements/dom-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { OptionalMutableData } from '../mixins/mutable-data.js';
import { GestureEventListeners } from '../mixins/gesture-event-listeners.js';
import { strictTemplatePolicy } from '../utils/settings.js';
import { wrap } from '../utils/wrap.js';
import { legacyOptimizations } from '../utils/settings.js';
import { hideElementsGlobally } from '../utils/hide-template-controls.js';

/**
* @constructor
Expand Down Expand Up @@ -76,7 +76,7 @@ export class DomBind extends domBindBase {
* @return {void}
*/
connectedCallback() {
if (!legacyOptimizations) {
if (!hideElementsGlobally()) {
this.style.display = 'none';
}
this.render();
Expand Down
4 changes: 2 additions & 2 deletions lib/elements/dom-if.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { enqueueDebouncer, flush } from '../utils/flush.js';
import { microTask } from '../utils/async.js';
import { root } from '../utils/path.js';
import { wrap } from '../utils/wrap.js';
import { legacyOptimizations } from '../utils/settings.js';
import { hideElementsGlobally } from '../utils/hide-template-controls.js';

/**
* The `<dom-if>` element will stamp a light-dom `<template>` child when
Expand Down Expand Up @@ -135,7 +135,7 @@ export class DomIf extends PolymerElement {
*/
connectedCallback() {
super.connectedCallback();
if (!legacyOptimizations) {
if (!hideElementsGlobally()) {
this.style.display = 'none';
}
if (this.if) {
Expand Down
4 changes: 2 additions & 2 deletions lib/elements/dom-repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { OptionalMutableData } from '../mixins/mutable-data.js';
import { matches, translate } from '../utils/path.js';
import { timeOut, microTask } from '../utils/async.js';
import { wrap } from '../utils/wrap.js';
import { legacyOptimizations } from '../utils/settings.js';
import { hideElementsGlobally } from '../utils/hide-template-controls.js';

/**
* @constructor
Expand Down Expand Up @@ -321,7 +321,7 @@ export class DomRepeat extends domRepeatBase {
*/
connectedCallback() {
super.connectedCallback();
if (!legacyOptimizations) {
if (!hideElementsGlobally()) {
this.style.display = 'none';
}
// only perform attachment if the element was previously detached.
Expand Down
36 changes: 36 additions & 0 deletions lib/utils/hide-template-controls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/

/**
* @fileoverview
*
* Module to hide `<dom-bind>`, `<dom-if>`, and `<dom-repeat>` elements
* optimally in ShadyDOM
*/

import {legacyOptimizations, useShadow} from './settings.js';

let elementsHidden = false;

/**
* @return {boolean} True if elements will be hidden globally
*/
export function hideElementsGlobally() {
if (legacyOptimizations && !useShadow) {
if (!elementsHidden) {
elementsHidden = true;
const style = document.createElement('style');
style.textContent = 'dom-bind,dom-if,dom-repeat{display:none;}';
document.head.appendChild(style);
}
return true;
}
return false;
}