Skip to content

fix: persist async data across tab navigation#963

Merged
antfu merged 1 commit intomainfrom
antfu/fix-imports-tab-empty
Mar 23, 2026
Merged

fix: persist async data across tab navigation#963
antfu merged 1 commit intomainfrom
antfu/fix-imports-tab-empty

Conversation

@antfu
Copy link
Member

@antfu antfu commented Mar 23, 2026

Summary

The imports tab (and other tabs) would show empty after navigating away and back because Nuxt's purgeCachedData cleared the cached data on unmount. When remounting, the default getCachedData only checks nuxtApp.static.data (empty in SPA mode), not payload.data where the actual fetch result is stored.

Solution

Provide a custom getCachedData that reads from payload.data[key]. This both:

  • Prevents clearNuxtDataByKey from running when the last consumer unmounts (line 459 of asyncData.js)
  • Returns previously fetched data on remount, so pages render instantly with cached data instead of showing blank

Testing

The imports, components, and pages tabs should now persist data correctly across navigation without showing empty states.

🤖 Generated with Claude Code

The imports tab (and other tabs) would show empty after navigation because
Nuxt's purgeCachedData cleared the cached data on unmount. The default
getCachedData only checks nuxtApp.static.data (empty in SPA mode), not
payload.data where the actual fetch result is stored.

By providing a custom getCachedData that reads from payload.data:
1. Data persists across unmount/remount cycles
2. Prevents clearNuxtDataByKey from running (line 459 of asyncData.js)
3. Pages render instantly with previous data instead of showing blank

This fixes the empty imports/components/pages tabs on navigation back.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link

Deploying nuxt-devtools with  Cloudflare Pages  Cloudflare Pages

Latest commit: ba62838
Status: ✅  Deploy successful!
Preview URL: https://f71b992f.nuxt-devtools.pages.dev
Branch Preview URL: https://antfu-fix-imports-tab-empty.nuxt-devtools.pages.dev

View logs

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8a7f389e-b89b-4e9f-95aa-d793d2c20585

📥 Commits

Reviewing files that changed from the base of the PR and between 741ebeb and ba62838.

📒 Files selected for processing (1)
  • packages/devtools/client/composables/utils.ts

📝 Walkthrough

Walkthrough

This change modifies the useAsyncState composable function to alter its caching strategy. Instead of creating a separate cache entry in nuxt.payload.unique[key], the function now directly calls useAsyncData and uses its built-in caching mechanism by reading from nuxt.payload.data[key]. The implementation spreads any provided options and explicitly sets the getCachedData function to retrieve data from the correct payload location, ensuring cached data persists across component remounts and preventing Nuxt from purging the cached state when components unmount.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: preventing async data from being cleared when navigating away from and back to tabs.
Description check ✅ Passed The description clearly explains the problem (cached data being purged on unmount), the solution (custom getCachedData), and testing expectations, all directly related to the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch antfu/fix-imports-tab-empty

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@antfu antfu merged commit a201092 into main Mar 23, 2026
4 of 5 checks passed
@antfu antfu deleted the antfu/fix-imports-tab-empty branch March 23, 2026 07:47
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

Successfully merging this pull request may close these issues.

1 participant