-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
add template only name #58
Conversation
bd1f293
to
1fade50
Compare
@@ -1468,7 +1468,7 @@ describe('htmlbars-inline-precompile', function () { | |||
import { precompileTemplate } from "@ember/template-compilation"; | |||
import { setComponentTemplate } from "@ember/component"; | |||
import templateOnly from "@ember/component/template-only"; | |||
export default setComponentTemplate(precompileTemplate('<HelloWorld @color={{"#ff0000"}} />', { scope: () => ({ HelloWorld }), strictMode: true }), templateOnly()); | |||
export default setComponentTemplate(precompileTemplate('<HelloWorld @color={{"#ff0000"}} />', { scope: () => ({ HelloWorld }), strictMode: true }), templateOnly(undefined, "foo-bar")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be PascalCase, since it's what would get shown in the inspector, and how it would be invoked by a consumer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inspector would auto transform it to pascal case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it also doesn't matter if it starts with lower case. so my-template-only-2
would also be shown as MyTemplateOnly2
2761187
to
c99903e
Compare
perhaps we should handle this in the glimmer-vm's debug render tree? since the templats / VM have to know the names at the call sites, which is more accurate for showing in the inspector?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the right place to fix this. The correct name to show in the inspector doesn't depend on the definition of the component, it depends on the name used by the caller of the component.
If your template says
import Button from 'fancy-button-addon';
<template>
<Button />
</template>
The inspector should show <Button />
, not whatever name is used inside the component definition in fancy-button-addon.
This would probably be a change in the debugRenderTree area.
I agree, but that information is lost already during precompile. Also what about nested things like |
I'm not sure I agree with that. The current look and feel of the UI too strongly implies that what shows up in the inspector pane should match your source code, which it is not really designed to do and IMO a non-goal. If we wanted to do that it would require something similar to source-map level of information which we just don't have/would to be expensive to keep around in the current architecture. I am not saying that we should deliberately make the UI worse, but it's important that we are on the same page about the goals/capabilities/limitations of the current system and not to over extend it/push it in the directions it wasn't meant/designed for. This has also comes up in the past when @patricklx wants to add more runtime/metadata bookkeeping to guarantee the ordering of the tree nodes matches DOM order in all cases, which I personally also think is a non-goal in the current design. We previously talked about dropping the idea of "module name" entirely, which I think would be fine, as long as we add back a way to find the component. I think @ef4 previous suggested adding a stub function so we can use jump to function definition for the linkage, which I think is a good idea. Back to the current topic. I would say it's definitely not the intention to have the render node represent/preserve any caller side information, and in any case the actual JS binding name gets lost very quickly and I'm not even sure we are in a position to preserve/propagate it even if we want to. In terms of the current system, the render node is a hookable API by the component managers, and and it takes the "component definition" as the input. Typically the component definition is just a JS reference to the component class. I suppose you can do something in the JS/babel side to wrap each of these references with an object that preserves the name as a string, but you would be doing that for every instance of every component invocation. IMO that is just not worth it. It will also either have bloat the production payload or make the code very different in dev vs prod, which could cause other problems. |
isn't the goal of the debug render tree to make it easy for the tools to debug the render tree -- rather than make up assumptions about how things are invoked?
what would that look like? 🤔 |
I should probably also say what I believe the goal of the inspector pane is. I think it's just supposed to give you best-effort/useful-enough information so that someone who works on the codebase would have a decent shot at correlating the output with the application logic, while limiting the overhead of metadata/bookkeeping we add to make it work. Generally, we try to piggy back on whatever information we already have/need for other purposes (which is why To the extent it is helpful, we can lay things out to match how it looks in the template source code, that's one way to help developers make the correlation, but it's not the primary objective and we don't impose that as a goal on ourselves at the expense of having to capture/carry extra stuff just to make the visualization nice. I think there is a alternative design where we can make that a goal, but it would need to be a very different architecture where the additional information is completely optional and carried in a side channel like how source maps work. |
I think how the inspector displays the components is good, considering the many ways a component can be obtained through functions etc it should just show the component name. what could be done in addition is to add a label to it (if at some point we get it from glimmer-vm) and have options in the inspector to inline it in the component tree or have them as tooltip. it will probably take some time until that lands in glimmer. if at all. |
This PR is literally capturing extra information just to make the visualization marginally nicer, while also sometimes making it more misleading. I don't think it's worth it. I do think we will ultimately want to capture extra debug information, but in a separate bundle that doesn't effect normal app usage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to come up with descriptions here we should try to make them actually distinct for distinct components. These are not.
src/plugin.ts
Outdated
@@ -496,14 +497,27 @@ function insertCompiledTemplate<EnvSpecificOptions>( | |||
|
|||
let expression = t.callExpression(templateFactoryIdentifier, [templateExpression]); | |||
|
|||
let assignment = target.parent; | |||
let assignmentName: t.StringLiteral = t.stringLiteral(state.filename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can leak whole filesystem paths, which is both bloat and information leak. Also, it's not even a good answer, because you can have many components in this same file and they will all look as if they're the same component in the inspector, leading to confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, should be the same as below, babel.types.identifier('undefined')
src/plugin.ts
Outdated
let assignment = target.parent; | ||
let assignmentName: t.StringLiteral = t.stringLiteral(state.filename); | ||
if (assignment.type === 'AssignmentExpression' && assignment.left.type === 'Identifier') { | ||
assignmentName = t.stringLiteral(assignment.left.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using local variables like this is also likely to mislead, because nothing is stopping people from reusing the same local variable names in different modules that interact with each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think its the best we can do right now. at least better than unknown template.
how about basename of file + variable name?
Another problem here: this feature only works in the pre-rfc-931 API. Right now, the babel plugin only uses that API. But we don't want to be stuck with that. Apps could all already use the post-rfc-931 API and get smaller code (we just haven't gotten around to making that improvement here), and that API intentionally does not accept a component name argument. |
So we will end up needing an alternative anyway? would that also require changes to glimmer-vm or only in the babel plugin? |
I said a lot of things and it's pretty nuanced, I didn't mean for it to boil down to "let's declare a moratorium on new metadata (though my personal position is not far off from that). I am not here to endorse this particular PR. I do think there is some value in keeping the status quo of the inspector working enough as we make these other changes, so to the extent it's not too onerous and the amount of metadata is inline with what the previous status quo, that feels okay to me personal, but:
Yes I think you should make those calls. I also pointed out an alternative (what IIRC you originally proposed elsewhere) is to attach a stub function to the components, either to capture a stack trace or to use the jump to function definition feature to link the component, which I think is a pretty neat idea. (Though we probably still need some kind of text label for any form of visualization. What I was largely responding to was the original reason for rejecting the PR was:
This would require pushing the metadata capturing to the invocation side, which would massively increase the amount of information we need to capture and also not a good fit for the current
If you are talking about multiple components in the same file, or that the file name/path is not a particularly good indicator anyway, then 100%. I would totally be onboard with tweaking the debug label API and see about capturing the identifier we assigned it to, etc. What I disagree with is that the name should/has to match the source text form the invocation side to be "accurate", and that it is a design goal of the current inspector/debugRenderTree API. And that has been a mild disagreement brewing/something I have been trying to explain to @patricklx and @NullVoxPopuli for a while. I understand that the current UI is a bit uncanny in that it resembles your source code a bit too much and so when they don't match up exactly it seems "surprising" and feels like something needs fixing. But really it's just an abstracted/lossy reconstructed view of the runtime information we have, and it's by design (or at least, the lack of a better design). Keep pushing on adding more metadata to the current system such in the direction of reconstructing a more accurate view of the template source is like adding metadata to an AST so that it can eventually re-print the source code. Sometimes you can get away with it, but ultimately it's a pretty poor fit. And more importantly in our case, all those metadata we capture has runtime costs today.
That we are on the same page and is what I meant by:
It is a fair bit of work and needs careful design though. IMO as long as we accept that the current system is meant to be a lossy/best-effort view that gives you enough information to point you at the right direction, there is still plenty of millage left there without blowing everything up. It's really not worse than things like function names in stack traces and flame graphs where the information is there just a bit lossy. |
Yeah I think we are pretty aligned. I see why my original suggestion is a bridge too far for the current design and would require a wholly different system. |
So, anything that can be done near feature to not have many unknown components in the inspector tree? |
I found that this was the default behaviour in ember template imports v3 |
I think this makes more sense to add back to ember-template-imports. because this is only needed if ember-template-imports is used |
this is for inspector to show template only component names.
templateOnly
takes 2 params moduleName and name. https://github.com/glimmerjs/glimmer-vm/blob/10eae7429b702b1e7f5434b91802d5767ff7ad9a/packages/%40glimmer/runtime/lib/component/template-only.ts#L84and have their defaults set to
I had to update dependencies to test locally... #59