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

fix(nuxt): properly handle query for component wrapper #20591

Merged
merged 2 commits into from Apr 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/nuxt/src/components/transform.ts
Expand Up @@ -21,15 +21,19 @@ export function createTransformPlugin (nuxt: Nuxt, getComponents: getComponentsT
function getComponentsImports (): Import[] {
const components = getComponents(mode)
return components.flatMap((c): Import[] => {
const withMode = (mode: string | undefined) => mode
? `${c.filePath}${c.filePath.includes('?') ? '&' : '?'}nuxt_component=${mode}`
: c.filePath

return [
{
as: c.pascalName,
from: c.filePath + (c.mode === 'client' ? '?component=client' : ''),
from: withMode(c.mode === 'client' ? 'client' : undefined),
name: 'default'
},
{
as: 'Lazy' + c.pascalName,
from: c.filePath + '?component=' + [c.mode === 'client' ? 'client' : '', 'async'].filter(Boolean).join(','),
from: withMode([c.mode === 'client' ? 'client' : '', 'async'].filter(Boolean).join(',')),
name: 'default'
}
]
Expand All @@ -43,10 +47,10 @@ export function createTransformPlugin (nuxt: Nuxt, getComponents: getComponentsT
},
async transform (code, id) {
// Virtual component wrapper
if (id.includes('?component')) {
if (id.match(/[?&]nuxt_component=/)) {
const { search } = parseURL(id)
const query = parseQuery(search)
const mode = query.component
const mode = query.nuxt_component
const bare = id.replace(/\?.*/, '')
if (mode === 'async') {
return [
Expand Down