@dudousxd/nestjs-telescope-ui 1.20.0 → 1.20.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @dudousxd/nestjs-telescope-ui
2
2
 
3
+ ## 1.20.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#69](https://github.com/DavideCarvalho/nestjs-telescope/pull/69) [`acdfacb`](https://github.com/DavideCarvalho/nestjs-telescope/commit/acdfacba22495b6517bf89d7e50a25d3032c1933) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Clear the console launcher's pending state when the page is restored from the back/forward cache.
8
+
9
+ `useOpenTelescopeConsole` deliberately keeps `isPending` set after a successful mint so the button
10
+ does not flicker back to idle on a page that is navigating away. With bfcache the page does not die:
11
+ pressing Back restored the launcher with its React state intact, leaving a permanent "Opening…"
12
+ spinner on a button that could never be clicked again. The hook now listens for `pageshow` and
13
+ resets only when `event.persisted` is true, so a fresh load and a mint that is still genuinely in
14
+ flight both keep the original behaviour.
15
+
3
16
  ## 1.20.0
4
17
 
5
18
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"use-open-console.d.ts","sourceRoot":"","sources":["../../src/react/use-open-console.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,KAAK,kBAAkB,EAGxB,MAAM,8BAA8B,CAAC;AAEtC;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,0EAA0E;IAC1E,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,0EAA0E;IAC1E,SAAS,EAAE,OAAO,CAAC;IACnB,0EAA0E;IAC1E,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAClC,uEAAuE;IACvE,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,kBAAuB,GAAG,oBAAoB,CAoC9F;AAED;;;;;;;;GAQG;AACH,wBAAgB,mCAAmC,CAAC,OAAO,GAAE,kBAAuB,GAAG;IACrF,WAAW,EAAE,SAAS,OAAO,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC,CAKA"}
1
+ {"version":3,"file":"use-open-console.d.ts","sourceRoot":"","sources":["../../src/react/use-open-console.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,KAAK,kBAAkB,EAGxB,MAAM,8BAA8B,CAAC;AAEtC;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,0EAA0E;IAC1E,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,0EAA0E;IAC1E,SAAS,EAAE,OAAO,CAAC;IACnB,0EAA0E;IAC1E,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAClC,uEAAuE;IACvE,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,kBAAuB,GAAG,oBAAoB,CA0D9F;AAED;;;;;;;;GAQG;AACH,wBAAgB,mCAAmC,CAAC,OAAO,GAAE,kBAAuB,GAAG;IACrF,WAAW,EAAE,SAAS,OAAO,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC,CAKA"}
@@ -1,4 +1,4 @@
1
- import { useCallback, useRef, useState } from 'react';
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import { ConsoleSessionError, openTelescopeConsole, telescopeConsoleSessionUrl, } from '../client/console-session.js';
3
3
  export function useOpenTelescopeConsole(options = {}) {
4
4
  const [isPending, setIsPending] = useState(false);
@@ -15,6 +15,9 @@ export function useOpenTelescopeConsole(options = {}) {
15
15
  // Deliberately NOT clearing `isPending` on success: the navigation is already underway and
16
16
  // this component is about to be torn down. Flipping the button back to idle first produces
17
17
  // a visible flicker of "ready to click again" on a page that is leaving.
18
+ //
19
+ // "About to be torn down" is not guaranteed, though — see the `pageshow` effect below for
20
+ // the case where the page comes back instead of dying.
18
21
  })
19
22
  .catch((cause) => {
20
23
  setError(cause instanceof ConsoleSessionError
@@ -25,6 +28,26 @@ export function useOpenTelescopeConsole(options = {}) {
25
28
  setIsPending(false);
26
29
  });
27
30
  }, []);
31
+ // The success path above leaves `isPending` true on the assumption that the page is leaving for
32
+ // good. The back/forward cache breaks that assumption: instead of destroying the document, the
33
+ // browser freezes it and restores it — React state and all — when the user presses Back. Without
34
+ // this the user returns from the console to a spinner that never stops, on a button that is
35
+ // permanently disabled because nothing else ever clears the flag.
36
+ //
37
+ // `persisted === true` is the ONLY signal that distinguishes a restore from a fresh load, and the
38
+ // condition is load-bearing in both directions: a normal `pageshow` (`persisted: false`) fires on
39
+ // every page load and must not touch anything, and a mint that is genuinely still in flight must
40
+ // keep its spinner. Dropping the check to "simplify" reintroduces the flicker this hook avoids.
41
+ useEffect(() => {
42
+ if (typeof window === 'undefined')
43
+ return;
44
+ const onPageShow = (event) => {
45
+ if (event.persisted)
46
+ setIsPending(false);
47
+ };
48
+ window.addEventListener('pageshow', onPageShow);
49
+ return () => window.removeEventListener('pageshow', onPageShow);
50
+ }, []);
28
51
  const reset = useCallback(() => setError(null), []);
29
52
  return { open, isPending, error, reset };
30
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-open-console.js","sourceRoot":"","sources":["../../src/react/use-open-console.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EACL,mBAAmB,EAEnB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,8BAA8B,CAAC;AAqBtC,MAAM,UAAU,uBAAuB,CAAC,UAA8B,EAAE;IACtE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAA6B,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AAE,CAAC,CAAC;IAEP,gGAAgG;IAChG,+FAA+F;IAC/F,iGAAiG;IACjG,4FAA4F;IAC5F,kEAAkE;IAClE,EAAE;IACF,kGAAkG;IAClG,kGAAkG;IAClG,iGAAiG;IACjG,gGAAgG;IAChG,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAC1C,MAAM,UAAU,GAAG,CAAC,KAA0B,EAAQ,EAAE;YACtD,IAAI,KAAK,CAAC,SAAS;gBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAC3C,CAAC,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAChD,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAClE,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAEpD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC3C,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,mCAAmC,CAAC,UAA8B,EAAE;IAIlF,OAAO;QACL,WAAW,EAAE,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAU;QAChF,UAAU,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC;KAChD,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-telescope-ui",
3
- "version": "1.20.0",
3
+ "version": "1.20.1",
4
4
  "description": "Bundled dashboard + composable React components for @dudousxd/nestjs-telescope.",
5
5
  "license": "MIT",
6
6
  "repository": {