diff --git a/package-lock.json b/package-lock.json index eb037af5..8b7f9160 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,8 +21,8 @@ "@isomorphic-git/lightning-fs": "^4.6.2", "@modelcontextprotocol/sdk": "^1.22.0", "@mozilla/readability": "^0.6.0", - "@nostrify/nostrify": "^0.51.1", - "@nostrify/react": "^0.4.1", + "@nostrify/nostrify": "^0.54.1", + "@nostrify/react": "^0.6.6", "@opensecret/react": "^1.5.4", "@plausible-analytics/tracker": "^0.4.4", "@radix-ui/react-accordion": "^1.2.0", @@ -3293,11 +3293,11 @@ } }, "node_modules/@nostrify/nostrify": { - "version": "0.51.1", - "resolved": "https://registry.npmjs.org/@nostrify/nostrify/-/nostrify-0.51.1.tgz", - "integrity": "sha512-oPJhUiO1TlV5sGYizqAP4GvLijib34Uwh48wxlFimR/2MoCuSmab4AppcztGPNwxQoTKkJbLJwsSpl42V+WIXA==", + "version": "0.54.1", + "resolved": "https://registry.npmjs.org/@nostrify/nostrify/-/nostrify-0.54.1.tgz", + "integrity": "sha512-/iMRPBZdz+74pPXKHbQ7RsMwQtEXbJ/M21iNp1kbAMMvRh30hFjdV3ROU93rxGIDsOMSOpzeXXWT4Z+gXZW8Bg==", "dependencies": { - "@nostrify/types": "0.36.9", + "@nostrify/types": "0.37.0", "@scure/base": "^2.0.0", "@smithy/util-base64": "^4.3.0", "@smithy/util-hex-encoding": "^4.2.0", @@ -3334,12 +3334,12 @@ "license": "MIT" }, "node_modules/@nostrify/react": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/@nostrify/react/-/react-0.4.1.tgz", - "integrity": "sha512-2JXxEl4e6FIFhbi96Dwv2knu5qAACYulo1a0oVell/aS8KCWsBTPd1+v0EUra0yqiUA3Q1nVLrk8mx7kQYH/yQ==", + "version": "0.6.6", + "resolved": "https://registry.npmjs.org/@nostrify/react/-/react-0.6.6.tgz", + "integrity": "sha512-WTWTT3dtw0BF5bZsFgOob9S3J9rWKOsPQ2LLKDsDhx3PxbjIFKSVqSQLw7jiN6LoVGom9OuVOG/PB6p9hAWDjQ==", "dependencies": { - "@nostrify/nostrify": "0.51.1", - "@nostrify/types": "0.36.9" + "@nostrify/nostrify": "0.54.1", + "@nostrify/types": "0.37.0" }, "peerDependencies": { "@tanstack/react-query": "^5.69.0", @@ -3349,9 +3349,9 @@ } }, "node_modules/@nostrify/types": { - "version": "0.36.9", - "resolved": "https://registry.npmjs.org/@nostrify/types/-/types-0.36.9.tgz", - "integrity": "sha512-tMx/r0W+QoVRRgs8d6ltaSgrftasOXuFsi33kW8WirswCy2b3UR1tqRgc0iBU9zRa9XR0nlej/wJZW+6wUFi+Q==" + "version": "0.37.0", + "resolved": "https://registry.npmjs.org/@nostrify/types/-/types-0.37.0.tgz", + "integrity": "sha512-P0AKR+qcNeBBTA5UDnJM6SxLAQbgud2+ZcdVyheoP37XGQvi7rUncQUDKwebG+Ui5kswp/IPEmvqNtCMQpwRoA==" }, "node_modules/@opensecret/react": { "version": "1.5.4", diff --git a/package.json b/package.json index d19130dd..903cd02e 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,8 @@ "@isomorphic-git/lightning-fs": "^4.6.2", "@modelcontextprotocol/sdk": "^1.22.0", "@mozilla/readability": "^0.6.0", - "@nostrify/nostrify": "^0.51.1", - "@nostrify/react": "^0.4.1", + "@nostrify/nostrify": "^0.54.1", + "@nostrify/react": "^0.6.6", "@opensecret/react": "^1.5.4", "@plausible-analytics/tracker": "^0.4.4", "@radix-ui/react-accordion": "^1.2.0", diff --git a/src/test/setup.ts b/src/test/setup.ts index d382eb26..ac63c41d 100644 --- a/src/test/setup.ts +++ b/src/test/setup.ts @@ -34,6 +34,81 @@ class LocalStorageMock implements Storage { global.localStorage = new LocalStorageMock(); +// The @nostrify/react 0.6.6 NostrLoginProvider resolves stored logins on a +// microtask: it renders a null `fallback` on the first synchronous paint and +// only mounts its children once storage resolves. Component/hook tests render +// synchronously and query immediately, so they'd observe an empty tree (this is +// the sole cause of the render breakage introduced by the upgrade). Replace the +// provider — and the hook that reads its context — with a synchronous +// equivalent for tests, importing everything else (NLogin.nostrconnect and the +// connect helpers, whose handshake enforcement is the point of the upgrade; +// NUser) from the real module untouched. +vi.mock('@nostrify/react/login', async (importActual) => { + const actual = await importActual(); + const { createContext, useContext, useReducer, useEffect, createElement } = await import('react'); + + const NostrLoginContext = createContext(undefined); + + type Login = { id: string }; + type LoginAction = + | { type: 'login.add'; login: Login; set?: boolean } + | { type: 'login.remove'; id: string } + | { type: 'login.set'; id: string } + | { type: 'login.clear' }; + + function reducer(state: Login[], action: LoginAction): Login[] { + switch (action.type) { + case 'login.add': { + const filtered = state.filter((l) => l.id !== action.login.id); + return action.set ? [action.login, ...filtered] : [...filtered, action.login]; + } + case 'login.remove': + return state.filter((l) => l.id !== action.id); + case 'login.set': { + const login = state.find((l) => l.id === action.id); + if (!login) return state; + return [login, ...state.filter((l) => l.id !== action.id)]; + } + case 'login.clear': + return []; + default: + return state; + } + } + + const NostrLoginProvider = ({ children, storageKey, storage = localStorage }: { + children: React.ReactNode; + storageKey: string; + storage?: Storage; + }) => { + const [state, dispatch] = useReducer(reducer, undefined, (): Login[] => { + const stored = storage.getItem(storageKey); + return typeof stored === 'string' ? (JSON.parse(stored) as Login[]) : []; + }); + useEffect(() => { + storage.setItem(storageKey, JSON.stringify(state)); + }, [state, storageKey, storage]); + const value = { + logins: state, + addLogin: (login: Login) => dispatch({ type: 'login.add', login }), + removeLogin: (id: string) => dispatch({ type: 'login.remove', id }), + setLogin: (id: string) => dispatch({ type: 'login.set', id }), + clearLogins: () => dispatch({ type: 'login.clear' }), + }; + return createElement(NostrLoginContext.Provider, { value }, children); + }; + + function useNostrLogin() { + const context = useContext(NostrLoginContext); + if (!context) { + throw new Error('useNostrLogin must be used within a NostrLoginProvider'); + } + return context; + } + + return { ...actual, NostrLoginProvider, useNostrLogin }; +}); + // Mock CSS imports vi.mock('*.css', () => ({})); vi.mock('*.scss', () => ({}));