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

Hot Reloading TypeScript component triggers rendering of ancestor TypeScript components #66

Open
ajcrites opened this issue Jun 7, 2018 · 10 comments

Comments

@ajcrites
Copy link

ajcrites commented Jun 7, 2018

I'm not sure that this is directly related to this transformer, but this is quite frankly the best documentation for working with React Native and TypeScript that I can find, so I'm hoping that it can either be fixed in the transformer directly or at least someone has some advice.

It seems like if you make a change to a TypeScript, .tsx component it triggers a render of any ancestors during hot reloading. If you make a change to a .js component, it won't do this -- even if the ancestors are .tsx components.

You can see an example of this here: https://github.com/ajcrites/TsHotReload

@ds300
Copy link
Owner

ds300 commented Jun 13, 2018

Thanks for the report, and for submitting a repro ❤️

This issue slipped off my radar, apologies for that. I'll try to take a look some time this week.

@ds300
Copy link
Owner

ds300 commented Jun 13, 2018

Just had a very quick look, one thing we discovered the other day was that the target and module options in tsconfig.json are important for hot reloading. You need to set both of them as es2015.

Don't have time to test right now.

@ajcrites
Copy link
Author

Thanks so much, seems like that does make it work! I honestly don't really understand the target / module stuff well ... are there any other consequences to changing these?

@ds300
Copy link
Owner

ds300 commented Jun 13, 2018

At the moment, this transformer uses babel as a secondary transpiler, so the only limitation is that the target needs to be supported by the babel config in your project. I'm not aware of any features that TS's most advanced target, ESNext would output that RN's default babel config could not cope with, so maybe it doesn't matter. That could be wrong, or it could change in the future, so es2015 is a safe bet for now.

@ds300
Copy link
Owner

ds300 commented Jun 13, 2018

I should just make the transformer overwrite the target and module options to prevent these issues in the future.

@ajcrites
Copy link
Author

Actually jest / ts-jest (haven't narrowed it down) seem to require commonjs or else I'll get "Unexpected token import" when running tests. It's not a huge deal since I can use a different configuration when testing vs. building, but wondering if you have any insight into that that might help me or others.

@ds300
Copy link
Owner

ds300 commented Jun 13, 2018

Hmmmm good point. I hadn't considered that. I know it's possible to use babel as a secondary transpilation step with ts-jest too, maybe I should encourage that. Otherwise, yes, the two-different-configs thing is easy enough to do. I'm going to leave this issue open to remind me to do something about this.

@GeeWee
Copy link

GeeWee commented Jul 3, 2018

Jest requires commonjs, not a ts-jest thing.

@ajcrites
Copy link
Author

ajcrites commented Jul 4, 2018

@GeeWee can you explain a bit more about what you mean or provide an example repo?

@GeeWee
Copy link

GeeWee commented Jul 4, 2018

I mean that jest requires the transpiled code to be in the CommonJS module format - so in ts-jest we try to ensure that the module format is set to that as the standard, unless the user explicitly overrides it (because they're using babel to do it themselves eg)

Did that make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants