-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
The behavior about width or height attribute of <img /> is not diffrent between vue and original html #8780
Comments
should be |
I know this point, but why not preserve the attribute written by the user, instead, rewrite it to 0? Mdn did not say that when a value has units, it needs to be rewritten to In standard html, when give dom a invalid attribute or a invalid value of attribute, html will preserve it. So I don't think rewrite it to 0 is a good choice. |
Agree with this issue. Currently, native HTML, react, solid, and svelte can all support width with units, but only Vue does not support it, which is very awkward. |
I agree. But when a user gives an invalid value, vue should keep this value and let the HTML handle it according to browser's standard, rather than handling it at the Vue level. |
Firstly, contrary to what you said, most browsers support this usage, and in fact, I don't know which browser does not support this usage, could you please give me an example? Another point I want to express is that if a user writes an incorrect HTML fragment in the template section of a Vue, the Vue should keep the corresponding HTML fragment intact and leave it to the browser to process the HTML, rather than modifying it into an HTML fragment that is inconsistent with the user's code. |
I deleted my comment as I misremembered it from our last discussion about this in #7658. In most cases Vue tries to set properties if they exist. Shall we keep all invalid attributes in HTML? If so I think we need to always prefer setting attributes for string values. This also solves the inconsistency described at #7658 (comment). |
I think it is necessary to preserve the attributes in all user code. For example, sometimes users may add an attribute to the dom that is not in the HTML specification and unify the dom with that attribute. Therefore, Vue should preserve the user's code. |
That’s not the case here. Vue only sets bindings as properties if they exist on the element. Unknown attributes are always set as-is. |
Yes, I just made an analogy of this situation. When you give a non integer value to the width of the img tag in a pure HTML file, the HTML will retain your code and let the browser handle it, but Vue will change your code to |
I've just encountered that strange behaviour. I wish vuejs/core team member would handle that issue. |
At present, |
This patch breaks everything. I am using custom components:
No |
Vue version
3.3.4
Link to minimal reproduction
https://play.vuejs.org/#eNqNUctOwzAQ/JXIZxJXlFNVUAH1AAdAwDGXNFlSF79kr5tKVf+dtVvSUB7i5p1Z78zObtm1tcU6AJuwqa+dsJh5wGCvSj3le4CeVCAoKysEqrJsKlSbeVdflmyJaP2E867r4px85YvaKG7DQoqaC1W14DkRhdVtybJONLikb+ejkd1QzZNQP5ydMaGscZiryhYrbzQZ20bJ8kD4kk2yhESMBsf6aKNuNH1rQIq1KzQg11bxGbVxFzQKBXlj1GxcjIsL3giPQ7gAr/KFM50HR0NKdjaQ4QSuweUOdAMO3H9lT74NpU+ob/JRfVfqHYWCvjb6TbQnkVDSVkhwjxaF0V+jqaQ03X3C0AXod6mXUL//gK883SPu9OQgORvsj5VrAff0/OUBNvTuSWWaIA9n+IV8Bm9kiB73bTdBN2R70Jfc3qULC92++vkGQfvPpaLRlEbqT/e4/WP1o11Ku09x9wFaCvxF
Steps to reproduce
Just need to open the link: reproduce link
What is expected?
When the
width
orheight
attribute of the emmebbed tag such as<img />
is not a integer type, it will be rewrite to0
.I have known that mdn specify the height or width of
<img />
must be an integer without a unit. But in fact for most browsers, when we set thewidth
orheight
of<img />
with unit, it can also work.So when user give a non pure numerical value to the
width
orheight
attribute of<img />
, vue should preserve the attribute written by the user on the HTML tag instead of rewriting it to 0. The specific rendering behavior is left to the browser to decide.What is actually happening?
The behavior is different between vue and html:
In vue:
![image](https://private-user-images.githubusercontent.com/73059627/253443931-dda8b855-2a5f-4d61-9727-5df109cdee4c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMzEyMTQsIm5iZiI6MTczOTIzMDkxNCwicGF0aCI6Ii83MzA1OTYyNy8yNTM0NDM5MzEtZGRhOGI4NTUtMmE1Zi00ZDYxLTk3MjctNWRmMTA5Y2RlZTRjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDIzNDE1NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBhYjM5NDVjNzY5ZDA5N2ZkMmZmMTYyZDJlY2Q3OTA1YjlkMWRmNDkyMjhlY2Y0NGI5ZmQzYzBhOWNlN2NmMjYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.iFAlgWg4mpKUw75WItSRG-0CycQjLFn19chXw8N9F5A)
In html:
![image](https://private-user-images.githubusercontent.com/73059627/253447341-06c34b55-5539-4646-b30b-c0e193f12082.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMzEyMTQsIm5iZiI6MTczOTIzMDkxNCwicGF0aCI6Ii83MzA1OTYyNy8yNTM0NDczNDEtMDZjMzRiNTUtNTUzOS00NjQ2LWIzMGItYzBlMTkzZjEyMDgyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDIzNDE1NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI5MjMyNWJhYjg5YWIzYjQ1YTE1MDVkOWY4MWY3MWJjZGFlZTQxYWEzNjZhYjhmOTVhNWE0MTU4NjY2NWJjNDYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.29z7jTHBFGjQn9ny54dLBK1aJO_Z48iNEDnlSAlOwxA)
System Info
Any additional comments?
No response
The text was updated successfully, but these errors were encountered: