-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Literally undefined class #3283
Comments
When we're walking through the AST and want to update a node containing |
Similarly, I often mix static and dynamic classes. Ideally, I'd be able to write the following: <script>
let dynamicClass = undefined;
</script>
<h1 class={"fixedClass" + dynamicClass}></h1> With a desired output of: <h1 class="fixedClass"></h1> The closest way to achieve a similar result right now is with a bit of extra logic: <h1 class={"fixedClass" + " " + (dynamicClass || "")}></h1> |
That's unrelated to the bug this issue is about, and is something we don't want to do. We're not going to mess with what things like |
Understood. Thanks for the clarification, @Conduitry. |
@Conduitry Hello! I work on "Literally undefined class #3283" and found a possible solution. We may add 2 new code string in compiler/../Attribute class, but we add condition from image in the COMPILED file (more precisely "create_fragment")(screens only as example). I understand your comment correct (you placed info about possible resolution strategy in the issue)? It's possible to open mr, but i don't want to spend your time on mr review in a situation where I may misunderstand the main idea about svelte / bug. Thanks |
Either svelte could make use of just another small library like classnames or clsx or create it's own similar resolver function, rather than generating Then there is the case of |
@deviprsd it should remove only |
@cvlab it should remove all falsy values unless passed as string, I have tried to use a variable containing P.S. The proposed fix |
@deviprsd I mean @Conduitry fix, it not remove all falsy values. There are many attributes in html elements, for some |
@deviprsd Why only |
@cvlab lets say I had an app with multiple classes or attributes, and taking @Conduitry fix class="{class1 == null && class1 == undefined ? '' : class1} svelte-123app"
class="{class2 == null && class2 == undefined ? '' : class2} svelte-124app"
class="{class3 == null && class3 == undefined ? '' : class3} svelte-125app"
...
class="{class50 == null && class50 == undefined ? '' : class3} svelte-200app" Doesn't this make the app bigger and also adds a lot of checks if you had a big app?
I agree with this too, what if there is a helper function? |
@deviprsd You need only |
First of all, https://www.stevefenton.co.uk/2018/04/catching-null-and-undefined-without-side-effects/ there is performance overhead, it's obviously not much but why avoid optimization when there can be other ways
Your way is not everyone's way, no app is the same |
Is it not possible to simply try: class="{class1 || ''}" ? Or even better :
then:
? |
@deviprsd I did not see performance overhead, in your article. It Do you know another way to save result of function? |
It does, but it also says that, and I did say the overhead is not much but we should look for other ways first
Yes, |
@deviprsd I'm not sure, but No, it's not complex, because for svelte/src/runtime/internal/dom.ts Line 94 in 0be4e28
<div { ...{ class: undefined} }></div>
|
No it isn't, there is some type coercion as
I don't think either of the solutions is a good idea, you are not thinking in the perspective of a big app. |
I looked right now, in V8
Sure, you are welcome to propose good ideas. |
fixed in 3.6.11, thanks! |
There is a very small bug. When there is
undefined
class value and some styles, the element will get literallyundefined
class.will produce
PS: For my components I like nice way to define combination of external and internal classes, just to use
true
instead of concatenation:The text was updated successfully, but these errors were encountered: