Skip to content
Closed
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
1 change: 1 addition & 0 deletions packages/@ember/-internals/glimmer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@
export { templateFactory as template, templateCacheCounters } from '@glimmer/opcode-compiler';

export { default as RootTemplate } from './lib/templates/root';
export { default as ErrorBoundary } from './lib/components/error-boundary';
export { default as Input } from './lib/components/input';
export { default as LinkTo } from './lib/components/link-to';
export { default as Textarea } from './lib/components/textarea';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ export const CURLY_CAPABILITIES: InternalComponentCapabilities = {
wrapped: true,
willDestroy: true,
hasSubOwner: false,
errorBoundary: false,
};

export const CURLY_COMPONENT_MANAGER = new CurlyComponentManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const CAPABILITIES = {
wrapped: false,
willDestroy: false,
hasSubOwner: true,
errorBoundary: false,
};

class MountManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const CAPABILITIES: InternalComponentCapabilities = {
wrapped: false,
willDestroy: false,
hasSubOwner: false,
errorBoundary: false,
};

const CAPABILITIES_MASK = capabilityFlagsFrom(CAPABILITIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const ROOT_CAPABILITIES: InternalComponentCapabilities = {
wrapped: true,
willDestroy: false,
hasSubOwner: false,
errorBoundary: false,
};

export class RootComponentDefinition implements ComponentDefinition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const CAPABILITIES: InternalComponentCapabilities = {
wrapped: false,
willDestroy: false,
hasSubOwner: false,
errorBoundary: false,
};

const CAPABILITIES_MASK = capabilityFlagsFrom(CAPABILITIES);
Expand Down
110 changes: 110 additions & 0 deletions packages/@ember/-internals/glimmer/lib/components/error-boundary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import type {
Bounds,
Destroyable,
DynamicScope,
Environment,
InternalComponentCapabilities,
InternalComponentManager,
Nullable,
Owner,
VMArguments,
WithCreateInstance,
} from '@glimmer/interfaces';
import type { Reference } from '@glimmer/reference';
import { setComponentTemplate, setInternalComponentManager } from '@glimmer/manager';
import { createConstRef, valueForRef } from '@glimmer/reference';
import { ErrorBoundaryState } from '@glimmer/runtime';

import ErrorBoundaryTemplate from '../templates/error-boundary';

const CAPABILITIES: InternalComponentCapabilities = {
dynamicLayout: false,
dynamicTag: false,
prepareArgs: false,
createArgs: true,
attributeHook: false,
elementHook: false,
createCaller: false,
dynamicScope: false,
updateHook: true,
createInstance: true,
wrapped: false,
willDestroy: false,
hasSubOwner: false,
errorBoundary: true,
};

class ErrorBoundaryManager
implements InternalComponentManager<ErrorBoundaryState>, WithCreateInstance<ErrorBoundaryState>
{
getCapabilities(): InternalComponentCapabilities {
return CAPABILITIES;
}

create(
_owner: Owner,
_definition: object,
args: Nullable<VMArguments>,
_env: Environment,
_dynamicScope: Nullable<DynamicScope>,
_caller: Nullable<Reference>,
_hasDefaultBlock: boolean
): ErrorBoundaryState {
let state = new ErrorBoundaryState();

if (args && args.named.has('retryWith')) {
let retryWithRef = args.named.get('retryWith');
state.retryWithRef = retryWithRef;
state._lastRetryWithValue = valueForRef(retryWithRef);
}

return state;
}

didCreate(): void {}
didUpdate(): void {}
didRenderLayout(): void {}
didUpdateLayout(): void {}

getDebugName(): string {
return 'ErrorBoundary';
}

getSelf(instance: ErrorBoundaryState): Reference {
return createConstRef(instance, 'this');
}

getDestroyable(_instance: ErrorBoundaryState): Nullable<Destroyable> {
return null;
}

update(instance: ErrorBoundaryState, _dynamicScope: Nullable<DynamicScope>): void {
// Consume the @retryWith ref's tag at the ROOT tracking level (outside
// the EB component's JumpIfNotModified scope). This ensures the root's
// combined tag includes the retryWith value, so root JumpIfNotModified
// falls through when @retryWith changes — which in turn allows the EB's
// opcodes to run.
// The actual reset logic is in ErrorBoundaryOpcode.evaluate().
if (instance.retryWithRef) {
valueForRef(instance.retryWithRef);
}
}

didSplatAttributes(
_instance: ErrorBoundaryState,
_element: ErrorBoundaryState,
_operations: Bounds
): void {}
}

const MANAGER = new ErrorBoundaryManager();

const ErrorBoundary = {
create() {
throw new Error('ErrorBoundary does not support .create(). It is managed internally.');
},
};
setInternalComponentManager(MANAGER, ErrorBoundary);
setComponentTemplate(ErrorBoundaryTemplate, ErrorBoundary);

export default ErrorBoundary;
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ const CAPABILITIES: InternalComponentCapabilities = {
wrapped: false,
willDestroy: false,
hasSubOwner: false,
errorBoundary: false,
};

class InternalManager
Expand Down
2 changes: 2 additions & 0 deletions packages/@ember/-internals/glimmer/lib/setup-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Registry } from '@ember/-internals/container';
import { privatize as P } from '@ember/-internals/container';
import { getOwner } from '@ember/-internals/owner';
import { assert } from '@ember/debug';
import ErrorBoundary from './components/error-boundary';
import Input from './components/input';
import LinkTo from './components/link-to';
import Textarea from './components/textarea';
Expand Down Expand Up @@ -47,6 +48,7 @@ export function setupEngineRegistry(registry: Registry): void {

registry.optionsForType('helper', { instantiate: false });

registry.register('component:error-boundary', ErrorBoundary);
registry.register('component:input', Input);

registry.register('component:link-to', LinkTo);
Expand Down
11 changes: 11 additions & 0 deletions packages/@ember/-internals/glimmer/lib/templates/error-boundary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { precompileTemplate } from '@ember/template-compilation';
export default precompileTemplate(
`{{#if this.hasError}}{{yield this.error this.retry to="error"}}{{else}}{{yield}}{{/if}}`,
{
moduleName: 'packages/@ember/-internals/glimmer/lib/templates/error-boundary.hbs',
strictMode: true,
scope() {
return {};
},
}
);
Loading
Loading