Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] add template name to debug render tree #18548

Merged
merged 1 commit into from
Nov 15, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,15 @@ export default class CurlyComponentManager
return factory(owner);
}

getDynamicLayout({ component }: ComponentStateBucket): Invocation {
getDynamicLayout(bucket: ComponentStateBucket): Invocation {
let component = bucket.component;
let template = this.templateFor(component);
let layout = template.asWrappedLayout();

if (ENV._DEBUG_RENDER_TREE) {
bucket.environment.debugRenderTree.setTemplate(bucket, template);
}

return {
handle: layout.compile(),
symbolTable: layout.symbolTable,
Expand Down Expand Up @@ -348,6 +353,7 @@ export default class CurlyComponentManager
name: state.name,
args: args.capture(),
instance: component,
template: state.template,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export default class CustomComponentManager<ComponentInstance>
name: definition.name,
args: args.capture(),
instance: component,
template: definition.template,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class InputComponentManager extends InternalComponentManager<Inpu

create(
env: Environment,
{ ComponentClass }: InternalDefinitionState,
{ ComponentClass, layout }: InternalDefinitionState,
args: Arguments,
_dynamicScope: DynamicScope,
caller: VersionedPathReference
Expand All @@ -79,6 +79,7 @@ export default class InputComponentManager extends InternalComponentManager<Inpu
name: 'input',
args: args.capture(),
instance,
template: layout,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class MountManager extends AbstractManager<EngineState, EngineDefinitionState>
let template = templateFactory(state.engine);
let layout = template.asLayout();

if (ENV._DEBUG_RENDER_TREE) {
state.environment.debugRenderTree.setTemplate(state.controller, template);
}

return {
handle: layout.compile(),
symbolTable: layout.symbolTable,
Expand Down Expand Up @@ -117,13 +121,16 @@ class MountManager extends AbstractManager<EngineState, EngineDefinitionState>
name,
args: args.capture(),
instance: engine,
template: undefined,
});

environment.debugRenderTree.create(controller, {
type: 'route-template',
name: 'application',
args: args.capture(),
instance: controller,
// set in getDynamicLayout
template: undefined,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class OutletComponentManager extends AbstractManager<OutletInstanceState, Outlet
name: state.outlet.name,
args: EMPTY_ARGS,
instance: undefined,
template: undefined,
});

let parentState = parentStateRef.value();
Expand All @@ -120,6 +121,7 @@ class OutletComponentManager extends AbstractManager<OutletInstanceState, Outlet
name: mountPoint,
args: EMPTY_ARGS,
instance: engine,
template: undefined,
});
}

Expand All @@ -128,6 +130,7 @@ class OutletComponentManager extends AbstractManager<OutletInstanceState, Outlet
name: definition.name,
args: args.capture(),
instance: definition.controller,
template: definition.template,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class RootComponentManager extends CurlyComponentManager {
name: state.name,
args: EMPTY_ARGS,
instance: component,
template: state.template,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class TemplateOnlyComponentManager

create(
environment: Environment,
{ name }: TemplateOnlyComponentDefinitionState,
{ name, template }: TemplateOnlyComponentDefinitionState,
args: Arguments
): Option<DebugStateBucket> {
if (ENV._DEBUG_RENDER_TREE) {
Expand All @@ -65,6 +65,7 @@ export default class TemplateOnlyComponentManager
name: name,
args: args.capture(),
instance: null,
template,
});
return bucket;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { assert } from '@ember/debug';
import { Simple } from '@glimmer/interfaces';
import { Bounds, CapturedArguments } from '@glimmer/runtime';
import { expect, Option, Stack } from '@glimmer/util';
import { OwnedTemplate } from '../template';

export type RenderNodeType = 'outlet' | 'engine' | 'route-template' | 'component';

Expand All @@ -10,6 +11,7 @@ export interface RenderNode {
name: string;
args: CapturedArguments;
instance: unknown;
template?: OwnedTemplate;
}

interface InternalRenderNode<T extends object> extends RenderNode {
Expand All @@ -23,6 +25,7 @@ export interface CapturedRenderNode {
name: string;
args: ReturnType<CapturedArguments['value']>;
instance: unknown;
template: Option<string>;
bounds: Option<{
parentElement: Simple.Element;
firstNode: Simple.Node;
Expand Down Expand Up @@ -90,6 +93,11 @@ export default class DebugRenderTree<Bucket extends object = object> {
this.enter(state);
}

// for dynamic layouts
setTemplate(state: Bucket, template: OwnedTemplate): void {
this.nodeFor(state).template = template;
}

didRender(state: Bucket, bounds: Bounds): void {
assert(`BUG: expecting ${this.stack.current}, got ${state}`, this.stack.current === state);
this.nodeFor(state).bounds = bounds;
Expand Down Expand Up @@ -170,9 +178,14 @@ export default class DebugRenderTree<Bucket extends object = object> {
private captureNode(id: string, state: Bucket): CapturedRenderNode {
let node = this.nodeFor(state);
let { type, name, args, instance, refs } = node;
let template = this.captureTemplate(node);
let bounds = this.captureBounds(node);
let children = this.captureRefs(refs);
return { id, type, name, args: args.value(), instance, bounds, children };
return { id, type, name, args: args.value(), instance, template, bounds, children };
}

private captureTemplate({ template }: InternalRenderNode<Bucket>): Option<string> {
return (template && template.referrer.moduleName) || null;
}

private captureBounds(node: InternalRenderNode<Bucket>): CapturedRenderNode['bounds'] {
Expand Down
Loading