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(runtime-dom): undefined cssvars should not be bound to the element #7475

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

baiwusanyu-c
Copy link
Member

close: #7474

@baiwusanyu-c
Copy link
Member Author

I tried adding a unit test, but there is a difference in how the setProperty method handles undefined in node vs browser, which prevents me from reproducing #7474 in jest, I think I need some guidance

@@ -80,7 +80,9 @@ function setVarsOnNode(el: Node, vars: Record<string, string>) {
if (el.nodeType === 1) {
const style = (el as HTMLElement).style
for (const key in vars) {
style.setProperty(`--${key}`, vars[key])
if(vars[key]){

Choose a reason for hiding this comment

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

Just want to note this condition will prevent setting empty strings to the property.

I think there is at least one use case where this might be preferred, as an empty string would be a valid value for a content property.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with your opinion 😊

Choose a reason for hiding this comment

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

Just want to make sure this comment is not holding up this PR. It's good since 91a2dc6, but there is no option for me to resolve this comment.

@netlify
Copy link

netlify bot commented Jan 8, 2023

Deploy Preview for vuejs-coverage failed.

Name Link
🔨 Latest commit 3798471
🔍 Latest deploy log https://app.netlify.com/sites/vuejs-coverage/deploys/63bacd776b170400085a778a

@vercel
Copy link

vercel bot commented Apr 6, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
sfc-playground ⬜️ Ignored (Inspect) Apr 6, 2023 0:44am

Copy link

github-actions bot commented Dec 19, 2023

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 90.2 kB (+14 B) 34.6 kB (+9 B) 31.2 kB (+8 B)
vue.global.prod.js 147 kB (+14 B) 54.1 kB (+8 B) 48.1 kB (+37 B)

Usages

Name Size Gzip Brotli
createApp 49.7 kB 19.5 kB 17.8 kB
createSSRApp 53.2 kB 21 kB 19.1 kB
defineCustomElement 51.9 kB 20.2 kB 18.5 kB
overall 63.2 kB 24.5 kB 22.3 kB

Copy link

codspeed-hq bot commented Dec 19, 2023

CodSpeed Performance Report

Merging #7475 will not alter performance

Comparing baiwusanyu-c:bwsy/fix/CSSVarsUndefined (6b36b86) with main (bae79dd)

Summary

✅ 53 untouched benchmarks

Copy link
Contributor

@skirtles-code skirtles-code left a comment

Choose a reason for hiding this comment

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

I think it needs to clear any old value for the property when the new value is null/undefined. e.g.:

Currently the text remains blue in that example after clicking the button, which is incorrect.

@PeterEsenwa
Copy link

PeterEsenwa commented May 19, 2024

@baiwusanyu-c, is this PR ready to go through? I can try to fix the failing test, if that is all that is left.

@haoqunjiang haoqunjiang added 🧹 p1-chore Priority 1: this doesn't change code behavior. scope: sfc-style-vars labels May 29, 2024
@skirtles-code
Copy link
Contributor

There's also a potential problem with components that render recursively. If the inner component doesn't set the variable then it will be inherited from the outer component:

Setting a variable to null already behaves this way, so it could be argued that this PR is just making undefined consistent with null. That said, I'm not sure whether this is desirable or not.

@edison1105 edison1105 added the ready for review This PR requires more reviews label Aug 21, 2024
@adamdehaven
Copy link

Setting a variable to null already behaves this way, so it could be argued that this PR is just making undefined consistent with null. That said, I'm not sure whether this is desirable or not.

I think the answer is yes, as I would not expect undefined to ever be bound to an element via CSS Custom Property.

Is there anything else holding up this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧹 p1-chore Priority 1: this doesn't change code behavior. ready for review This PR requires more reviews scope: sfc-style-vars
Projects
Status: Needs Review
10 participants