NativeBase: VSCode high CPU when browse StyleProvider
Hi,
I’ve isolated a weird behavior in my workflow.
I’m using :
Win10
vscode 1.36.1
RN 0.60.4
Native-base 2.13.4 with theme ejected and up to date
As soon as i open the file that containing the styleProvider component and modify it, intellisence goes very slow on all the other files.
When i look at my process explorer, it looks like this screenshot above and it never improve before i restart VScode even if i close the problematic file.

Here a simple exemple that has the problem :
import React, { Component } from 'react';
import { Root, StyleProvider } from 'native-base';
import getTheme from '../native-base-theme/components';
import platform from '../native-base-theme/variables/platform';
import Main from './Main';
export default class App extends Component {
constructor(props) {
super(props);
}
render() {
return (
<Root>
<StyleProvider style={getTheme(platform)}>
<Main />
</StyleProvider>
</Root>
);
}
}
A workaround is to isolate this piece of code and never open it to keep vscode stable. I’ve no error or warning due to lint/flows/etc… It worked nice before my migration to RN 0.60.4 from RN 0.59.9
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 15 (2 by maintainers)
confirm on MacOS: vscode 1.37.1 RN 0.59.9 Native-base 2.13.4
workaroud
.vscode/settings.json:it’s works!
After trying for about 3 hours, I found it is the variable file (for me its
platform.jsandcommonColor.js) leads 100% CPU, and I figured out tsserver cannot handle so muchPLATFORM.IOSand it stucks atsemanticDiag.My workaround is to add a variable
isIosto replaceplatform === PLATFORM.IOS, it works perfect.I opened a PR #3024 for my fix, it should be an elegant way to resolve this.
My project does not eject the theme but rather extends by spread operator (…) from
native-base/src/theme/variables/platformbefore callinggetThemeHere is the variation of
platform.jsthat eventually worked with Intellisense though I am unsure why refactoring all of thePLATFORM.IOSrefs back to “ios” makes it work.Try
npm install typescript@nextand tell VSCode to use the local Typescript-Version. That fixed it for me.For some reason, a simple replacement of
PLATFORM.*constants with string values works, like suggested in this comment.@kagurazakakotori Sadly, PR stuck on formatting issues. I shortly reviewed changes, IIUC this will prevent another platform from being injected like
getTheme(variables). The platform was originally provided via DI,const platform = variables.platform; ... platform === PLATFORM.IOS. And nowisIosis hard-coded to current platform. This doesn’t seem to affect the lib itself but could affect theme customization in third-party code.I’ve spent a whole day in finding out why TS is broken, so created a JSON file having theme variables & then passing it to
StyleProviderThis is probably the same… I’m happy not to be alone on this case 💃 I’ve decided to touch theme files the less i can !