nextjs - 💡(How to fix) Fix Fast Refresh breaks in presence of top level await [2 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#84658Fetched 2026-04-08 02:18:50
View on GitHub
Comments
2
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
commented ×2issue_type_added ×1labeled ×1

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0: Thu Dec 19 20:44:10 PST 2024; root:xnu-10063.141.1.703.2~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 24.4.1
  npm: 11.4.2
  Yarn: 3.6.0
  pnpm: 10.15.1
Relevant Packages:
  next: 15.6.0-canary.53 // Latest available version is detected (15.6.0-canary.53).
  eslint-config-next: 15.5.4
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/rnbrady/next-15-tla

To Reproduce

Start in dev mode with pnpm dev and open the page:

Step 1: Click to increment the counter Step 2: Edit the message in the lib/with-tla.ts and save the file Step 3: Return to the page, you will find the counter has been reset, meaning the Fast Refresh has failed. Step 4: Edit the code to use lib/without-tla.ts. You will notice the counter no longer resets.

Current vs. Expected behavior

Expected: Counter state should be preserved. Fast refresh should work.

Current: Counter state resets. The following is shown which does not explain the problem:

[Fast Refresh] performing full reload

Fast Refresh will perform a full reload when you edit a file that's imported by modules outside of the React rendering tree. You might have a file which exports a React component but also exports a value that is imported by a non-React component file. Consider migrating the non-React component export to a separate file and importing it into both files.

It is also possible the parent component of the component you edited is a class component, which disables Fast Refresh. Fast Refresh requires at least one parent function component in your React tree.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0: Thu Dec 19 20:44:10 PST 2024; root:xnu-10063.141.1.703.2~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 24.4.1
  npm: 11.4.2
  Yarn: 3.6.0
  pnpm: 10.15.1
Relevant Packages:
  next: 15.6.0-canary.53 // Latest available version is detected (15.6.0-canary.53).
  eslint-config-next: 15.5.4
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

React

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

Happens with and without Turbopack.

If TLA is present anywhere in projects or deps, Fast Refresh will fail everywhere, regardless of whether page being refreshed imports the TLA module.

extent analysis

TL;DR

The most likely fix is to refactor the code to avoid exporting non-React components from the same file as React components, as suggested by the Fast Refresh error message.

Guidance

  • Review the lib/with-tla.ts file and identify any non-React component exports that could be causing the issue.
  • Consider migrating these exports to a separate file, as suggested by the error message, to allow Fast Refresh to work correctly.
  • Verify that the parent component of the edited component is a function component, as class components can disable Fast Refresh.
  • Test the fix by editing the lib/with-tla.ts file and checking if the counter state is preserved after a Fast Refresh.

Example

No specific code example is provided, as the issue is more related to code organization and structure rather than a specific code snippet.

Notes

The issue seems to be related to the way Next.js and Fast Refresh handle module imports and exports. The presence of TLA (Top-Level Await) in the project or dependencies appears to be causing the issue, but the exact cause is not entirely clear.

Recommendation

Apply workaround: Refactor the code to avoid exporting non-React components from the same file as React components, as this is the most likely cause of the issue and is suggested by the Fast Refresh error message.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING