@molecule/app-auth-modal-react 4.0.2 → 4.0.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"AuthModal.d.ts","sourceRoot":"","sources":["../src/AuthModal.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,SAAS,EAA+B,MAAM,OAAO,CAAA;AAY7E,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAI9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AA0CvD,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC7B,iCAAiC;IACjC,IAAI,EAAE,OAAO,CAAA;IACb,4DAA4D;IAC5D,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,qDAAqD;IACrD,WAAW,CAAC,EAAE,aAAa,CAAA;IAC3B;;;OAGG;IACH,WAAW,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3C;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,IAAI,CAAA;IACzB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5C;;;;;;;;;;;;;;OAcG;IACH,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,OAAO,EACP,WAAsB,EACtB,WAAW,EACX,YAAY,EACZ,eAAe,EACf,WAAW,EACX,aAAoB,GACrB,EAAE,cAAc,GAAG,GAAG,CAAC,OAAO,CAkR9B;yBA3Re,SAAS"}
1
+ {"version":3,"file":"AuthModal.d.ts","sourceRoot":"","sources":["../src/AuthModal.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,SAAS,EAAqD,MAAM,OAAO,CAAA;AAYnG,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAI9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAqEvD,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC7B,iCAAiC;IACjC,IAAI,EAAE,OAAO,CAAA;IACb,4DAA4D;IAC5D,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,qDAAqD;IACrD,WAAW,CAAC,EAAE,aAAa,CAAA;IAC3B;;;OAGG;IACH,WAAW,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3C;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,IAAI,CAAA;IACzB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5C;;;;;;;;;;;;;;OAcG;IACH,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,OAAO,EACP,WAAsB,EACtB,WAAW,EACX,YAAY,EACZ,eAAe,EACf,WAAW,EACX,aAAoB,GACrB,EAAE,cAAc,GAAG,GAAG,CAAC,OAAO,CAkR9B;yBA3Re,SAAS"}
package/dist/AuthModal.js CHANGED
@@ -17,7 +17,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
17
17
  *
18
18
  * @module
19
19
  */
20
- import { useEffect, useRef, useState } from 'react';
20
+ import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
21
21
  import { useAuthFormState } from '@molecule/app-auth-shell-react';
22
22
  import { OAuthButtons, OAuthDivider } from '@molecule/app-oauth-buttons-react';
23
23
  import { useAuth, useAuthClient, useI18nError, useLogin, useSignup, useTranslation, } from '@molecule/app-react';
@@ -37,6 +37,39 @@ const TOUCH_FIRST_QUERY = '(max-width: 767px), (pointer: coarse)';
37
37
  * runs concurrently, so the real delay is `max(this, onAuthenticated)`.
38
38
  */
39
39
  const SUCCESS_DISPLAY_MS = 1000;
40
+ /**
41
+ * Subscribe to changes of {@link TOUCH_FIRST_QUERY}; the no-op subscription on
42
+ * a runtime without `matchMedia` (SSR) never fires.
43
+ *
44
+ * @param onStoreChange - Called when the media query starts or stops matching.
45
+ * @returns The unsubscribe function.
46
+ */
47
+ function subscribeTouchFirst(onStoreChange) {
48
+ if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
49
+ return () => { };
50
+ const mql = window.matchMedia(TOUCH_FIRST_QUERY);
51
+ mql.addEventListener('change', onStoreChange);
52
+ return () => mql.removeEventListener('change', onStoreChange);
53
+ }
54
+ /**
55
+ * Whether {@link TOUCH_FIRST_QUERY} currently matches, read from the browser.
56
+ *
57
+ * @returns True on phone-width or touch-first devices.
58
+ */
59
+ function getTouchFirstSnapshot() {
60
+ return (typeof window !== 'undefined' &&
61
+ typeof window.matchMedia === 'function' &&
62
+ window.matchMedia(TOUCH_FIRST_QUERY).matches);
63
+ }
64
+ /**
65
+ * The server-side snapshot: no viewport exists when rendering to a string, so
66
+ * report a non-touch desktop. The client re-reads the real value on hydration.
67
+ *
68
+ * @returns Always `false`.
69
+ */
70
+ function getTouchFirstServerSnapshot() {
71
+ return false;
72
+ }
40
73
  /**
41
74
  * Whether {@link TOUCH_FIRST_QUERY} currently matches. SSR-safe (reports
42
75
  * `false` until mounted in a browser) and subscribes to media-query changes
@@ -45,19 +78,7 @@ const SUCCESS_DISPLAY_MS = 1000;
45
78
  * @returns True on phone-width or touch-first devices.
46
79
  */
47
80
  function useTouchFirstViewport() {
48
- const [matches, setMatches] = useState(() => typeof window !== 'undefined' &&
49
- typeof window.matchMedia === 'function' &&
50
- window.matchMedia(TOUCH_FIRST_QUERY).matches);
51
- useEffect(() => {
52
- if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
53
- return;
54
- const mql = window.matchMedia(TOUCH_FIRST_QUERY);
55
- const onChange = (e) => setMatches(e.matches);
56
- setMatches(mql.matches);
57
- mql.addEventListener('change', onChange);
58
- return () => mql.removeEventListener('change', onChange);
59
- }, []);
60
- return matches;
81
+ return useSyncExternalStore(subscribeTouchFirst, getTouchFirstSnapshot, getTouchFirstServerSnapshot);
61
82
  }
62
83
  /**
63
84
  * The in-app auth modal: login/signup tabs rendered in a Modal overlay — the user authenticates without leaving the current page (no navigation, no lost work). Usually rendered via `AuthModalMount`, not directly.
@@ -1 +1 @@
1
- {"version":3,"file":"AuthModalMount.d.ts","sourceRoot":"","sources":["../src/AuthModalMount.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,KAAK,GAAG,EAA4C,MAAM,OAAO,CAAA;AAI1E,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,oBAAoB,CAAA;AAE3B,wCAAwC;AACxC,MAAM,WAAW,mBAAmB;IAClC,gFAAgF;IAChF,WAAW,EAAE,cAAc,CAAC,aAAa,CAAC,CAAA;IAC1C,wEAAwE;IACxE,YAAY,CAAC,EAAE,MAAM,IAAI,CAAA;IACzB,0EAA0E;IAC1E,eAAe,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5C;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,IAAI,CAAA;IAC5B;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3C;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,cAAc,CAAC,aAAa,CAAC,CAAA;IAC3C,yHAAyH;IACzH,aAAa,CAA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CAAC,eAAe,CAAC,CAAA;IAC/C,wEAAwE;IACxE,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAA;IACnD,0FAA0F;IAC1F,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACjC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAC7B,WAAW,EACX,YAAY,EACZ,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,SAA8B,EAC9B,YAAoC,GACrC,EAAE,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAqFnC;yBA/Fe,cAAc"}
@@ -18,7 +18,7 @@ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
18
18
  *
19
19
  * @module
20
20
  */
21
- import { useCallback, useEffect, useRef, useState } from 'react';
21
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
22
22
  import { useAuth } from '@molecule/app-react';
23
23
  import { AuthModal } from './AuthModal.js';
24
24
  import { authModeForHref, DEFAULT_AUTH_PATHS, DEFAULT_UPGRADE_PATHS, upgradePathForHref, } from './cta-intercept.js';
@@ -59,7 +59,12 @@ export function AuthModalMount({ oauthConfig, onBeforeAuth, onAuthenticated, onU
59
59
  // anywhere in the app, incl. ones opened with target="_blank". Capture-phase +
60
60
  // preventDefault stops navigation. Plain left-clicks only — a modifier/middle
61
61
  // click still opens the real page.
62
- useEffect(() => {
62
+ // A layout effect, not a passive one: React runs those inside the commit, so when a host
63
+ // remounts this component (under a new parent, on a layout change) the unmounted instance's
64
+ // listener is gone and the new one is in place before any click can be handled. A passive
65
+ // effect runs in a later task, and a click in between reached the unmounted instance: it
66
+ // prevented the navigation and its `setOpen` opened nothing.
67
+ useLayoutEffect(() => {
63
68
  const onClick = (e) => {
64
69
  if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey)
65
70
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-auth-modal-react",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "In-app login / signup modal + click-interceptor + popup OAuth — authenticate and upgrade without ever navigating away or losing work",
5
5
  "homepage": "https://www.molecule.dev/packages/app-auth-modal-react",
6
6
  "type": "module",
@@ -46,17 +46,17 @@
46
46
  "react": "^18.0.0 || ^19.0.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@molecule/app-auth-shell-react": "4.0.2",
49
+ "@molecule/app-auth-shell-react": "4.1.0",
50
50
  "@molecule/app-i18n": "1.2.2",
51
- "@molecule/app-oauth-buttons-react": "4.0.0",
52
- "@molecule/app-react": "4.7.1",
53
- "@molecule/app-ui": "1.4.0",
54
- "@molecule/app-ui-react": "4.1.4",
51
+ "@molecule/app-oauth-buttons-react": "4.1.0",
52
+ "@molecule/app-react": "4.12.0",
53
+ "@molecule/app-ui": "1.5.0",
54
+ "@molecule/app-ui-react": "4.3.0",
55
55
  "@testing-library/react": "16.3.3",
56
56
  "@types/node": "26.6.5",
57
57
  "@types/react": "19.3.0",
58
58
  "@types/react-dom": "19.3.0",
59
- "jsdom": "30.1.3",
59
+ "jsdom": "31.0.1",
60
60
  "react": "19.3.1",
61
61
  "react-dom": "19.3.1",
62
62
  "typescript": "6.0.3",