Skip to content

Commit a525f27

Browse files
backspaceclaude
andcommitted
create-file: emit RRI prefix only for base-realm imports
The generated-import canonicalization was rewriting every registered realm's module ref to its RRI prefix form, including cross-realm references (e.g. a card in workspace A extending one in workspace B became `@test-realm/test2/animal`). Generated user source should address the base realm by its stable alias (`@cardstack/base/X`, matching the emitted Component import) but keep cross-realm references as their absolute URL, which is how they resolve. Narrow the canonicalization to the base realm; other realms keep the absolute URL. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 5560d79 commit a525f27

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

packages/host/app/components/operator-mode/create-file-modal.gts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
specRef,
3636
chooseCard,
3737
baseRealm,
38+
baseRealmRRI,
3839
RealmPaths,
3940
Deferred,
4041
SupportedMimeType,
@@ -844,15 +845,22 @@ export default class CreateFileModal extends Component<Signature> {
844845
this.network.virtualNetwork,
845846
) as ResolvedCodeRef
846847
).module;
848+
// Address the base realm by its stable RRI prefix (`@cardstack/base/X`),
849+
// matching the `Component` import emitted below — base modules are
850+
// referenced by alias, not by a deployment-specific real URL.
847851
// `codeRefWithAbsoluteIdentifier` returns the resolved real URL for
848-
// RRI-prefix inputs (`@cardstack/base/X` → `https://localhost:4201/base/X`).
849-
// Canonicalize to the registered RRI prefix form when one matches so
850-
// generated import lines use the stable identifier (`@cardstack/base/X`)
851-
// instead of a deployment-specific real URL.
852+
// RRI-prefix inputs, so map it back to the prefix form for base only.
853+
// Cross-realm references keep their absolute URL: a generated import
854+
// pointing at another workspace resolves by real URL and is not
855+
// rewritten to a realm-prefix form here.
852856
const canonicalModule =
853857
this.network.virtualNetwork.unresolveURL(absoluteModuleHref);
858+
const moduleForImport: RealmResourceIdentifier | URL =
859+
canonicalModule.startsWith(`${baseRealmRRI}`)
860+
? (canonicalModule as RealmResourceIdentifier)
861+
: new URL(absoluteModuleHref);
854862
let moduleURL = maybeRelativeReference(
855-
canonicalModule,
863+
moduleForImport,
856864
url,
857865
new URL(this.selectedRealmURL),
858866
);

0 commit comments

Comments
 (0)