Parcel: react-hot-loader not working with typescript

Created on 23 Jan 2019  路  6Comments  路  Source: parcel-bundler/parcel

馃悰 bug report

When using typescript and react-hot-loader, component handlers are not being patched correctly after hot reloading.

Please have a look at https://github.com/llamadeus/parcel-typescript-react-hot-loader for a minimal setup.

馃帥 Configuration (.babelrc, package.json, cli command)

.babelrc

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ],
  "plugins": [
    "react-hot-loader/babel",
    "@babel/plugin-proposal-class-properties"
  ]
}

package.json

{
  "name": "parcel-react-hot-loader-test",
  "version": "1.0.0",
  "license": "MIT",
  "scripts": {
    "start": "parcel src/index.html"
  },
  "devDependencies": {
    "@babel/core": "^7.0.0-0",
    "@babel/plugin-proposal-class-properties": "^7.3.0",
    "@babel/preset-react": "^7.0.0",
    "parcel-bundler": "^1.11.0",
    "typescript": "^3.2.4"
  },
  "dependencies": {
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "react-hot-loader": "^4.6.3"
  }
}

馃 Expected Behavior

When I hit the Press me button for the first time, it should properly alert('test');. Then, after commenting line 9 in src/Content.tsx and waiting for HMR to update the component, another click on the button should NOT trigger an alert.

馃槸 Current Behavior

The second button press actually DOES trigger another alert.

馃拋 Possible Solution

No idea.

馃敠 Context

Just any typescript application using hot module replacement.

馃捇 Code Sample

https://github.com/llamadeus/parcel-typescript-react-hot-loader

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.11.0 |
| Node | 8.12.0 |
| npm/Yarn | 6.4.1/1.12.3 |
| Operating System | macOS 10.14.2 |

Bug HMR Stale

Most helpful comment

Any news on this? Otherwise, I'd appreciate any tips on where and how to fix this problem.

All 6 comments

The same problem appears, when using ES6 and class decorators.

As it turns out, the bug only exists for arrow functions in the class. Replacing the arrow function with a normal class method and binding this manually works. However, I prefer arrow functions, so I'd like to be able to avoid that.

Can confirm! Thanks, @llamadeus.

Looks like I'll just do a codemod later.

Any news on this? Otherwise, I'd appreciate any tips on where and how to fix this problem.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidnagli picture davidnagli  路  3Comments

dotdash picture dotdash  路  3Comments

urbanhop picture urbanhop  路  3Comments

Niggler picture Niggler  路  3Comments

devongovett picture devongovett  路  3Comments