navgo 6.0.0 → 6.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +22 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -511,9 +511,28 @@ export default class Navgo {
511
511
  res = entry
512
512
  source = 'cache'
513
513
  } else if (strategy === 'swr' && entry) {
514
- res = entry
515
- source = fresh ? 'cache' : 'stale'
516
- if (!fresh) {
514
+ if (fresh) {
515
+ res = entry
516
+ source = 'cache'
517
+ } else if (nav_id === 0) {
518
+ // Preload should not freeze a stale snapshot into #preloads.
519
+ // Fetch now so goto() reuses fresh data.
520
+ try {
521
+ res = await this.#fetch_and_cache(
522
+ req,
523
+ cache,
524
+ side,
525
+ tags,
526
+ controller.signal,
527
+ )
528
+ source = 'network'
529
+ } catch {
530
+ res = entry
531
+ source = 'stale'
532
+ }
533
+ } else {
534
+ res = entry
535
+ source = 'stale'
517
536
  this.#fetch_and_cache(req, cache, side, tags, controller.signal)
518
537
  .then(r => this.#parse_response(r.clone ? r.clone() : r, parse))
519
538
  .then(v => this.#emit_revalidate(nav_id, as, v))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "navgo",
3
- "version": "6.0.0",
3
+ "version": "6.0.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/mustafa0x/navgo.git"