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

Bug: [Refresh] Default exported unnamed functions are ignored #21181

Closed
davidbonnet opened this issue Apr 5, 2021 · 5 comments
Closed

Bug: [Refresh] Default exported unnamed functions are ignored #21181

davidbonnet opened this issue Apr 5, 2021 · 5 comments
Labels
Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@davidbonnet
Copy link

React version: 17.0.2
React-refresh version: 0.10.0

This issue is similar to #21179, but ignores default exported unnamed functions instead.

As a code comment suggests, this is a known limitation:

// Anonymous direct exports like export default function() {}
// are currently ignored.

Would a fix be considered?

Steps To Reproduce

Given the following files, making changes to Component.js doesn't trigger a re-render.

main.js module:

import React from 'react'
import { render } from 'react-dom'

import Component from './Component.js'

function App() {
  return <main><Component /></main>
}

render(<App />, window.document.getElementById('root'))

Component.js module:

import React from 'react'

export default ({ value = "Hello" }) => (<div>{value}</div>)

The current behavior

Making changes to Component.js does not re-render the element in main.js.
The transformed Component.js module does not register the Component for refresh.

The expected behavior

Making changes to Component.js does re-render the element in main.js.

@davidbonnet davidbonnet added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Apr 5, 2021
@davidbonnet davidbonnet changed the title [Refresh] Default exported unnamed functions are ignored Bug: [Refresh] Default exported unnamed functions are ignored Apr 5, 2021
@gaearon
Copy link
Collaborator

gaearon commented Apr 5, 2021

This is intentional — even if we fix this case, we need some heuristic for other tools like lint rules. Why are you using this style? Functions should have names so that you get them in stack traces and so on.

@davidbonnet
Copy link
Author

davidbonnet commented Apr 5, 2021

Indeed, but then it becomes confusing: vitejs/vite-plugin-react#20.

If there's no way around, this can be closed and I'll make a suggestion downstream to use https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/function-component-definition.md. The code comment mentioned above should then also be more explicit, replacing "currently" by "intentionally".

@davidbonnet
Copy link
Author

However, given that an ignored component prevents a refresh (vitejs/vite-plugin-react#20), I haven't figured out yet whether this is an issue with react-refresh itself or with @vitejs/plugin-react-refresh. AFAIK, a code update of an ignored component should still trigger a refresh.

Copy link

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 10, 2024
EdisonVan pushed a commit to EdisonVan/react that referenced this issue Apr 15, 2024
These though fail.

Anon default export: facebook#21181
Promise callbacks: facebook#26186
Returning anon functions: facebook#22520
Copy link

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

2 participants