Skip to content

[compiler-sfc] the inlineTemplate option makes it hard to expose component name to dev tools #5496

@haoqunjiang

Description

@haoqunjiang
Member

What problem does this feature solve?

As previously discussed in private, the inlineTemplate option should always be turned on for production for best performance.

/**
* Compile the template and inline the resulting render function
* directly inside setup().
* - Only affects `<script setup>`
* - This should only be used in production because it prevents the template
* from being hot-reloaded separately from component state.
*/
inlineTemplate?: boolean

But it surfaces another problem: enabling this option makes it hard to expose necessary information to the devtools in production.

As described in vitejs/vite#4984 (comment), devtools relies on the __file field to infer the component's name.
But with inlineTemplates enabled, <script setup> components are closed by default, therefore the devtools cannot get the field from the component instances.

It is hard for build tools to expose this field automatically, because of the dynamic nature of the expose call.
Users may or may not have called defineExpose by themselves, or have defined the expose field in a sibling <script> block.
Even if it can be implemented on the @vite/plugin-vue or vue-loader side, it would be a burden to keep maintaining.

What does the proposed API look like?

So I think the best solution is to auto-expose __file in the @vue/compiler-sfc package.

The __file field is like __vccOpts, served as an undocumented convention for various core libraries to work better together.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @yyx990803@haoqunjiang

        Issue actions

          [compiler-sfc] the `inlineTemplate` option makes it hard to expose component name to dev tools · Issue #5496 · vuejs/core