Skip to content

feat: allow VPContent to use custom components#5176

Merged
brc-dd merged 2 commits intovuejs:mainfrom
shigma:patch-2
Apr 8, 2026
Merged

feat: allow VPContent to use custom components#5176
brc-dd merged 2 commits intovuejs:mainfrom
shigma:patch-2

Conversation

@shigma
Copy link
Copy Markdown
Contributor

@shigma shigma commented Apr 8, 2026

Description

Currently, VPContent hardcodes the use of VPPage, VPHome, and VPDoc for the built-in page, home, and doc layouts. Custom layouts only work via <component :is> for non-built-in layout names. This means there is no way to fully override the built-in layout components from a custom theme.

This PR uses resolveComponent to check whether the user has registered a global component matching the layout name (page, home, or doc). If a matching component is found, VPContent falls through to <component :is> instead of using the built-in component. If no override is registered, the behavior is exactly the same as before.

Linked Issues

N/A

Additional Context

N/A


Tip

The author of this PR can publish a preview release by commenting /publish below.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 8, 2026

npm i https://pkg.pr.new/vitepress@5176

commit: 4ee0955

@brc-dd brc-dd merged commit c0b38d5 into vuejs:main Apr 8, 2026
12 checks passed

function resolveLayout(name: string) {
const component = resolveComponent(name)
return typeof component === 'string' ? null : component
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could've just returned true/false I guess for this use case

@edison1105
Copy link
Copy Markdown
Member

@brc-dd @shigma
It is not appropriate to use resolveComponent to check whether a component exists, as it will trigger a warning in DEV if the component does not exist. If this check is required, it is recommended to use resolveDynamicComponent instead, which can eliminate the warning. Additionally, both helpers are private.
I'm wondering if there is a more reasonable approach to explicitly use a user-provided layout.

image

@brc-dd
Copy link
Copy Markdown
Member

brc-dd commented Apr 14, 2026

Hmm, yeah hard to do this without resolveComponent/resolveDynamicComponent. Other alternative I see is doing something like this https://github.com/vueform/vueform/blob/main/src/utils/isComponentRegistered.js#L3, but that will need getCurrentInstance 🫠

We can go back to not supporting the default theme names it if there are issues with the vapor implementation.

@shigma
Copy link
Copy Markdown
Contributor Author

shigma commented Apr 17, 2026

resolveComponent is actually a public API, not private. You can see it in the official docs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants