Gracefully handle common HTML attributes when they don't exist as props on component (e.g. id
or class
) during dev
#53
Labels
enhancement
New feature or request
Describe the problem
Right now, even though
svelte-retag
should already already know all valid props ahead of time, it will still dutifully forward attributes that it is not aware of. That even includes ones which may have no relevance to the component itself and may purely only be useful in HTML, for example:class
- useful for styling/positioning the host elementid
- useful for linking to the host element (e.g.example.com/#element-name
)data-*
attributes which may be exposed for unit testing purposesThis results in a large number of console warnings similar to this (screenshots below):
Describe the proposed solution
It would be cool if
svelte-retag
had a way of ignoring these warnings without being too heavy handed. Some developers may actually want some of these attributes to be passed along. Warnings in that case would be super useful (reminding them that they may have accidentally forgotten to theid
prop to their component).However, in many situations like those noted above, this may also be annoying. Especially if you want to use a custom element as a page anchor that you can link to or want to position it with a CSS class (but don't have any reason to use that CSS class in the component itself).
Some solutions:
attributes: true
is specified (i.e. user is just auto forwarding all attributes without explicitly listing them)id
,class
ordata-*
svelte-retag
has not detected this prop/attribute (i.e. via the proxy which infers all props on the first render)ignoreCommonAttribWarnings: false
.true
to allowsvelte-retag
to decide which attributes to ignore (i.e. the list above) or can set to an array so the developer can tell it to only ignore the desired attributes.Option 1 feels better because it's more direct, but it does change the functionality of
attributes: true
slightly. It could confuse users if they expected<example-element id=...>
to trigger a warning if the user didn't have theexport let id;
defined in their component. The biggest risk here though is likely going to be for existingsvelte-retag
users who may update, but not realizeattributes: true
has changed to now skip forwarding some attributes if they don't also exist already on the component.On the flip side, 2 is good because it's a little more careful, but if not done right it could confuse people who expect it to ignore common HTML attributes all the time (which that isn't going to be the case; only if it isn't also present). 🤔
Alternatives considered
Ignore the warnings during development. They do not occur in the production builds.
Importance
nice to have
The text was updated successfully, but these errors were encountered: