Skip to content
Draft
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: 10 additions & 1 deletion .github/workflows/ci-host.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,16 @@ jobs:
# raw notFound when the host store does a direct GET) point at
# the same race; match both. A second shard pass typically lands
# after the race resolves.
RETRY_PATTERN='ChunkLoadError|Failed to fetch dynamically imported module|NetworkError when attempting to fetch resource|unable to fetch https://icons\.[^:]+: fetch failed|cross-realm fetch failed for https://realm-test\.[^/]+|Could not find https://realm-test\.[^/"]+'
# The `Global error: Uncaught TypeError: Failed to fetch` form is a
# test-harness startup race: base card components (workspace,
# cards-grid) fire a `_types` fetch against the mock test realm the
# moment they render, and with base modules compiled into the host
# bundle that render can land before the test-realm service worker
# is intercepting — the fetch escapes to the real network and the
# rejection surfaces as a Global error. The race is rare per shard,
# so a second pass lands; the durable fix is queuing test-realm
# fetches in the harness until realm registration completes.
RETRY_PATTERN='ChunkLoadError|Failed to fetch dynamically imported module|NetworkError when attempting to fetch resource|unable to fetch https://icons\.[^:]+: fetch failed|cross-realm fetch failed for https://realm-test\.[^/]+|Could not find https://realm-test\.[^/"]+|Global error: Uncaught TypeError: Failed to fetch'
if [ $exit_code -ne 0 ] && grep -Eq "$RETRY_PATTERN" /tmp/test-output.log; then
echo ""
echo "::warning::Transient chunk-fetch failure detected — retrying shard ${{ matrix.shardIndex }}"
Expand Down
2 changes: 1 addition & 1 deletion packages/base/audio-file-def.gts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MusicIcon from '@cardstack/boxel-icons/music';
import {
BaseDefComponent,
type BaseDefComponent,
Component,
NumberField,
contains,
Expand Down
2 changes: 1 addition & 1 deletion packages/base/brand-guide.gts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
buildCssVariableName,
sanitizeHtmlSafe,
eq,
CssVariableEntry,
type CssVariableEntry,
} from '@cardstack/boxel-ui/helpers';

