emberjs / emberjs/rfcs

Replacing `moduleName` in template meta

Open
#940 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
801
Forks
409
PR merge metrics
No merged PRs in 30d

Description

Historically, Ember compiles a `moduleName` into the wire format of each template. The Ember Inspector displays this when navigating the hierarchy of components.

This isn't really viable going forward, for two reasons:

1. `moduleName` as traditionally understood doesn't exist reliably anymore
- it used to be the "runtime" name of a module, which was unambiguous because all packages were forced into one flat namespace. But we don't do that anymore. Under embroider (and even in classic builds when consuming v2 addons), we follow normal node_modules resolution, so packages are not a flat namespace.
- the mapping from publicly-visible name to internal-name can be complicated, based on the full feature set of package.json exports. For us to try to produce a traditional `moduleName` we would need to faithfully run that transformation, backwards.

2. The existence of Template Tag means that templates are not one-to-one with modules anymore. So identifying which module a component lives in is not enough to unambiguously locate it.

Since templates are javascript values (or to be precise: templates are a detail of components and components are javascript values), it's worth asking: why do we think we need to label them with their module names, when we don't do that with any other javascript values?

I would like to suggest that instead of trying to label components by their template moduleName, we can change the inspector to offer a "jump to definition" button on components.

- For class-based components, `window.inspect(theComponentInstance.constructor)` already works.
- But for template-only components, there's no function present to point at.
- we could introduce one inside the wire format of the template
- or we could make `templateOnlyComponent()` capture an Exception and save its stack so that it would be possible to navigate back to the site at which the component was defined.

A related concern here is that AST transforms can see `moduleName` and I know some rely on it. They need a deprecation path to stop doing that. It's going to troll them anyway as soon as people are using template tag.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.