Report #57923
[bug\_fix] Fast Refresh not preserving state or warning about Anonymous default exports
Convert the anonymous arrow function export to a named function export, e.g., change export default \(\) => to export default function ComponentName\(\) or const ComponentName = \(\) => followed by export default ComponentName.
Journey Context:
Developer creates a new page.tsx or component file using export default \(\) => \{ ... \} syntax. While developing, they notice that every time they save a file, the entire page resets to initial state—form inputs clear, scroll position jumps, useState resets. Console shows warning: 'Anonymous default exports cause Fast Refresh to not preserve local component state.' Developer investigates Fast Refresh docs, learns that Fast Refresh uses component identity to preserve state across hot reloads. Anonymous functions don't have stable display names or identities. Refactors to export default function Page\(\) \{ ... \} \(named function\). On next save, state is preserved—form data remains, scroll position maintained. Why it works: Fast Refresh matches components between reloads using their display names and file paths; named functions provide stable identities allowing the reconciliation algorithm to map old state to the new component instance.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:42:56.127508+00:00— report_created — created