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

Remove code for pre-ember-v4 #1382

Merged
merged 10 commits into from
May 31, 2023
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
import Ember from 'ember';
import {
macroCondition,
importSync,
dependencySatisfies,
} from '@embroider/macros';

let getComponentManager: (definition: object, owner: object) => unknown;

if (macroCondition(dependencySatisfies('ember-source', '>=3.27.0-alpha.1'))) {
let _getComponentManager =
//@ts-ignore
importSync('@glimmer/manager').getInternalComponentManager;

getComponentManager = (definition: object, owner: object) => {
return _getComponentManager(definition, true);
};
} else if (
macroCondition(dependencySatisfies('ember-source', '>=3.25.0-beta.1'))
) {
let _getComponentManager = (Ember as any).__loader.require(
'@glimmer/manager'
).getInternalComponentManager;

getComponentManager = (definition: object, owner: object) => {
return _getComponentManager(definition, true);
};
} else {
let _getComponentManager = (Ember as any).__loader.require(
'@glimmer/runtime'
).getComponentManager;

getComponentManager = (definition: object, owner: object) => {
return _getComponentManager(owner, definition);
};
}
import { getInternalComponentManager as getComponentManager } from '@glimmer/manager';

export default getComponentManager;
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { macroCondition, dependencySatisfies } from '@embroider/macros';
import type { ComponentLike } from '@glint/template';

import getComponentManager from './get-component-manager';
Expand All @@ -15,15 +14,21 @@ function isComponent(
maybeComponent: object,
owner: object
): maybeComponent is ComponentLike {
if (macroCondition(dependencySatisfies('ember-source', '>=3.25.0-beta.1'))) {
// SAFETY: in more recent versions of @glimmer/manager,
// this throws an error when maybeComponent does not have
// an associated manager.
try {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that @glimmer/manager changed its behavior. This change absorbs the change in @glimmer/manager

return !!getComponentManager(maybeComponent, owner);
} else {
return (
!!getComponentManager(maybeComponent, owner) ||
['@ember/component', '@ember/component/template-only'].includes(
maybeComponent.toString()
} catch (e) {
if (
`${e}`.includes(
`wasn't a component manager associated with the definition`
)
);
) {
return false;
}

throw e;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Ember from 'ember';
import {
macroCondition,
importSync,
Expand All @@ -10,21 +9,9 @@ let renderSettled: () => Promise<void>;
if (macroCondition(dependencySatisfies('ember-source', '>=4.5.0-beta.1'))) {
//@ts-ignore
renderSettled = importSync('@ember/renderer').renderSettled;
} else if (
macroCondition(dependencySatisfies('ember-source', '>=3.27.0-alpha.1'))
) {
} else {
//@ts-ignore
renderSettled = importSync('@ember/-internals/glimmer').renderSettled;
} else if (
macroCondition(dependencySatisfies('ember-source', '>=3.6.0-alpha.1'))
) {
renderSettled = (Ember as any).__loader.require(
'@ember/-internals/glimmer'
).renderSettled;
} else {
renderSettled = (Ember as any).__loader.require(
'ember-glimmer'
).renderSettled;
}

export default renderSettled;
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { assert } from '@ember/debug';
import { runHooks } from './helper-hooks';
import hasEmberVersion from './has-ember-version';
import isComponent from './-internal/is-component';
import { macroCondition, dependencySatisfies } from '@embroider/macros';
import { ComponentRenderMap, SetUsage } from './setup-context';

const OUTLET_TEMPLATE = hbs`{{outlet}}`;
Expand Down Expand Up @@ -129,55 +128,33 @@ export function render(
let OutletTemplate = lookupOutletTemplate(owner);
let ownerToRenderFrom = options?.owner || owner;

if (macroCondition(dependencySatisfies('ember-source', '<3.24.0'))) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code change is the removal of this if branch, keeping only the else

// Pre 3.24, we just don't support rendering components at all, so we error
// if we find anything that isn't a template.
const isTemplate =
('__id' in templateOrComponent && '__meta' in templateOrComponent) ||
('id' in templateOrComponent && 'meta' in templateOrComponent);
if (isComponent(templateOrComponent, owner)) {
// We use this to track when `render` is used with a component so that we can throw an
// assertion if `this.{set,setProperty} is used in the same test
ComponentRenderMap.set(context, true);

if (!isTemplate) {
throw new Error(
`Using \`render\` with something other than a pre-compiled template is not supported until Ember 3.24 (you are on ${Ember.VERSION}).`
const setCalls = SetUsage.get(context);

if (setCalls !== undefined) {
assert(
`You cannot call \`this.set\` or \`this.setProperties\` when passing a component to \`render\`, but they were called for the following properties:\n${setCalls
.map((key) => ` - ${key}`)
.join('\n')}`
);
}

context = {
ProvidedComponent: templateOrComponent,
};
templateOrComponent = INVOKE_PROVIDED_COMPONENT;
} else {
templateId += 1;
let templateFullName = `template:-undertest-${templateId}` as const;
ownerToRenderFrom.register(templateFullName, templateOrComponent);
templateOrComponent = lookupTemplate(
ownerToRenderFrom,
templateFullName
);
} else {
if (isComponent(templateOrComponent, owner)) {
// We use this to track when `render` is used with a component so that we can throw an
// assertion if `this.{set,setProperty} is used in the same test
ComponentRenderMap.set(context, true);

const setCalls = SetUsage.get(context);

if (setCalls !== undefined) {
assert(
`You cannot call \`this.set\` or \`this.setProperties\` when passing a component to \`render\`, but they were called for the following properties:\n${setCalls
.map((key) => ` - ${key}`)
.join('\n')}`
);
}

context = {
ProvidedComponent: templateOrComponent,
};
templateOrComponent = INVOKE_PROVIDED_COMPONENT;
} else {
templateId += 1;
let templateFullName = `template:-undertest-${templateId}` as const;
ownerToRenderFrom.register(templateFullName, templateOrComponent);
templateOrComponent = lookupTemplate(
ownerToRenderFrom,
templateFullName
);
}
}

let outletState = {
Expand Down
5 changes: 0 additions & 5 deletions addon/tests/integration/dom/scroll-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@ import {
setupRenderingContext,
teardownContext,
} from '@ember/test-helpers';
import hasEmberVersion from '@ember/test-helpers/has-ember-version';
import {
buildExpectedSteps,
registerHooks,
unregisterHooks,
} from '../../helpers/register-hooks';

module('DOM Helper: scroll-to', function (hooks) {
if (!hasEmberVersion(2, 4)) {
return;
}

hooks.beforeEach(async function () {
await setupContext(this);
await setupRenderingContext(this);
Expand Down
1 change: 1 addition & 0 deletions addon/types/virtual.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@glimmer/manager';