question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SWC hot reload doesn't work when arrow function is used

See original GitHub issue

Whenever I use arrow function instead of function, hot reload doesn’t work. See screenshot and how to repro below:

image

Repro:

  1. clone react-refresh-webpack-plugin
  2. navigate to examples/typescript-with-swc
  3. Change
function App() {
  return (
    <div>
      <ClassDefault />
      <ClassNamed />
      <FunctionDefault />
      <FunctionNamed />
      <Suspense fallback={<h1>Loading</h1>}>
        <LazyComponent />
      </Suspense>
    </div>
  );
}

to

const App= () => {
  return (
    <div>
      {/* added */}
     <div> test </div> 
      <ClassDefault />
      <ClassNamed />
      <FunctionDefault />
      <FunctionNamed />
      <Suspense fallback={<h1>Loading</h1>}>
        <LazyComponent />
      </Suspense>
    </div>
  );
}
  1. Change test text to different text

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
Austarascommented, Sep 6, 2021

Cool, great to get my questions answered. I’ll send fix when I have time.

1reaction
Austarascommented, Sep 5, 2021

Yeah it’s me. I have spent some time for this issue and there’re multiple layers of problems in this issue:

  1. Arrow function get transpiled to (function () {}).bind(this), which is a long standing minor defect in swc and there haven’t been a good reason to fix it(until this issue)
  2. And somehow this will cause react refresh to stop working, I have no idea why though
  3. I forget to enable preset-env for swc, so this issue should be reopened @pmmmwh
  4. However when I add it and add browserslist field to package.json, webpack hot reload will silently fail, I have tested with other examples and they behave the same. I have absolutely idea why this is happening
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does changing componentDidMount to non-arrow ...
So all I did was change componentDidMount from an arrow function to a non-arrow function. So my question is: Why does changing it...
Read more >
I don't understand the point of vite. I tried using it and the "build ...
What I want is to reload the page and see my changes. I've never seen a "hot reload" that works properly. The one...
Read more >
@swc/helpers | Yarn - Package Manager
SWC (stands for Speedy Web Compiler ) is a super-fast TypeScript / JavaScript compiler written in Rust. It's a library for Rust and...
Read more >
[Android 4.1+] HeadUnit Reloaded for Android Auto with Wifi
If the app does not start automatically when you plug in your phone, you can always open HUR, tap the USB button and...
Read more >
Getting started with NestJS, Vite, and esbuild - LogRocket Blog
In this article, we'll learn about NestJS, Vite, and esbuild; how they work together; and how to configure a NestJS app to make...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found