Skip to content

Commit

Permalink
feat(build/snakeskin): normalize v-attrs to directive for web compone…
Browse files Browse the repository at this point in the history
…nts (#1519)

* feat(build/snakeskin): normalize v-attrs to directive for web components

* docs: update changelog
  • Loading branch information
shining-mind authored Dec 23, 2024
1 parent 46c9b13 commit da53a05
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Changelog
_Note: Gaps between patch versions are faulty, broken or test releases._

## v4.0.0-beta.?? (2024-12-23)

#### :house: Internal

* Forced v-attrs to be converted into directive for tags that are web components `build/snakeskin`

## v4.0.0-beta.170 (2024-12-19)

#### :house: Internal
Expand Down
6 changes: 6 additions & 0 deletions build/snakeskin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Changelog
> - :house: [Internal]
> - :nail_care: [Polish]
## v4.0.0-beta.?? (2024-12-23)

#### :house: Internal

* Forced v-attrs to be converted into directive for tags that are web components

## v4.0.0-beta.155 (2024-11-20)

#### :house: Internal
Expand Down
7 changes: 5 additions & 2 deletions build/snakeskin/default-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ function tagFilter({name: tag, attrs = {}}, _, rootTag, forceRenderAsVNode, tplN
componentName = tag.camelize(false);
}

const component = componentParams[componentName];
const
component = componentParams[componentName],
isWebComponent = isV4WebComponent.test(tag);

Object.entries(attrs).forEach(([key, attr]) => {
if (isStaticV4Prop.test(key)) {
// Do not change any attrs name for web components
if (isV4WebComponent.test(tag)) {
if (isWebComponent) {
return;
}

Expand Down Expand Up @@ -183,6 +185,7 @@ function tagFilter({name: tag, attrs = {}}, _, rootTag, forceRenderAsVNode, tplN
rootTag,
attrs,
component,
isWebComponent,

isSimpleTag,
isFunctional,
Expand Down
19 changes: 14 additions & 5 deletions build/snakeskin/filters/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports = [
* @param {string} params.isSimpleTag
* @param {string} params.isFunctional
* @param {string} params.vFuncDir
* @param {boolean} params.isWebComponent
* @throws {Error} if the attributes contain invalid values
*/
function normalizeV4Attrs({
Expand All @@ -50,18 +51,26 @@ module.exports = [
attrs,
isSimpleTag,
isFunctional,
vFuncDir
vFuncDir,
isWebComponent
}) {
// Remove empty class attributes
if (attrs['class'] && !attrs['class'].join().trim()) {
delete attrs['class'];
}

// To ensure correct functioning on the client side with functional components,
// we normalize all calls to the v-attrs directive as props
if (attrs['v-attrs']) {
attrs[':v-attrs'] = attrs['v-attrs'].slice();
delete attrs['v-attrs'];
// we normalize all calls to the v-attrs directive as props, except for web components
if (!isWebComponent) {
if (attrs['v-attrs']) {
attrs[':v-attrs'] = attrs['v-attrs'].slice();
delete attrs['v-attrs'];
}

// For the web components v-attrs must be normalized to the directive
} else if (attrs[':v-attrs']) {
attrs['v-attrs'] = attrs[':v-attrs'].slice();
delete attrs[':v-attrs'];
}

if (webpack.ssr) {
Expand Down

0 comments on commit da53a05

Please sign in to comment.