withastro / language-tools

Language tools for Astro
MIT License
261 stars 52 forks source link

🐛 BUG: solid's control flow elements can't infer children props #276

Closed ProspectPyxis closed 2 years ago

ProspectPyxis commented 2 years ago

Describe the Bug

Solid's control flow elements (<Show>, <For>, etc.) requires children elements to be passed. However, using the normal syntax with closing tags throws an error in the editor, requiring you to directly define the children prop manually. The component does compile when running npm run dev, so I can confirm it's just an editor issue.

Steps to Reproduce

  1. Start a new astro project with npm create astro@latest. Select the "Completely empty" template, and enable solidjs integration.
  2. In src, create a new .tsx file and paste in the following:
    
    import { Component, For, Show } from 'solid-js'

const TestComponent: Component = () => { return (

{num}

} />

) }

export default TestComponent

3. Neither components should throw an error.
4. Replace the div's contents with the following:
```tsx
      <Show when={true}>Hello world!</Show>
      <For each={[1, 2, 3]}>{(num) =>
        <p>{num}</p>
      }</For>
  1. Both <Show> and <For> now throws an error: errorscreenshot
Princesseuh commented 2 years ago

The Astro extension does not run inside tsx files 😅

You're missing the required tsconfig.json settings for TypeScript for Solid, that's why you're seeing this error:

"compilerOptions": {
  "jsx": "preserve",
  "jsxImportSource": "solid-js",
}

(From https://github.com/solidjs/solid#quick-start)

ProspectPyxis commented 2 years ago

Ah, oops. :sweat_smile: Apologies for the user error, it only happened when I was using astro with solid so I assumed, haha.