Skip to content

Commit 8b4f51f

Browse files
committed
docs: deprecate the legacy window-global connection handoff
1 parent 526e06a commit 8b4f51f

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

packages/devframe/src/client/connection-storage.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@ import type { ConnectionMeta } from 'devframe/types'
22
import type { DevframeConnection } from './connection'
33
import { DEVFRAME_CONNECTION_KEY } from 'devframe/constants'
44

5+
/**
6+
* @deprecated Legacy window-global meta handoff, fully subsumed by the
7+
* connection stored under `DEVFRAME_CONNECTION_KEY` (which carries the meta
8+
* together with its source URL and auth token). Still written and read for
9+
* compatibility with viewers bundling an older `devframe/client`; the read
10+
* path goes first, then the writes, in future releases.
11+
*/
512
const CONNECTION_META_KEY = '__DEVFRAME_CONNECTION_META__'
13+
/**
14+
* Key for the persisted auth token. The `localStorage` entry stays — it is
15+
* what lets trust survive reloads and reach sibling tabs. The *window-global*
16+
* entry under this key is deprecated: same-realm viewers read the token from
17+
* the connection under `DEVFRAME_CONNECTION_KEY` instead.
18+
*/
619
const CONNECTION_AUTH_TOKEN_KEY = '__DEVFRAME_CONNECTION_AUTH_TOKEN__'
720

821
function readFromWindows<T>(key: string): T | undefined {
@@ -26,6 +39,12 @@ export function readStoredConnection(): DevframeConnection | undefined {
2639
return readFromWindows<DevframeConnection>(DEVFRAME_CONNECTION_KEY)
2740
}
2841

42+
/**
43+
* @deprecated Reads the legacy meta global, kept only so a viewer embedded
44+
* under a host running an older `devframe/client` still inherits a
45+
* connection. Use {@link readStoredConnection} — `DEVFRAME_CONNECTION_KEY`
46+
* is the authoritative handoff.
47+
*/
2948
export function readStoredConnectionMeta(): (ConnectionMeta & { baseUrl?: string }) | undefined {
3049
return readFromWindows<ConnectionMeta & { baseUrl?: string }>(CONNECTION_META_KEY)
3150
}
@@ -41,13 +60,18 @@ export function readStoredAuthToken(userAuthToken?: string): string | undefined
4160
}
4261
catch {}
4362

63+
// Deprecated window-global fallback — an older `devframe/client` host may
64+
// still publish the token this way. New hosts hand it over inside the
65+
// connection under `DEVFRAME_CONNECTION_KEY`.
4466
return readFromWindows<string>(CONNECTION_AUTH_TOKEN_KEY)
4567
}
4668

4769
export function storeConnection(connection: DevframeConnection): void {
4870
;(globalThis as any)[DEVFRAME_CONNECTION_KEY] = connection
49-
// Keep the established metadata/auth globals in sync for viewers that still
50-
// consume the legacy handoff directly.
71+
// Deprecated: mirror into the legacy meta global so viewers bundling an
72+
// older `devframe/client` still inherit a connection. The connection under
73+
// `DEVFRAME_CONNECTION_KEY` is authoritative; this write goes away once the
74+
// legacy read path is retired.
5175
;(globalThis as any)[CONNECTION_META_KEY] = {
5276
...connection.connectionMeta,
5377
baseUrl: connection.metaBaseUrl,
@@ -61,6 +85,9 @@ export function storeAuthToken(token: string): void {
6185
localStorage.setItem(CONNECTION_AUTH_TOKEN_KEY, token)
6286
}
6387
catch {}
88+
// Deprecated: mirror into the legacy window global for viewers bundling an
89+
// older `devframe/client`. New viewers read the token from the connection
90+
// under `DEVFRAME_CONNECTION_KEY`.
6491
;(globalThis as any)[CONNECTION_AUTH_TOKEN_KEY] = token
6592

6693
const connection = readStoredConnection()

packages/devframe/src/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export const DEVFRAME_CONNECTION_META_FILENAME = '__connection.json'
99
* Global key holding the serializable connection prepared by
1010
* `setupDevframeConnection()`. External viewers can use this key to read the
1111
* connection from another JavaScript realm.
12+
*
13+
* This is the authoritative same-realm handoff: it supersedes the legacy
14+
* `__DEVFRAME_CONNECTION_META__` and window-global
15+
* `__DEVFRAME_CONNECTION_AUTH_TOKEN__` entries, which are now deprecated and
16+
* kept in sync only for viewers bundling an older `devframe/client`.
1217
*/
1318
export const DEVFRAME_CONNECTION_KEY = '__DEVFRAME_CONNECTION__'
1419

0 commit comments

Comments
 (0)