import { cardTypeDisplayName } from '@cardstack/runtime-common';
Expand Down
36 changes: 21 additions & 15 deletions packages/base/card-api.gts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import {
baseRef,
CardContextName,
CardError,
CodeRef,
ToolContext,
type CodeRef,
type ToolContext,
Deferred,
byteStreamToUint8Array,
fields,
Expand All @@ -55,12 +55,12 @@ import {
loadCardDocument,
Loader,
localId,
LocalPath,
type LocalPath,
meta,
primitive,
realmURL,
relativeTo,
SingleCardDocument,
type SingleCardDocument,
uuidv4,
NumberSerializer,
type Format,
Expand All @@ -86,9 +86,9 @@ import {
FileMetaResourceType,
CardResourceType,
loadFileMetaDocument,
CardResource,
LooseLinkableResource,
LooseSingleResourceDocument,
type CardResource,
type LooseLinkableResource,
type LooseSingleResourceDocument,
shouldTrackRuntimeModuleGraph,
shouldTrackRuntimeRelationship,
trackRuntimeFileDependency,
Expand Down Expand Up @@ -208,8 +208,8 @@ import { TextInputValidator } from './text-input-validator';
import { type GetMenuItemParams, getDefaultCardMenuItems } from './menu-items';
import { getDefaultFileMenuItems } from './file-menu-items';
import {
LinkableDocument,
SingleFileMetaDocument,
type LinkableDocument,
type SingleFileMetaDocument,
} from '@cardstack/runtime-common/document-types';
import type { MarkdownEmbedChooser } from '@cardstack/runtime-common/bfm-card-references';
import type { FileMetaResource } from '@cardstack/runtime-common';
Expand Down Expand Up @@ -4921,16 +4921,22 @@ export function resolveRef(
}

function myLoader(): Loader {
// we know this code is always loaded by an instance of our Loader, which sets
// import.meta.loader.
// A Loader that evaluates this module injects `import.meta.loader`. When
// the module is compiled into the host bundle instead, the platform
// evaluates it and no loader is injected; the host publishes the loader
// bundled modules should use (see Loader.setForBundledModules).

// When type-checking realm-server, tsc sees this file and thinks
// it will be transpiled to CommonJS and so it complains about this line. But
// this file is always loaded through our loader and always has access to import.meta.
// When type-checking realm-server, tsc sees this file and thinks it will
// be transpiled to CommonJS and so it complains about import.meta.
// @ts-ignore
return (import.meta as any).loader;
let loader = (import.meta as any).loader ?? Loader.forBundledModules();
if (!loader) {
throw new Error('No Loader is available to this module');
}
return loader;
}


class FallbackCardStore implements CardStore {
#instances: Map<string, CardDef> = new Map();
#fileMetaInstances: Map<string, FileDef> = new Map();
Expand Down
19 changes: 12 additions & 7 deletions packages/base/card-serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
CardResource,
CardResourceMeta,
FileMetaResource,
Loader,
LooseCardResource,
LooseFileMetaResource,
LooseSingleCardDocument,
Expand All @@ -25,6 +24,7 @@ import { isEqual, merge } from 'lodash-es';
import {
assertIsSerializerName,
CardResourceType,
Loader,
fieldSerializer,
FileMetaResourceType,
getSerializer,
Expand Down Expand Up @@ -92,14 +92,19 @@ export const deserialize = Symbol.for('cardstack-deserialize');
// --- Serialization Functions ---

function myLoader(): Loader {
// we know this code is always loaded by an instance of our Loader, which sets
// import.meta.loader.
// A Loader that evaluates this module injects `import.meta.loader`. When
// the module is compiled into the host bundle instead, the platform
// evaluates it and no loader is injected; the host publishes the loader
// bundled modules should use (see Loader.setForBundledModules).

// When type-checking realm-server, tsc sees this file and thinks
// it will be transpiled to CommonJS and so it complains about this line. But
// this file is always loaded through our loader and always has access to import.meta.
// When type-checking realm-server, tsc sees this file and thinks it will
// be transpiled to CommonJS and so it complains about import.meta.
// @ts-ignore
return (import.meta as any).loader;
let loader = (import.meta as any).loader ?? Loader.forBundledModules();
if (!loader) {
throw new Error('No Loader is available to this module');
}
return loader;
}

export async function cardClassFromResource<CardT extends BaseDefConstructor>(
Expand Down
2 changes: 1 addition & 1 deletion packages/base/cards-grid.gts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
subscribeToRealm,
codeRefFromInternalKey,
type Query,
CardErrorJSONAPI,
type CardErrorJSONAPI,
} from '@cardstack/runtime-common';

import CardsGridLayout, {
Expand Down
26 changes: 25 additions & 1 deletion packages/base/code-ref.gts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
CardURLContextName,
fieldSerializer,
CodeRefSerializer,
Loader,
} from '@cardstack/runtime-common';
import { not } from '@cardstack/boxel-ui/helpers';
import { BoxelInput } from '@cardstack/boxel-ui/components';
Expand Down Expand Up @@ -75,7 +76,14 @@ class EditView extends Component<typeof CodeRefField> {
module = new URL(module, new URL(this.cardURL)).href;
}
try {
let code = (await import(module))[name];
// Load through the Loader rather than a bare dynamic import: the
// module is a runtime realm URL, which only a Loader can resolve
// (shims, realm mappings, authenticated fetch). Inside
// loader-evaluated modules the AMD transpile rewrites `import()`
// this way implicitly; compiled-in modules must do it explicitly.
let code = (await myLoader().import<Record<string, any>>(module))[
name
];
if (code) {
this.validationState = 'valid';
if (!opts?.checkOnly) {
Expand All @@ -91,6 +99,22 @@ class EditView extends Component<typeof CodeRefField> {
);
}

function myLoader(): Loader {
// A Loader that evaluates this module injects `import.meta.loader`. When
// the module is compiled into the host bundle instead, the platform
// evaluates it and no loader is injected; the host publishes the loader
// bundled modules should use (see Loader.setForBundledModules).

// When type-checking realm-server, tsc sees this file and thinks it will
// be transpiled to CommonJS and so it complains about import.meta.
// @ts-ignore
let loader = (import.meta as any).loader ?? Loader.forBundledModules();
if (!loader) {
throw new Error('No Loader is available to this module');
}
return loader;
}

export default class CodeRefField extends FieldDef {
static displayName = 'CodeRef';
static icon = CodeIcon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import type { ColorFieldConfiguration } from '../util/color-utils';
import { parseCssColor, parseCssColorSafe } from '../util/color-utils';
import {
detectColorFormat,
RichColorFormat,
type RichColorFormat,
hexToRgba,
hsvToRgb,
RGBA,
type RGBA,
rgbaToFormatString,
rgbaToHexString,
rgbaToHsl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
import {
detectColorFormat,
hslToRgb,
RGBA,
type RGBA,
rgbaToFormatString,
rgbaToHsv,
} from '@cardstack/boxel-ui/helpers';
Expand Down
4 changes: 2 additions & 2 deletions packages/base/color-field/components/slider-picker.gts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import type Owner from '@ember/owner';
import type { ColorFieldSignature } from '../util/color-field-signature';
import {
parseCssColor,
SliderColorFormat,
SliderVariantConfiguration,
type SliderColorFormat,
type SliderVariantConfiguration,
} from '../util/color-utils';
import {
detectColorFormat,
Expand Down
4 changes: 2 additions & 2 deletions packages/base/color.gts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '@cardstack/base/card-api';
import StringField from '@cardstack/base/string';
import { Component } from './card-api';
import StringField from './string';
import { Swatch } from '@cardstack/boxel-ui/components';
import { markdownEscape } from '@cardstack/boxel-ui/helpers';
import PaletteIcon from '@cardstack/boxel-icons/palette';
Expand Down
18 changes: 12 additions & 6 deletions packages/base/contains-many-component.gts
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,18 @@ export function getContainsManyComponent({
}

function myLoader(): Loader {
// we know this code is always loaded by an instance of our Loader, which sets
// import.meta.loader.
// A Loader that evaluates this module injects `import.meta.loader`. When
// the module is compiled into the host bundle instead, the platform
// evaluates it and no loader is injected; the host publishes the loader
// bundled modules should use (see Loader.setForBundledModules).

// When type-checking realm-server, tsc sees this file and thinks
// it will be transpiled to CommonJS and so it complains about this line. But
// this file is always loaded through our loader and always has access to import.meta.
// When type-checking realm-server, tsc sees this file and thinks it will
// be transpiled to CommonJS and so it complains about import.meta.
// @ts-ignore
return (import.meta as any).loader;
let loader = (import.meta as any).loader ?? Loader.forBundledModules();
if (!loader) {
throw new Error('No Loader is available to this module');
}
return loader;
}

2 changes: 1 addition & 1 deletion packages/base/csv-file-def.gts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { byteStreamToUint8Array } from '@cardstack/runtime-common';
import { htmlSafe } from '@ember/template';
import CsvIcon from '@cardstack/boxel-icons/csv';
import {
BaseDefComponent,
type BaseDefComponent,
Component,
StringField,
contains,
Expand Down
8 changes: 4 additions & 4 deletions packages/base/field-component.gts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
type BaseDefComponent,
type BaseDefConstructor,
type Theme,
CardContext,
type CardContext,
formats,
FieldFormats,
CardCrudFunctions,
type FieldFormats,
type CardCrudFunctions,
} from './card-api';
import { isCard, isCompoundField } from './field-support';
import {
Expand All @@ -23,7 +23,7 @@ import {
isCardInstance,
type CodeRef,
type Permissions,
ResolvedCodeRef,
type ResolvedCodeRef,
CardCrudFunctionsContextName,
} from '@cardstack/runtime-common';
import type { ComponentLike } from '@glint/template';
Expand Down
2 changes: 1 addition & 1 deletion packages/base/json-file-def.gts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { byteStreamToUint8Array } from '@cardstack/runtime-common';
import { htmlSafe } from '@ember/template';
import JsonIcon from '@cardstack/boxel-icons/json';
import {
BaseDefComponent,
type BaseDefComponent,
Component,
StringField,
contains,
Expand Down
20 changes: 13 additions & 7 deletions packages/base/links-to-editor.gts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
type Field,
type CardContext,
type LinkableDefConstructor,
CreateCardFn,
type CreateCardFn,
isFileDef,
} from './card-api';
import {
Expand Down Expand Up @@ -282,12 +282,18 @@ export class LinksToEditor extends GlimmerComponent<Signature> {
}

function myLoader(): Loader {
// we know this code is always loaded by an instance of our Loader, which sets
// import.meta.loader.
// A Loader that evaluates this module injects `import.meta.loader`. When
// the module is compiled into the host bundle instead, the platform
// evaluates it and no loader is injected; the host publishes the loader
// bundled modules should use (see Loader.setForBundledModules).

// When type-checking realm-server, tsc sees this file and thinks
// it will be transpiled to CommonJS and so it complains about this line. But
// this file is always loaded through our loader and always has access to import.meta.
// When type-checking realm-server, tsc sees this file and thinks it will
// be transpiled to CommonJS and so it complains about import.meta.
// @ts-ignore
return (import.meta as any).loader;
let loader = (import.meta as any).loader ?? Loader.forBundledModules();
if (!loader) {
throw new Error('No Loader is available to this module');
}
return loader;
}

Loading
Loading