🐛 BUG: Undefined behavior when I pass children to a component that has no <slot/>
#689
Replies: 7 comments
-
Do other frameworks warn here? When we've updated the VSCode extension to be more intelligent it might be able to tell you that there is no slot for this component. |
Beta Was this translation helpful? Give feedback.
-
Since the VSCode extension is just based on the LSP which is based on the compiler, maybe that's something we can detect in the compiler and then surface through that chain of communication? |
Beta Was this translation helpful? Give feedback.
-
Shouldn't this be a build-stopping error? |
Beta Was this translation helpful? Give feedback.
-
We don't stop the build (or throw) for any other mistakes so I don't think we should do so here. |
Beta Was this translation helpful? Give feedback.
-
Ah, I assumed we did since I've run into errors that fail to build pages in dev mode, ok |
Beta Was this translation helpful? Give feedback.
-
It depends on the type of error. Passing an unwanted slot doesn't cause any errors. For example, if you failed to pass a prop to a component the component could choose to throw. If an API existed for slots like in withastro/astro#1225 then a component could throw for slots being wrong. Maybe what you're looking for is a type checker like svelte has with svelte-check. Such a tool could error on things like this. |
Beta Was this translation helpful? Give feedback.
-
+1 for treating this like a TS error, similar to what happens when you use a bad prop. Even better if we can support type checking based on slot names, and warn if you use an incorrect slot name. |
Beta Was this translation helpful? Give feedback.
-
What package manager are you using?
npm
What operating system are you using?
mac
Describe the Bug
Given this component usage:
I would expect this to warn or error if
WrapChildrenWithText
did not have a<slot>
defined. Currently, I do not know what will happen other than we aren't providing warnings./cc @natemoo-re
Link to Minimal Reproducible Example (Optional)
No response
Beta Was this translation helpful? Give feedback.
All reactions