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: block.scoped is undefined #5977

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
)
} else {
// sub block request
const descriptor = getDescriptor(filename, options)!
const descriptor = getDescriptor(filename, options, true, id)!
if (query.type === 'template') {
return transformTemplateAsModule(code, descriptor, options, this, ssr)
} else if (query.type === 'style') {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ async function genStyleCode(
const attrsQuery = attrsToQuery(style.attrs, 'css')
const srcQuery = style.src ? `&src` : ``
const directQuery = asCustomElement ? `&inline` : ``
const query = `?vue&type=style&index=${i}${srcQuery}${directQuery}`
const query = `?vue&type=style&index=${i}${srcQuery}${directQuery}&target=${descriptor.filename}`
const styleRequest = src + query + attrsQuery
if (style.module) {
if (asCustomElement) {
Expand Down
26 changes: 23 additions & 3 deletions packages/plugin-vue/src/utils/descriptorCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface SFCParseResult {
errors: Array<CompilerError | SyntaxError>
}

const cache = new Map<string, SFCDescriptor>()
const cache = new Map<string, SFCDescriptor | Array<SFCDescriptor>>()
const prevCache = new Map<string, SFCDescriptor | undefined>()

export function createDescriptor(
Expand Down Expand Up @@ -48,10 +48,21 @@ export function setPrevDescriptor(
export function getDescriptor(
filename: string,
options: ResolvedOptions,
createIfNotFound = true
createIfNotFound = true,
id?: string
): SFCDescriptor | undefined {
if (cache.has(filename)) {
return cache.get(filename)!
const ds = cache.get(filename)
if (Array.isArray(ds) && id && id.includes('target')) {
let target = /target=(.+)/.exec(id)?.[1]
if (target?.includes('&')) {
target = /(.+)&/.exec(target)?.[1]
}
if (target) {
return ds.find(({ filename }) => filename === target)
}
}
return ds as SFCDescriptor
}
if (createIfNotFound) {
const { descriptor, errors } = createDescriptor(
Expand All @@ -67,5 +78,14 @@ export function getDescriptor(
}

export function setDescriptor(filename: string, entry: SFCDescriptor): void {
const ds = cache.get(filename)
if (ds) {
if (Array.isArray(ds)) {
cache.set(filename, [...ds, entry])
} else {
cache.set(filename, [ds, entry])
}
return
}
cache.set(filename, entry)
}