Comments (9)
@rejhgadellaa have you checked the latest version? I believe that was a bug that was corrected.
Edit: Never mind, hasn't been released yet. Fixed in #4393 though
from preact.
Answer: it depends, sometimes Preact sets the
.foo
property, sometimes Preact sets thefoo
attribute. The user has no control over this.
While I don't disagree with the premise/request, and have written up minor forks/patches that add this, there are quite defined rules. It's not random or a guess: if the provided label has a DOM property, and isn't from a small list of excluded labels, it gets set as a property, else, attr.
Preact (and other UI libs) aren't "guessing" at what others expect; they work with the DOM as they see fit. It's up to the individual devs to reconcile the expectations of different pieces of software. More control here would absolutely help devs reconcile those expectations, but I just want to make it clear that it isn't really a project goal to "guess correctly" as you put it.
from preact.
It's not random or a guess: if the provided label has a DOM property, and isn't from a small list of excluded labels, it gets set as a property, else, attr.
Perhaps "heuristic" or "rules" are better terms. To re-express with those words, no heuristic or rule can satisfy all scenarios because all scenarios can only be users picking which to use.
from preact.
Not quite what I meant, no. We largely set what we set, we're not looking to satisfy any scenarios beyond "works with DOM APIs correctly". Anything beyond that is a non-goal of the project really, something for users to address. It's not a concern of the project if it doesn't enable a CSS selector, for example.
Not having great tools for users to address these issues is, however, a valid issue for the project, if that makes sense.
Minor (perhaps frivolous) semantics, I know, but I want to clarify project goals.
from preact.
I'm not sure what's the debate. In my mind it's a valid request (and likely project goal) to be able to control DOM elements with a DOM framework like Preact (wanting to set an attribute to use for CSS selecting is but one of many reasons), but of course that's up to each framework.
I changed the issue template to feature request (accidentally chose bug first).
from preact.
I recently ran into the popover
property not accepting boolean values, but the attribute can be a boolean (it will then default to auto
). So this:
<menu popover />
Will actually try to set Element.popover = true
(which is an error)
You have to write:
<menu popover="auto" />
Not a big problem, but annoying 😅
from preact.
@trusktr I'm saying the comments of "It is not possible for Preact to always guess correctly which of the above cases the user will want" and "no heuristic or rule can satisfy all scenarios" aren't really relevant as it's not, nor was it ever, a project goal to do that. That was always on the user's end of things.
I just want to make that clear as the inability to "guess which cases the users will want" is not in itself a problem or a valid issue, as we never made any attempt at all to guess what a user could prefer in sone scenario. Lack of tools for the user to set things how they want, however, is absolutely a valid issue.
It's somewhat important framing, as it's confusing fundamental project goals, but I digress.
from preact.
@rschristian oh sweet, I actually thought this was "working as intended", and maybe even more of an issue of the spec where the property and attribute don't accept the same argument types. Thanks!
from preact.
why not check the static observedAttributes
? If my custom element is interested in e.g. disabled
I must add "disabled" to the observedAttributes property anyway - which should sufficiently state that I am indeed interested in the content attribute and preact should not just drop that
from preact.
Related Issues (20)
- [email protected] unexpected child ordering with skew based diff HOT 2
- [email protected] application is broken on old user agents HOT 2
- useEffect never called HOT 2
- JSX prop works incorrectly on Custom Element, Preact fails to detect JS property setter HOT 5
- [preact/hooks] useMemo keeps recalculating even when the dependency is not changed HOT 2
- JSX type errors on React Bootstrap 2.x & Preact 10.x HOT 6
- Type inference of Omit type not working, CSSProperties in preact/compat HOT 3
- Options debounceRendering and requestAnimationFrame HOT 1
- Support cleanup functions for refs
- Suspense / ErrorBoundary content rendered twice when hydrating with render HOT 1
- Consider bumping version of `@preact/compat` to 18
- RFC: Hydration 2.0 HOT 2
- Aliasing in node refers to the old @preact/compat HOT 2
- Failed to execute insertBefore DOMException happens on rendering list of items HOT 2
- preact demo won't run
- Minified Preact code causing Error by storing event handlers in `l` property on elements causing a name conflict HOT 4
- Wrong typing for HTML translate property HOT 3
- preact cannot be installed from git remote url HOT 2
- Hooks broken in pure browser aka "no build tools route" HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from preact.