diff --git a/packages/base/codemirror-editor.gts b/packages/base/codemirror-editor.gts index 3930196dc2..dfd066084d 100644 --- a/packages/base/codemirror-editor.gts +++ b/packages/base/codemirror-editor.gts @@ -11,7 +11,8 @@ import { baseRealm, trimJsonExtension, maybeRelativeReference, - type VirtualNetwork, + resolveRRIReference, + rri, } from '@cardstack/runtime-common'; import { type BfmRefRange, @@ -98,24 +99,17 @@ function isInline(kind: string): boolean { return kind === 'inline'; } -function resolveUrl( - raw: string, - baseUrl: string | null | undefined, - virtualNetwork: VirtualNetwork | undefined, -): string { - // With a VN, resolve through it so prefix-form bases and registered - // prefix-form refs round-trip correctly. Without a VN, plain - // `new URL(raw, baseUrl)` still handles the common case — URL-form - // refs (with or without a base) and relative refs against a URL-form - // base. Prefix-form bases need a VN; `new URL()` throws on those and - // we fall back to the raw ref. +function resolveUrl(raw: string, baseUrl: string | null | undefined): string { + // Resolve in RRI space (no VirtualNetwork), matching the MarkDownTemplate + // display path. Instance ids are canonical (prefix form for mapped realms, + // URL for unmapped), so a prefix-form base resolves relative refs to RRI and + // a URL-form base to URL — either way the `in:{ id }` reference query below + // matches the indexed card (prefix ids are expanded to their URL forms + // index-side). try { - if (virtualNetwork) { - return trimJsonExtension( - virtualNetwork.resolveURL(raw, baseUrl || undefined).href, - ); - } - return trimJsonExtension(new URL(raw, baseUrl || undefined).href); + return trimJsonExtension( + resolveRRIReference(raw, baseUrl ? rri(baseUrl) : undefined), + ); } catch { return trimJsonExtension(raw); } @@ -163,7 +157,6 @@ interface CodeMirrorEditorSignature { linkedCards?: CardDef[] | null; linkedFiles?: FileDef[] | null; cardReferenceBaseUrl?: string | null; - cardReferenceVirtualNetwork?: VirtualNetwork; /** When false, all syntax markers are visible (source mode). Default true. */ livePreview?: boolean; getCards?: ( @@ -854,11 +847,10 @@ export default class CodeMirrorEditor extends GlimmerComponent(); for (let target of this._widgetTargets) { if (target.refType === refType) { - urls.add(resolveUrl(target.cardId, baseUrl, vn)); + urls.add(resolveUrl(target.cardId, baseUrl)); } } return [...urls]; @@ -911,7 +903,6 @@ export default class CodeMirrorEditor extends GlimmerComponent { - let resolvedUrl = resolveUrl(target.cardId, baseUrl, vn); + let resolvedUrl = resolveUrl(target.cardId, baseUrl); return { ...target, instance: instancesByUrl.get(resolvedUrl) ?? null, @@ -1123,7 +1114,10 @@ export default class CodeMirrorEditor extends GlimmerComponent {{#if this._embedPopoverOpen}} -
+
{{else}} @@ -246,7 +233,6 @@ export class RichMarkdownField extends FieldDef { @linkedCards={{this.linkedCards}} @linkedFiles={{this.linkedFiles}} @cardReferenceBaseUrl={{this.baseUrl}} - @cardReferenceVirtualNetwork={{this.virtualNetwork}} @livePreview={{eq this._mode 'compose'}} @getCards={{context.getCards}} >