Skip to content

Is it possible to get hot-reload with typescript working? #6503

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

Closed
kanekv opened this issue Feb 23, 2019 · 26 comments
Closed

Is it possible to get hot-reload with typescript working? #6503

kanekv opened this issue Feb 23, 2019 · 26 comments

Comments

@kanekv
Copy link

kanekv commented Feb 23, 2019

No description provided.

@kumar303
Copy link

Why not? It seems like it should be possible: https://github.com/gaearon/react-hot-loader#typescript

I was able to get it working by adding react-app-rewire-hot-loader but that starts to complicate things.

@kanekv
Copy link
Author

kanekv commented Feb 28, 2019

@kumar303 does it work at all? What are complications?

@kumar303
Copy link

kumar303 commented Feb 28, 2019

@kumar303 does it work at all?

Yes, after following the instructions in react-app-require-hot-loader, hot reloads seem to be working just fine. This is all I had to change in a standard create-react-app project: https://github.com/mozilla/addons-code-manager/pull/276/files

What are complications?

Well, it involves replacing all react-scripts commands with react-app-rewired. This makes me think that upgrading to new versions of react-scripts would be difficult. Also, it would introduce a non-officially supported babel/webpack configuration which might get out of sync with react-scripts and might create confusing bugs. It's not as bad as ejecting, though.

@kanekv
Copy link
Author

kanekv commented Feb 28, 2019

It seems it works with that setup, closing this issue.

@kanekv kanekv closed this as completed Feb 28, 2019
@kumar303
Copy link

kumar303 commented Mar 5, 2019

It seems it works with that setup, closing this issue.

Could you please re-open the issue so that it gets fixed properly in create-react-app?

@kanekv kanekv reopened this Mar 5, 2019
@stale
Copy link

stale bot commented Apr 4, 2019

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Apr 4, 2019
@kumar303
Copy link

kumar303 commented Apr 5, 2019

Could someone from the team please consider this feature? I think it's really important.

As an example: sometimes I need to perform a few clicks to set up my UI in a state for development. Without proper hot reloading, the whole page gets reloaded as I edit files and I lose my state.

@stale stale bot removed the stale label Apr 5, 2019
@iansu
Copy link
Contributor

iansu commented Apr 5, 2019

We would be happy to consider this feature but without someone from the community doing the work and submitting a PR it's probably not going to happen. We have very limited resources and can barely keep up with all the issues and PRs that come in every day.

@kumar303
Copy link

kumar303 commented Apr 5, 2019

OK, I can look into making a patch for it. I just wanted to make sure there wasn't already some reason that hot reloading is disabled.

@iansu
Copy link
Contributor

iansu commented Apr 5, 2019

I think the reason is just that it's tricky to get it working properly.

@esetnik
Copy link

esetnik commented Apr 23, 2019

All that react-app-rewire-hot-loader does is add react-hot-loader/babel to the list of plugins for babel-loader. Can't we just modify https://github.com/facebook/create-react-app/blob/master/packages/babel-preset-react-app/create.js#L106 to include react-hot-loader/babel plugin and add it as a package dependency?

@esetnik
Copy link

esetnik commented Apr 23, 2019

I published a version of babel-preset-react-app that enables react-hot-loader/babel plugin. If you're using yarn you could try it out and let me know if it's working for you. If so I'll submit a PR to create-react-app.

    "babel-preset-react-app-react-hot-loader": "^8.0.1",
    "babel-preset-react-app": "npm:babel-preset-react-app-react-hot-loader",

@kamal94
Copy link

kamal94 commented May 5, 2019

Would definitely appreciate this working out of the box 👍

@stale
Copy link

stale bot commented Jun 4, 2019

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Jun 4, 2019
@wzup
Copy link

wzup commented Jun 4, 2019

It is still not working.

I've included TS in my create-react-app as described here and hot reload stopped working for .tsx files. It works for .js files but not for .tsx.

What is the fix? Where are docs about fix?

@stale stale bot removed the stale label Jun 4, 2019
@esetnik
Copy link

esetnik commented Jun 4, 2019

@wzup here's what I finally got working:

  1. create config-overrides.js in the root of your project:
const rewireReactHotLoader = require('react-app-rewire-hot-loader');

/* config-overrides.js */
module.exports = function override(config, env) {
  if (env === 'development') {
    config.resolve.alias['react-dom'] = '@hot-loader/react-dom';
  }
  config = rewireReactHotLoader(config, env);
  return config;
};
  1. Change your scripts to launch with react-app-rewired, e.g.:
  "scripts": {
    "start": "react-app-rewired start",
  }
  1. Mark your module as hot, e.g. App.tsx:
import { hot } from 'react-hot-loader/root';
import React from 'react';

const App = () => (
  ...
);

export default hot(App);

@7Kronos
Copy link

7Kronos commented Jun 4, 2019

Don't forget to add those dependencies :

  • react-app-rewire-hot-loader
  • react-app-rewired
  • react-hot-loader
  • @hot-loader/react-dom@xxx (xxx must match your react-dom package version as it is a patched version of the original one)

@stale
Copy link

stale bot commented Jul 4, 2019

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Jul 4, 2019
@kumar303
Copy link

kumar303 commented Jul 5, 2019

A team member has agreed in #6503 (comment) that this is an important feature.

@stale stale bot removed the stale label Jul 5, 2019
@bugzpodder
Copy link

bugzpodder commented Jul 5, 2019

I don't think we'll support react-hot-loader out of the box so I'm closing this issue. You can also use one of the workarounds provided above.
Dan is working on a new version and it is tracked in #5958

@kumar303
Copy link

kumar303 commented Jul 8, 2019

@bugzpodder why wouldn't create react app support hot reloading a typescript application out of the box?

Reloading hooks (#5958) is only a small piece so I don't see how tracking that PR would be helpful.

@bugzpodder
Copy link

We also don't support react-hot-loader for js applications, it's not just typescript. It will be supported when #5958 lands. Webpack HMR is already supported out of the box
...

@saranshkataria
Copy link
Contributor

@bugzpodder any reason for not supporting react-hot-loader out of the box?

@bugzpodder
Copy link

Dan has a list of things he want to accomplish and I can't find it right now. You can see https://gist.github.com/gaearon/a4d9fb3e6ea487a9296a8d2d9a6e3bf2 for some of his ideas.

@bugzpodder
Copy link

@kumar303
Copy link

kumar303 commented Jul 9, 2019

We also don't support react-hot-loader for js applications, it's not just typescript. It will be supported when #5958 lands. Webpack HMR is already supported out of the box
...

Oh, my bad. I thought this issue was about hot reloading in general. I am using Webpack HMR in a create react app (with TypeScript) and hot reloading still doesn't work for some cases, even with all the suggested redux/router setup. I will try to remember what those cases are. For some reason I thought all my trouble with this was related to TypeScript but now I can't remember why.

@lock lock bot locked and limited conversation to collaborators Jul 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants