diff --git a/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts b/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts
index 881b3cc7309..5693e5b7662 100644
--- a/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts
+++ b/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts
@@ -9,6 +9,7 @@ import {
setViewElement,
} from '@ember/-internals/views';
import { assert, debugFreeze } from '@ember/debug';
+import { EMBER_COMPONENT_IS_VISIBLE } from '@ember/deprecated-features';
import { _instrumentStart } from '@ember/instrumentation';
import { assign } from '@ember/polyfills';
import { DEBUG } from '@glimmer/env';
@@ -92,7 +93,7 @@ function applyAttributeBindings(
operations.setAttribute('id', PrimitiveReference.create(id), false, null);
}
- if (seen.indexOf('style') === -1) {
+ if (EMBER_COMPONENT_IS_VISIBLE && seen.indexOf('style') === -1) {
IsVisibleBinding.install(element, component, operations);
}
}
@@ -368,7 +369,9 @@ export default class CurlyComponentManager
} else {
let id = component.elementId ? component.elementId : guidFor(component);
operations.setAttribute('id', PrimitiveReference.create(id), false, null);
- IsVisibleBinding.install(element, component, operations);
+ if (EMBER_COMPONENT_IS_VISIBLE) {
+ IsVisibleBinding.install(element, component, operations);
+ }
}
if (classRef) {
diff --git a/packages/@ember/-internals/glimmer/lib/component.ts b/packages/@ember/-internals/glimmer/lib/component.ts
index 10d3ab44f1c..5086f71b45c 100644
--- a/packages/@ember/-internals/glimmer/lib/component.ts
+++ b/packages/@ember/-internals/glimmer/lib/component.ts
@@ -1104,6 +1104,7 @@ const Component = CoreView.extend(
@property isVisible
@type Boolean
@default null
+ @deprecated Use `
` or `{{#if this.showComponent}}
{{/if}}`
@public
*/
}
diff --git a/packages/@ember/-internals/glimmer/lib/utils/bindings.ts b/packages/@ember/-internals/glimmer/lib/utils/bindings.ts
index 7dbc87b37c3..b452c7114b1 100644
--- a/packages/@ember/-internals/glimmer/lib/utils/bindings.ts
+++ b/packages/@ember/-internals/glimmer/lib/utils/bindings.ts
@@ -1,5 +1,6 @@
import { get } from '@ember/-internals/metal';
-import { assert } from '@ember/debug';
+import { assert, deprecate } from '@ember/debug';
+import { EMBER_COMPONENT_IS_VISIBLE } from '@ember/deprecated-features';
import { dasherize } from '@ember/string';
import { Opaque, Option, Simple } from '@glimmer/interfaces';
import { CachedReference, combine, map, Reference, Tag } from '@glimmer/reference';
@@ -106,8 +107,16 @@ export const AttributeBinding = {
!(isSimple && isPath)
);
- if (attribute === 'style') {
- reference = new StyleBindingReference(reference, referenceForKey(component, 'isVisible'));
+ if (
+ EMBER_COMPONENT_IS_VISIBLE &&
+ attribute === 'style' &&
+ StyleBindingReference !== undefined
+ ) {
+ reference = new StyleBindingReference(
+ reference,
+ referenceForKey(component, 'isVisible'),
+ component
+ );
}
operations.setAttribute(attribute, reference, false, null);
@@ -118,48 +127,93 @@ export const AttributeBinding = {
const DISPLAY_NONE = 'display: none;';
const SAFE_DISPLAY_NONE = htmlSafe(DISPLAY_NONE);
-class StyleBindingReference extends CachedReference
{
- public tag: Tag;
- constructor(private inner: Reference, private isVisible: Reference) {
- super();
+let StyleBindingReference:
+ | undefined
+ | { new (...args: any[]): CachedReference };
+
+if (EMBER_COMPONENT_IS_VISIBLE) {
+ StyleBindingReference = class extends CachedReference {
+ public tag: Tag;
+ private component: Component;
+ constructor(
+ private inner: Reference,
+ private isVisible: Reference,
+ component: Component
+ ) {
+ super();
+
+ this.tag = combine([inner.tag, isVisible.tag]);
+ this.component = component;
+ }
- this.tag = combine([inner.tag, isVisible.tag]);
- }
+ compute(): string | SafeString {
+ let value = this.inner.value();
+ let isVisible = this.isVisible.value();
+
+ if (isVisible !== undefined) {
+ deprecate(
+ `\`isVisible\` is deprecated (from "${this.component._debugContainerKey}")`,
+ false,
+ {
+ id: 'ember-component.is-visible',
+ until: '4.0.0',
+ url: 'https://deprecations.emberjs.com/v3.x#toc_ember-component-is-visible',
+ }
+ );
+ }
- compute(): string | SafeString {
- let value = this.inner.value();
- let isVisible = this.isVisible.value();
+ if (isVisible !== false) {
+ return value;
+ }
- if (isVisible !== false) {
- return value;
- } else if (!value) {
- return SAFE_DISPLAY_NONE;
- } else {
- let style = value + ' ' + DISPLAY_NONE;
- return isHTMLSafe(value) ? htmlSafe(style) : style;
+ if (!value) {
+ return SAFE_DISPLAY_NONE;
+ } else {
+ let style = value + ' ' + DISPLAY_NONE;
+ return isHTMLSafe(value) ? htmlSafe(style) : style;
+ }
}
- }
+ };
}
-export const IsVisibleBinding = {
- install(_element: Simple.Element, component: Component, operations: ElementOperations) {
- operations.setAttribute(
- 'style',
- map(referenceForKey(component, 'isVisible'), this.mapStyleValue),
- false,
- null
- );
- // // the upstream type for addDynamicAttribute's `value` argument
- // // appears to be incorrect. It is currently a Reference, I
- // // think it should be a Reference.
- // operations.addDynamicAttribute(element, 'style', ref as any as Reference, false);
- },
-
- mapStyleValue(isVisible: boolean) {
- return isVisible === false ? SAFE_DISPLAY_NONE : null;
- },
+export let IsVisibleBinding: undefined | {
+ install(element: Simple.Element, component: Component, operations: ElementOperations): void;
+ mapStyleValue(isVisible: boolean, component: Component): SafeString | null;
};
+if (EMBER_COMPONENT_IS_VISIBLE) {
+ IsVisibleBinding = {
+ install(_element: Simple.Element, component: Component, operations: ElementOperations) {
+ let componentMapStyleValue = (isVisible: boolean) => {
+ return this.mapStyleValue(isVisible, component);
+ };
+
+ operations.setAttribute(
+ 'style',
+ map(referenceForKey(component, 'isVisible'), componentMapStyleValue),
+ false,
+ null
+ );
+ // // the upstream type for addDynamicAttribute's `value` argument
+ // // appears to be incorrect. It is currently a Reference, I
+ // // think it should be a Reference.
+ // operations.addDynamicAttribute(element, 'style', ref as any as Reference, false);
+ },
+
+ mapStyleValue(isVisible: boolean, component: Component) {
+ if (isVisible !== undefined) {
+ deprecate(`\`isVisible\` is deprecated (from "${component._debugContainerKey}")`, false, {
+ id: 'ember-component.is-visible',
+ until: '4.0.0',
+ url: 'https://deprecations.emberjs.com/v3.x#toc_ember-component-is-visible',
+ });
+ }
+
+ return isVisible === false ? SAFE_DISPLAY_NONE : null;
+ },
+ };
+}
+
export const ClassNameBinding = {
install(
_element: Simple.Element,
diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js
index ebcc64dd76f..b69dddea30b 100644
--- a/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js
+++ b/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js
@@ -2904,22 +2904,30 @@ moduleFor(
template: `foo
`,
});
- this.render(`{{foo-bar id="foo-bar" isVisible=visible}}`, {
- visible: false,
- });
+ expectDeprecation(() => {
+ this.render(`{{foo-bar id="foo-bar" isVisible=visible}}`, {
+ visible: false,
+ });
+ }, '`isVisible` is deprecated (from "component:foo-bar")');
assertStyle('display: none;');
this.assertStableRerender();
- runTask(() => {
- set(this.context, 'visible', true);
- });
+ expectDeprecation(() => {
+ runTask(() => {
+ set(this.context, 'visible', true);
+ });
+ }, '`isVisible` is deprecated (from "component:foo-bar")');
+
assertStyle('');
- runTask(() => {
- set(this.context, 'visible', false);
- });
+ expectDeprecation(() => {
+ runTask(() => {
+ set(this.context, 'visible', false);
+ });
+ }, '`isVisible` is deprecated (from "component:foo-bar")');
+
assertStyle('display: none;');
}
@@ -2933,9 +2941,11 @@ moduleFor(
template: `foo
`,
});
- this.render(`{{foo-bar id="foo-bar" isVisible=visible}}`, {
- visible: false,
- });
+ expectDeprecation(() => {
+ this.render(`{{foo-bar id="foo-bar" isVisible=visible}}`, {
+ visible: false,
+ });
+ }, '`isVisible` is deprecated (from "component:foo-bar")');
this.assertComponentElement(this.firstChild, {
tagName: 'div',
@@ -2944,18 +2954,22 @@ moduleFor(
this.assertStableRerender();
- runTask(() => {
- set(this.context, 'visible', true);
- });
+ expectDeprecation(() => {
+ runTask(() => {
+ set(this.context, 'visible', true);
+ });
+ }, '`isVisible` is deprecated (from "component:foo-bar")');
this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: { id: 'foo-bar', style: styles('color: blue;') },
});
- runTask(() => {
- set(this.context, 'visible', false);
- });
+ expectDeprecation(() => {
+ runTask(() => {
+ set(this.context, 'visible', false);
+ });
+ }, '`isVisible` is deprecated (from "component:foo-bar")');
this.assertComponentElement(this.firstChild, {
tagName: 'div',
@@ -2986,25 +3000,31 @@ moduleFor(
template: `foo
`,
});
- this.render(`{{foo-bar id="foo-bar" foo=foo isVisible=visible}}`, {
- visible: false,
- foo: 'baz',
- });
+ expectDeprecation(() => {
+ this.render(`{{foo-bar id="foo-bar" foo=foo isVisible=visible}}`, {
+ visible: false,
+ foo: 'baz',
+ });
+ }, '`isVisible` is deprecated (from "component:foo-bar")');
assertStyle('display: none;');
this.assertStableRerender();
- runTask(() => {
- set(this.context, 'visible', true);
- });
+ expectDeprecation(() => {
+ runTask(() => {
+ set(this.context, 'visible', true);
+ });
+ }, '`isVisible` is deprecated (from "component:foo-bar")');
assertStyle('');
- runTask(() => {
- set(this.context, 'visible', false);
- set(this.context, 'foo', 'woo');
- });
+ expectDeprecation(() => {
+ runTask(() => {
+ set(this.context, 'visible', false);
+ set(this.context, 'foo', 'woo');
+ });
+ }, '`isVisible` is deprecated (from "component:foo-bar")');
assertStyle('display: none;');
assert.equal(this.firstChild.getAttribute('foo'), 'woo');
diff --git a/packages/@ember/deprecated-features/index.ts b/packages/@ember/deprecated-features/index.ts
index 724ffb311f3..d49510de203 100644
--- a/packages/@ember/deprecated-features/index.ts
+++ b/packages/@ember/deprecated-features/index.ts
@@ -14,3 +14,4 @@ export const ALIAS_METHOD = !!'3.9.0';
export const APP_CTRL_ROUTER_PROPS = !!'3.10.0-beta.1';
export const FUNCTION_PROTOTYPE_EXTENSIONS = !!'3.11.0-beta.1';
export const MOUSE_ENTER_LEAVE_MOVE_EVENTS = !!'3.13.0-beta.1';
+export const EMBER_COMPONENT_IS_VISIBLE = !!'3.15.0-beta.1';