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

feat: added option dataAttributeSalt to saltify data-attributes #435

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/plugin-vue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export interface Options {
* - **default:** `false`
*/
prodHydrationMismatchDetails?: boolean
/**
* Custom value to add to data-attribute for components with `scoped` styles
*/
dataAttributeSalt?: string
}

// `script`, `template` and `style` are lower-level compiler options
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ export interface Options {
* - **default:** `false`
*/
prodHydrationMismatchDetails?: boolean

/**
* Custom value to add to data-attribute for components with `scoped` styles
*/
dataAttributeSalt?: string
}

/**
Expand Down
12 changes: 10 additions & 2 deletions packages/plugin-vue/src/utils/descriptorCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ const prevCache = new Map<string, SFCDescriptor | undefined>()
export function createDescriptor(
filename: string,
source: string,
{ root, isProduction, sourceMap, compiler, template }: ResolvedOptions,
{
root,
isProduction,
sourceMap,
compiler,
template,
features,
}: ResolvedOptions,
hmr = false,
): SFCParseResult {
const { descriptor, errors } = compiler.parse(source, {
Expand All @@ -34,7 +41,8 @@ export function createDescriptor(
// ensure the path is normalized in a way that is consistent inside
// project (relative to root) and on different systems.
const normalizedPath = normalizePath(path.relative(root, filename))
descriptor.id = getHash(normalizedPath + (isProduction ? source : ''))
const hash = getHash(normalizedPath + (isProduction ? source : ''))
descriptor.id = `${hash}${features?.dataAttributeSalt ?? ''}`
;(hmr ? hmrCache : cache).set(filename, descriptor)
return { descriptor, errors }
}
Expand Down