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

[Need investigate] Root component HMR works for babel but not for TypeScript? #2

Closed
Jack-Works opened this issue Nov 17, 2020 · 7 comments

Comments

@Jack-Works
Copy link
Owner

reported in #1

@Ogg70
Copy link

Ogg70 commented May 21, 2021

Hi, I have exactly the same problem.
I described in more detail here.
As far as I understand, the problem is here (I could be wrong). This includes arrow function components that are not hooks. Unfortunately I have no experience with custom ts transformers.

@Jack-Works
Copy link
Owner Author

As far as I understand, the problem is here (I could be wrong). This includes arrow function components that are not hooks. Unfortunately I have no experience with custom ts transformers.

This is introduced in 2.0.0. Can you try 1.1.1 to check if it get fixed?

@Ogg70
Copy link

Ogg70 commented May 21, 2021

As far as I understand, the problem is here (I could be wrong). This includes arrow function components that are not hooks. Unfortunately I have no experience with custom ts transformers.

This is introduced in 2.0.0. Can you try 1.1.1 to check if it get fixed?

I have checked, there is no problem in version 1.1.1.

@Jack-Works
Copy link
Owner Author

Jack-Works commented May 22, 2021

Ok, so I'll revert be48fbe because it's a wrong port to the upstream changes but I thought there is no harm to keep it.

@Jack-Works
Copy link
Owner Author

I have published 2.0.1, please try that out!

Ogg70 pushed a commit to Ogg70/react-refresh-transformer that referenced this issue May 22, 2021
@Ogg70
Copy link

Ogg70 commented May 22, 2021

Sorry i was wrong, the problem also exists in 1.1.1
Unfortunately, these edits did not fix the problem.
I have prepared a PR, please see.

@Jack-Works
Copy link
Owner Author

Jack-Works commented May 23, 2021

I tried to reproduce this and found it's likely not a bug in react-refresh-typescript.

If used as entry component means the following code:

import { render } from 'react-dom'
import { Component } from './Component'

export function App() {
    return (
        <div>
            <Component />
        </div>
    )
}
render(<App />, document.getElementById('root')!)

Yes, in this case, it won't refresh but reload the whole tree. Because every time this file getting HMRed, this whole file will be re-executed. And if you re-call ReactDOM.render (the last line) on your root component, it will be unmounted and remounted, because the previous App has a different identity than the current App, and the reconciliation algorithms will not diff the vDOM tree for a different component tree.

If it is your case, please move App to another file, that will fix the problem. If not, please point out and give a reproduce. Thanks

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

2 participants