Preact: Preact/compat - Input value does not show up in the HTML

Created on 4 Aug 2020  路  4Comments  路  Source: preactjs/preact

Reproduction

Steps to reproduce

Type "anything" in the email input.

Expected Behavior

Inspecting the input element shows a value of "anything".

Actual Behavior

Inspecting the input element does not show a value.

Note

If the default value is an empty string, the input value appears as an empty string in React.
Screen Shot 2020-08-03 at 8 31 24 PM

compat wontfix

All 4 comments

Thank you for reporting this issue. This seems to be (kinda) expected behaviour as we are using different DOM APIs as react does and thus the browser devtools are not updated.

Would you mind sharing your usecase where this is an issue?

Note that this only affects getAttribute('value') but not .value:

image

image

Hi @christianpv! Thanks for the issue, and thanks for the quick and accurate response @sventschui.

Just to echo: this is very much working-as-intended. The value of an input should never be reflected in the DOM, doing so is actually a known security vulnerability. Last time I looked into it, React plans to correct this behavior in their next major version.

For what it's worth, Preact _does_ correctly render using the value="" attribute during SSR, where doing so is necessary and intended.

@developit Thanks for the quick reply. I ran into this issue when I tried to replace React with Preact. Some of our unit tests were not passing due to the value not rendering but this issue is not affecting us anymore since we rewrote the tests. Thanks again!

Awesome - thanks for the context, that's useful to know. It might be good for us to update the docs to cover this somehow.

Was this page helpful?
0 / 5 - 0 ratings