Skip to content

Commit

Permalink
Merge pull request #2103 from cardstack/cs-7678-bug-adding-skill-card…
Browse files Browse the repository at this point in the history
…s-to-a-room-sometimes-says-theyre-not

Fetch default skill cards just-in-time in order to avoid having cards with stale loaders
  • Loading branch information
lukemelia authored Jan 30, 2025
2 parents c8731f2 + 82180f8 commit 1f3544b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/host/app/services/card-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export default class CardService extends Service {
return card;
}

async getCard(url: URL | string): Promise<CardDef> {
async getCard<T extends CardDef = CardDef>(url: URL | string): Promise<T> {
if (typeof url === 'string') {
url = new URL(url);
}
Expand All @@ -356,7 +356,7 @@ export default class CardService extends Service {
json,
new URL(json.data.id),
);
return card;
return card as T;
}

private async loadPatchedCards(
Expand Down
14 changes: 2 additions & 12 deletions packages/host/app/services/matrix-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ import type {
import type { Tool } from 'https://cardstack.com/base/matrix-event';
import { SkillCard } from 'https://cardstack.com/base/skill-card';

import { getCard } from '../resources/card-resource';
import { importResource } from '../resources/import';

import { RoomResource, getRoom } from '../resources/room';
Expand Down Expand Up @@ -141,7 +140,6 @@ export default class MatrixService extends Service {
new TrackedMap();
private cardHashes: Map<string, string> = new Map(); // hashes <> event id
private skillCardHashes: Map<string, string> = new Map(); // hashes <> event id
private defaultSkills: SkillCard[] = [];

constructor(owner: Owner) {
super(owner);
Expand Down Expand Up @@ -780,19 +778,11 @@ export default class MatrixService extends Service {
}

async loadDefaultSkills() {
if (this.defaultSkills.length > 0) {
return this.defaultSkills;
}

await Promise.all(
return await Promise.all(
DefaultSkillCards.map(async (skillCardURL) => {
let cardResource = getCard(this, () => skillCardURL);
await cardResource.loaded;
this.defaultSkills.push(cardResource.card as SkillCard);
return await this.cardService.getCard<SkillCard>(skillCardURL);
}),
);

return this.defaultSkills;
}

@cached
Expand Down

0 comments on commit 1f3544b

Please sign in to comment.