-
Notifications
You must be signed in to change notification settings - Fork 30.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
[@types/styled-components] Performance issues on compiler #34391
Comments
Does this also happen with typescript 3.3? |
I experienced same issue package.json devDependency
dependency
My problem is that it looks like webpack & webpack-dev-server can not parse @types/styled-components. Because when use just styled-components, there was no problem. It always happen when use @types/[email protected] same time. Before seeing issue of @voliva, I found infinite loop problem of webpack because it use cpu resource 100%. After changing @types/styled-compoents version to 4.1.5, it looks like everything is ok. |
@eps1lon: Nope, typescript 3.3 is fine; specifically, it looks like the issue starts under release 3.4.0-dev.20190226. Using @voliva's seed repo, I believe I've pinpointed the issue to the recursive usage of type OmitU<T, K extends keyof T> = T extends any ? PickU<T, Exclude<keyof T, K>> : never; And here are both of the places Definition of type WithOptionalTheme<P extends { theme?: T }, T> = OmitU<P, "theme"> & {
theme?: T;
}; Usage of WithOptionalTheme<
OmitU<
ReactDefaultizedProps<
C,
React.ComponentPropsWithRef<C>
> & O,
A
> & Partial<PickU<React.ComponentPropsWithRef<C> & O, A>>,
T
> Something about the union-distributed (Note that the To test this, I swapped out one or both of the distributed type OmitPickU<T, K extends keyof T> = PickU<T, Exclude<keyof T, K>>;
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; Here is
Running times for typescript 3.3.3 and 3.3.4000 are consistent with 3.4.0-dev.20190223 -- roughly 6 seconds across the board. I'm not familiar enough with styled-components to propose a solution, but I hope this data helps! |
I can confirm I have the same issue. Downgrading @types/styled-components to 4.1.5 worked for me as well. I'm on typescript 3.4.1 |
@michsa I was expecting some reduction but not a 10x. Since this was introduced in typescript 3.4 could you open an issue in the typescript repo as well? I would like to make sure we don't revert a bug fix if it's a regression that should be fixed in typescript. |
Sorry I initially didn't search in typescript's github, I found this issue they are currently investigating: microsoft/TypeScript#30663 |
@weswigham @RyanCavanaugh Can we please look into quickly publishing a revert to the styled components types that does not have the perf issues on 3.4. With the VS Code 1.33 release, a lot of js users are going to be downloading the bugged types through automatic type acquisition. Once this happens, to get out of the bad state, I believe that you either have to clear your automatic type acquisition cache or install the fixed |
This seems like it may still be an issue with @types/styled-components 4.1.19 and TS 3.6.3. TS completion and error highlighting taking 5-10+ seconds on 2018 i7 macbook pro 15. Need to do some more investigation. |
Erm, the OP is talking about 90s compilations (a 9x jump in time form the prior styled components version), seeing as both later version of TS have mitigations in place and later version of styled components were simplified to not have so much of a perf issues, 5-10s is maybe just your project and deps behaving normally. |
I hope not! It's frustratingly slow now when it wasn't in the past. I'm going to look into it further and report back here if it appears to be related to this issue. |
I'm experiencing the hell in the CSS-in-JS haven when I am coding with VSCode. |
@AndrewMorsillo @hilezir I switched from styled-components to styletron, using TS 4. Performance in styletron is much better both in vscode and in the browser. But I don't know about styletron on React Native. |
Is too late for us to make this change but I haven't heard of styletron and definitely like the looks of it more than styled components. |
Will there be a new issue or will this issue be reopened? There are still great performance issues with @types/styled-components 5.1.2 and TS 3.9.7 |
Spent a whole day trying to figure out how to speed up VSCode and finally figured out it was I was using TypeScript 4.0.3 and |
can someone suggest a better alternative to styled-components. my vscode completely freezes. |
try this? |
There is actually a Pull Request open to improve |
I am still experiencing very slow type checks with I compared on the following component : <Title variant="header">Hello</Title> If I remove the I tried to switch to I asked some colleagues and they had the same issue on other projects. |
Yesterday i had vscode tsserver performance issue in next.js typescript styled-components project. I fix it by removing styled-normalize from project and import it directly by link tag in _app.tsx. |
Unfortunately I do not use |
I had the same issue, switched to emotion and it works actually much better |
My intelisense is extremally slow when using the 5.1.9 version. Errors were taking over 10 seconds to show up and the intelisense was taking over 5 seconds. The issue disappeared when downgrading to 4.0.3 version. Not the best solution but worked for me. |
We should identify what's changed, then! Also, we could take inspiration from emotion's types. They work really well, and the API is the same. |
same 2!!! |
Why is this issue closed? Everyone seems to be having this issue. |
Do you find emotion has a similar / replaceable API with styled-components? I am working on getting our compilation speeds back up to snuff only to realize I think this is the only issue. |
Well, the migration is quite easy. It depends on the size of your project, but it's mostly replacing imports from styled-components to emotion. On react-native, there is an annoying problem with emotion though (but it has a solution). This doesn't work anymore :
because emotion doesn't convert numbers to string properly inside template strings.
Which does exactly the same but won't cause any issue to emotion. |
In case it helps anyone, I solved my own problem by creating my own type definitions for Styled Components. It was intended to be a temporary fix but ended up doing everything I needed. If you'd like to use it, just remove your dependency on |
TSSERVER broken in 5.1.15!!!!!!!!!!!!!!!!! |
A little bump here - removing |
Hi Everyone I've been having this issue for a while now. Downgrading @types/styled-components worked for me. yarn add @types/[email protected] |
|
I have discovered that, for us at least, a lot of the performance issues stem from the types deriving massive unions of all the valid JSX elements. Such large unions can be a performance issue as described here: https://github.com/microsoft/TypeScript/wiki/Performance#preferring-base-types-over-unions So I created custom types that replace usages of
I just define the element types I actually use and add them as necessary. I'm never going to do It makes a noticeable and worthwhile difference and I haven't needed to sacrifice any typing capabilities. |
@djskinner Do you have the steps to achieve the replacements? |
I created a file called - import styled from 'styled-components'
+ import styled from 'styled-components-fast' Note: the way the project is set up with webpack module resolution allows for this type of absolute import. You may need to do something like
Note:
|
Please open this. Still a big problem... |
Adding the latest version of @types/styled-components to an existing project causes build times to go up by about 1-2 minutes, by using the latest [email protected].
By using this seed repo, I've tested the following versions:
My machine is a Linux 4.18.0 (Ubuntu 18.10) laptop, with a i7-6700HQ CPU @ 2.60GHz
It seems clear that the release 4.1.11 is what's causing this performance issue. The PR for this release is #33061. As of why, I really don't know - I tried to dig into the internals of the compiler to see where it was getting stuck at, but I couldn't understand it.
@types/xxxx
package and had problems.Definitions by:
inindex.d.ts
) so they can respond.The text was updated successfully, but these errors were encountered: