Skip to content

Commit

Permalink
fix: reload the page during dev when no cache entry is available
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jul 26, 2022
1 parent 63d9630 commit 918bfd0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/data-fetching/defineLoader.ts
Expand Up @@ -30,9 +30,14 @@ export function defineLoader<P extends Promise<any>>(

// TODO: dev only
if (!entry) {
if (import.meta.hot) {
// reload the page if the loader is new
// TODO: test with webpack
import.meta.hot.invalidate()
}
// with HMR, if the user changes the script section, there is a new cache entry
// we need to transfer the old cache and call refresh
throw new Error('no cache entry')
throw new Error('No cache entry: reloading the page')
}

const { data, pending, error } = entry
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Expand Up @@ -8,6 +8,7 @@
"esModuleInterop": true,
"strict": true,
"strictNullChecks": true,
"resolveJsonModule": true
"resolveJsonModule": true,
"types": ["vite/client"]
}
}

0 comments on commit 918bfd0

Please sign in to comment.