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 for VS Code extension crushes react project #1149

Closed
florianGierlichs opened this issue Aug 27, 2021 · 12 comments
Closed

Svelte for VS Code extension crushes react project #1149

florianGierlichs opened this issue Aug 27, 2021 · 12 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@florianGierlichs
Copy link

Describe the bug
After installing the Svelte for VS Code extension in my editor to work on a svelte project, a different project written in react and typescript completely crushes and throws ts error all over the place:

Type '() => svelte.JSX.Element' is not assignable to type 'FC<{}>'.
  Type 'Element' is not assignable to type 'ReactElement<any, any> | null'.
    Type 'Element' is missing the following properties from type 'ReactElement<any, any>': type, props, key

literally every .tsx file throw errors, the project worked flawlessly before installing the svelte extension.

The only way I found so far, is to disable the extension every time I'm not working on a svelte project, which sucks, you know.

To Reproduce
Steps to reproduce the behavior:

Open a react-ts project with the svelte extension in VSCode i guess.

Expected behavior
svelte extension doesn't influence non-svelte projects

Screenshots
image

image

System (please complete the following information):

  • OS: MAC OS
  • IDE: VSCode
  • Plugin/Package: "Svelte for VSCode"
@florianGierlichs florianGierlichs added the bug Something isn't working label Aug 27, 2021
@dummdidumm
Copy link
Member

dummdidumm commented Aug 27, 2021

Did you enable the TypeScript plugin of the extension (https://github.com/sveltejs/language-tools/tree/master/packages/svelte-vscode#svelteenable-ts-plugin)? If yes, that could be the reason (though I need to investigate why this happens and fix that)

@florianGierlichs
Copy link
Author

I tried with the plugin enabled and disabled. Both ways don't work, unfortunately.
I'm wondering, there are not more people who run into this problem...

@dummdidumm
Copy link
Member

dummdidumm commented Aug 27, 2021

Is it every react project, or only specific ones? Which version of "Svelte for VS Code" is installed? I can't reproduce this.

@florianGierlichs
Copy link
Author

I tried different react projects, the errors appear in every project.
"Svelte for VS Code": v105.3.5

@dummdidumm
Copy link
Member

From the errors it sounds like the ambient definitions of svelte2tsx interfere with TSX somehow. But I fail to get why this would get picked up by TS, because the Svelte extension only operates on Svelte files, not TS(X) files. Only the TypeScript plugin would add Svelte capabilities, but we added a check recently to not initialize if a React project is detected - but you said you even get that behavior when the plugin is disabled, which is very strange. What's even more confusing is that the ambient definitions of svelte2tsx should not even get picked up because they are within the svelte.JSX namespace, which should not be picked up by React projects. Do you have svelte-check installed globally by any change, and if so, which version? If so, what happens if you uninstall it from the global modules?

@sudomf
Copy link

sudomf commented Sep 30, 2021

I'm having the same problem in a monorepo containing svelte and react projects.

@sudomf
Copy link

sudomf commented Sep 30, 2021

It backs to work if I disable the Svelte extension. Looks that somehow the extension is injecting the svelte-jsx.d.ts file.

@dummdidumm
Copy link
Member

Could you check if the problem persists with the latest release of the Svelte extension (105.4.2) ?

@sudomf
Copy link

sudomf commented Oct 8, 2021

@dummdidumm still happening here

image

@danielquintero
Copy link

Could you check if the problem persists with the latest release of the Svelte extension (105.4.2) ?

Having the same issue in an Nx monorepo with svelte and react. Enabling svelte plugin (with/out ts support) breaks "react", same as @maykefreitas ☝🏼

@jasonlyu123
Copy link
Member

Wondering if the tsserver reuses the same language service for both the react project and the svelte project. Can you try if adding a jsconfig.json to the svelte project root solved the problem?

Here's an example jsconfig:

{
    "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
}

dummdidumm added a commit that referenced this issue Jan 27, 2022
Goal: Get rid of a tsx-style transformation and simplify transformations along the way
#1077
#1256
#1149

Advantages:

-   no messing with projects who use JSX for some other reason and then have conflicting JSX definitions
-   TS control flow easier to keep flowing
-   overall easier transformations of Svelte specific syntax like await, each etc.
-   better type inference in some cases, for example around svelte:component

This includes:

-   rewriting the html2jsx part of svelte2tsx
-   adjusting the language server to the new transformation
-   adding a toggle to language-server and vs code extension to turn on the new transformation. Default "off" for now, with the plan to switch it to "on" and then removing the old transformation altogether
-   ensuring tests run with both new and old transformation
-   adjusting the TypeScript plugin. It uses the new transformation already now since it's not easily possible to add an option (on/off). Should be low-impact since TS doesn't need to know much about the contents of a Svelte file, only its public API

Look at the PR of this commit to see more explanations with some of the entry points of the new transformation.
@dummdidumm
Copy link
Member

The most recent versions of the extension and svelte-check contain a new transformation behind a flag which should fix this issue. You can try out the new transformation using

  • "Svelte for VS Code" version 105.11.1 and setting svelte.plugin.svelte.useNewTransformation to true
  • svelte-check version 2.4.0 with the --use-new-transformation flag.

Please try it out, more info in #1352

@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Dec 21, 2022
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

5 participants