Skip to content
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

Svelte 5: Components think children prop is being used when commented code is inside their tags #2263

Closed
HighFunctioningSociopathSH opened this issue Jan 8, 2024 · 1 comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@HighFunctioningSociopathSH

Describe the bug

Commented-out code is thought to be the children of a component. For example, if you pass a component that doesn't expect a children prop then you will encounter an error saying Object literal may only specify known properties, and 'children' does not exist in type 'Props'. Comments should be ignored as the value of the children prop.

Reproduction

let's say you have a component that doesn't take a children prop.

simpleComponent.svelte

<svelte:options runes />
<script lang="ts">
  let {name, age} = $props<{name: string; age: string}>()
</script>

+page.svelte

<svelte:options runes />
<script lang="ts">
  import simpleComponent from "$components/simpleComponent/simpleComponent.svelte";
</script>

<simpleComponent>
<!-- any kind of comment or even empty HTML comment will cause the component to think it is being passed the children prop -->
</simpleComponent>

You will get the previously mentioned error.

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22621
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-12650H
    Memory: 7.03 GB / 15.63 GB
  Binaries:
    Node: 18.14.2 - C:\Program Files\nodejs\node.EXE
    npm: 9.7.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (120.0.2210.121)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    svelte: ^5.0.0-next.29 => 5.0.0-next.29

Severity

annoyance

@Rykuno
Copy link

Rykuno commented Jan 18, 2024

I'm having the same issue.

"svelte": "^5.0.0-next.1",

@dummdidumm dummdidumm transferred this issue from sveltejs/svelte Jan 18, 2024
@dummdidumm dummdidumm added the bug Something isn't working label Jan 18, 2024
dummdidumm added a commit that referenced this issue Feb 7, 2024
- ignore comments when determining whether or not to add an implicit children prop #2263
- do static analysis of the destructuring to see whether or not children is destructured from `$props()`, and if not, add the implicit children prop if there's a slot. This results in less confusing type errors when transforming to runes mode and using a slot
dummdidumm added a commit that referenced this issue Feb 7, 2024
- ignore comments when determining whether or not to add an implicit children prop #2263
- do static analysis of the destructuring to see whether or not children is destructured from `$props()`, and if not, add the implicit children prop if there's a slot. This results in less confusing type errors when transforming to runes mode and using a slot
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

3 participants