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

Fix Trying to unregister a portal assertion when immediately unrendering portal #644

Merged
merged 1 commit into from
May 21, 2023
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
11 changes: 6 additions & 5 deletions ember-stargate/src/services/-portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default class PortalService extends Service {

unregisterTarget(name: string): void {
this.#targets.delete(name);
this.#portalCount.delete(name);
}

registerPortal(name: string): void {
Expand All @@ -70,11 +71,11 @@ export default class PortalService extends Service {
}

unregisterPortal(name: string): void {
let count = this.#portalCount.get(name) ?? 0;
assert(
`Trying to unregister a portal "${name}" that hasn't been registered before`,
count > 0
);
let count = this.#portalCount.get(name);
if (count === undefined) {
return;
}

count--;
this.#portalCount.set(name, count);
const target = this.#targets.get(name);
Expand Down
4 changes: 3 additions & 1 deletion test-app/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function (defaults) {
let app = new EmberApp(defaults, {
// Add options here
autoImport: {
watchDependencies: ['ember-stargate'],
},
});

// Use `app.import` to add additional libraries to the generated
Expand Down
23 changes: 22 additions & 1 deletion test-app/tests/integration/components/portal-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, settled } from '@ember/test-helpers';
import { render, rerender, settled } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import sinon from 'sinon';

Expand Down Expand Up @@ -316,4 +316,25 @@ module('Integration | Component | portal', function (hooks) {
assert.ok(action.calledWithExactly(2));
assert.strictEqual(action.callCount, 2);
});

test('portal can be immediately unrendered', async function (assert) {
assert.expect(0);

this.set('show', true);
const promise = render(hbs`
{{#if this.show}}
xxx
<PortalTarget @name="main" />
<Portal @target="main">
foo
</Portal>
{{/if}}
`);

await rerender();

this.set('show', false);

await promise;
});
});