@replanejs/next 0.7.3 → 0.7.5
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/README.md +160 -296
- package/dist/index.cjs +100 -174
- package/dist/index.d.cts +23 -183
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +24 -184
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -171
- package/dist/index.js.map +1 -1
- package/package.json +7 -15
- package/dist/chunk-CUT6urMc.cjs +0 -30
- package/dist/server.cjs +0 -95
- package/dist/server.d.cts +0 -114
- package/dist/server.d.cts.map +0 -1
- package/dist/server.d.ts +0 -114
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -94
- package/dist/server.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,203 +1,129 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
const __replanejs_react = __toESM(require("@replanejs/react"));
|
|
25
|
+
const __replanejs_sdk = __toESM(require("@replanejs/sdk"));
|
|
26
|
+
const react_jsx_runtime = __toESM(require("react/jsx-runtime"));
|
|
6
27
|
|
|
7
|
-
//#region src/
|
|
28
|
+
//#region src/root.tsx
|
|
8
29
|
/**
|
|
9
|
-
*
|
|
30
|
+
* Server component that fetches Replane configs and provides them to the app.
|
|
31
|
+
* This is the simplest way to set up Replane in Next.js App Router.
|
|
10
32
|
*
|
|
11
|
-
*
|
|
12
|
-
* 1. Restores the Replane client from a server-side snapshot instantly (no loading state)
|
|
13
|
-
* 2. Optionally connects to Replane for real-time updates
|
|
14
|
-
* 3. Preserves the client across re-renders for minimal latency
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
33
|
+
* @example Basic usage in layout.tsx
|
|
17
34
|
* ```tsx
|
|
18
35
|
* // app/layout.tsx
|
|
19
|
-
* import {
|
|
20
|
-
* import { ReplaneNextProvider } from "@replanejs/next";
|
|
21
|
-
*
|
|
22
|
-
* export default async function RootLayout({ children }) {
|
|
23
|
-
* const snapshot = await getReplaneSnapshot({
|
|
24
|
-
* baseUrl: process.env.REPLANE_BASE_URL!,
|
|
25
|
-
* sdkKey: process.env.REPLANE_SDK_KEY!,
|
|
26
|
-
* });
|
|
36
|
+
* import { ReplaneRoot } from "@replanejs/next";
|
|
27
37
|
*
|
|
38
|
+
* export default function RootLayout({ children }) {
|
|
28
39
|
* return (
|
|
29
40
|
* <html>
|
|
30
41
|
* <body>
|
|
31
|
-
* <
|
|
32
|
-
*
|
|
33
|
-
* connection={{
|
|
42
|
+
* <ReplaneRoot
|
|
43
|
+
* options={{
|
|
34
44
|
* baseUrl: process.env.NEXT_PUBLIC_REPLANE_BASE_URL!,
|
|
35
45
|
* sdkKey: process.env.NEXT_PUBLIC_REPLANE_SDK_KEY!,
|
|
36
46
|
* }}
|
|
37
47
|
* >
|
|
38
48
|
* {children}
|
|
39
|
-
* </
|
|
49
|
+
* </ReplaneRoot>
|
|
40
50
|
* </body>
|
|
41
51
|
* </html>
|
|
42
52
|
* );
|
|
43
53
|
* }
|
|
44
54
|
* ```
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```tsx
|
|
48
|
-
* // Without real-time updates (static snapshot only)
|
|
49
|
-
* <ReplaneNextProvider snapshot={snapshot}>
|
|
50
|
-
* {children}
|
|
51
|
-
* </ReplaneNextProvider>
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
function ReplaneNextProvider({ snapshot, connection, context, children }) {
|
|
55
|
-
const clientRef = (0, react.useRef)(null);
|
|
56
|
-
const clientKey = (0, react.useMemo)(() => {
|
|
57
|
-
const snapshotKey = JSON.stringify(snapshot.configs.map((c) => c.name).sort());
|
|
58
|
-
const connectionKey = connection ? `${connection.baseUrl}:${connection.sdkKey}` : "no-connection";
|
|
59
|
-
const contextKey = context ? JSON.stringify(context) : "no-context";
|
|
60
|
-
return `${snapshotKey}:${connectionKey}:${contextKey}`;
|
|
61
|
-
}, [
|
|
62
|
-
snapshot,
|
|
63
|
-
connection,
|
|
64
|
-
context
|
|
65
|
-
]);
|
|
66
|
-
const client = (0, react.useMemo)(() => {
|
|
67
|
-
if (clientRef.current) {}
|
|
68
|
-
const newClient = (0, __replanejs_sdk.restoreReplaneClient)({
|
|
69
|
-
snapshot,
|
|
70
|
-
connection: connection ? {
|
|
71
|
-
baseUrl: connection.baseUrl,
|
|
72
|
-
sdkKey: connection.sdkKey,
|
|
73
|
-
requestTimeoutMs: connection.requestTimeoutMs,
|
|
74
|
-
retryDelayMs: connection.retryDelayMs,
|
|
75
|
-
inactivityTimeoutMs: connection.inactivityTimeoutMs
|
|
76
|
-
} : void 0,
|
|
77
|
-
context
|
|
78
|
-
});
|
|
79
|
-
clientRef.current = newClient;
|
|
80
|
-
return newClient;
|
|
81
|
-
}, [clientKey]);
|
|
82
|
-
(0, react.useEffect)(() => {
|
|
83
|
-
return () => {
|
|
84
|
-
if (clientRef.current) {
|
|
85
|
-
clientRef.current.close();
|
|
86
|
-
clientRef.current = null;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}, []);
|
|
90
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__replanejs_react.ReplaneProvider, {
|
|
91
|
-
client,
|
|
92
|
-
children
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region src/script.tsx
|
|
98
|
-
const REPLANE_SNAPSHOT_KEY = "__REPLANE_SNAPSHOT__";
|
|
99
|
-
/**
|
|
100
|
-
* Generate the script content for embedding the snapshot.
|
|
101
|
-
*
|
|
102
|
-
* Use this in a Server Component to embed the snapshot in the page:
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* ```tsx
|
|
106
|
-
* // app/layout.tsx
|
|
107
|
-
* import { getReplaneSnapshot } from "@replanejs/next/server";
|
|
108
|
-
* import { getReplaneSnapshotScript, ReplaneScriptProvider } from "@replanejs/next";
|
|
109
|
-
*
|
|
110
|
-
* export default async function RootLayout({ children }) {
|
|
111
|
-
* const snapshot = await getReplaneSnapshot({ ... });
|
|
112
|
-
*
|
|
113
|
-
* return (
|
|
114
|
-
* <html>
|
|
115
|
-
* <head>
|
|
116
|
-
* <script
|
|
117
|
-
* dangerouslySetInnerHTML={{
|
|
118
|
-
* __html: getReplaneSnapshotScript(snapshot),
|
|
119
|
-
* }}
|
|
120
|
-
* />
|
|
121
|
-
* </head>
|
|
122
|
-
* <body>
|
|
123
|
-
* <ReplaneScriptProvider connection={{ ... }}>
|
|
124
|
-
* {children}
|
|
125
|
-
* </ReplaneScriptProvider>
|
|
126
|
-
* </body>
|
|
127
|
-
* </html>
|
|
128
|
-
* );
|
|
129
|
-
* }
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
function getReplaneSnapshotScript(snapshot) {
|
|
133
|
-
const json = JSON.stringify(snapshot).replace(/<\/script>/gi, "<\\/script>");
|
|
134
|
-
return `window.${REPLANE_SNAPSHOT_KEY}=${json};`;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Provider that reads the snapshot from a script tag.
|
|
138
|
-
*
|
|
139
|
-
* Use this with `getReplaneSnapshotScript()` for an alternative hydration pattern
|
|
140
|
-
* where the snapshot is embedded in a script tag instead of passed as a prop.
|
|
141
|
-
*
|
|
142
|
-
* This pattern can be useful for:
|
|
143
|
-
* - Pages with heavy component trees where prop drilling is inconvenient
|
|
144
|
-
* - Partial hydration scenarios
|
|
145
|
-
* - When you want the snapshot to be available before React hydrates
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```tsx
|
|
149
|
-
* // In app/layout.tsx (Server Component)
|
|
150
|
-
* <script dangerouslySetInnerHTML={{ __html: getReplaneSnapshotScript(snapshot) }} />
|
|
151
|
-
*
|
|
152
|
-
* // In a client component
|
|
153
|
-
* <ReplaneScriptProvider connection={{ baseUrl, sdkKey }}>
|
|
154
|
-
* <App />
|
|
155
|
-
* </ReplaneScriptProvider>
|
|
156
|
-
* ```
|
|
157
55
|
*/
|
|
158
|
-
function
|
|
159
|
-
const
|
|
160
|
-
if (typeof window !== "undefined" && window[REPLANE_SNAPSHOT_KEY]) return window[REPLANE_SNAPSHOT_KEY];
|
|
161
|
-
return null;
|
|
162
|
-
});
|
|
163
|
-
const clientRef = (0, react.useRef)(null);
|
|
164
|
-
(0, react.useEffect)(() => {
|
|
165
|
-
if (!snapshot && typeof window !== "undefined" && window[REPLANE_SNAPSHOT_KEY]) setSnapshot(window[REPLANE_SNAPSHOT_KEY]);
|
|
166
|
-
}, [snapshot]);
|
|
167
|
-
const client = (0, react.useMemo)(() => {
|
|
168
|
-
if (!snapshot) return null;
|
|
169
|
-
const newClient = (0, __replanejs_sdk.restoreReplaneClient)({
|
|
170
|
-
snapshot,
|
|
171
|
-
connection: connection ? {
|
|
172
|
-
baseUrl: connection.baseUrl,
|
|
173
|
-
sdkKey: connection.sdkKey,
|
|
174
|
-
requestTimeoutMs: connection.requestTimeoutMs,
|
|
175
|
-
retryDelayMs: connection.retryDelayMs,
|
|
176
|
-
inactivityTimeoutMs: connection.inactivityTimeoutMs
|
|
177
|
-
} : void 0
|
|
178
|
-
});
|
|
179
|
-
clientRef.current = newClient;
|
|
180
|
-
return newClient;
|
|
181
|
-
}, [snapshot, connection]);
|
|
182
|
-
(0, react.useEffect)(() => {
|
|
183
|
-
return () => {
|
|
184
|
-
if (clientRef.current) {
|
|
185
|
-
clientRef.current.close();
|
|
186
|
-
clientRef.current = null;
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
}, []);
|
|
190
|
-
if (!client) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: fallback ?? null });
|
|
56
|
+
async function ReplaneRoot({ options, children }) {
|
|
57
|
+
const snapshot = await (0, __replanejs_react.getReplaneSnapshot)(options);
|
|
191
58
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__replanejs_react.ReplaneProvider, {
|
|
192
|
-
|
|
59
|
+
options,
|
|
60
|
+
snapshot,
|
|
193
61
|
children
|
|
194
62
|
});
|
|
195
63
|
}
|
|
196
64
|
|
|
197
65
|
//#endregion
|
|
198
|
-
exports
|
|
199
|
-
|
|
200
|
-
|
|
66
|
+
Object.defineProperty(exports, 'ReplaneError', {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return __replanejs_sdk.ReplaneError;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, 'ReplaneErrorCode', {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return __replanejs_sdk.ReplaneErrorCode;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, 'ReplaneProvider', {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return __replanejs_react.ReplaneProvider;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
exports.ReplaneRoot = ReplaneRoot;
|
|
85
|
+
Object.defineProperty(exports, 'clearSnapshotCache', {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function () {
|
|
88
|
+
return __replanejs_react.clearSnapshotCache;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
Object.defineProperty(exports, 'clearSuspenseCache', {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function () {
|
|
94
|
+
return __replanejs_react.clearSuspenseCache;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(exports, 'createConfigHook', {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function () {
|
|
100
|
+
return __replanejs_react.createConfigHook;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(exports, 'createInMemoryReplaneClient', {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function () {
|
|
106
|
+
return __replanejs_sdk.createInMemoryReplaneClient;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, 'createReplaneClient', {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () {
|
|
112
|
+
return __replanejs_sdk.createReplaneClient;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(exports, 'createReplaneHook', {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
get: function () {
|
|
118
|
+
return __replanejs_react.createReplaneHook;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
Object.defineProperty(exports, 'getReplaneSnapshot', {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
get: function () {
|
|
124
|
+
return __replanejs_react.getReplaneSnapshot;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
201
127
|
Object.defineProperty(exports, 'restoreReplaneClient', {
|
|
202
128
|
enumerable: true,
|
|
203
129
|
get: function () {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,216 +1,56 @@
|
|
|
1
|
-
import * as react_jsx_runtime0$1 from "react/jsx-runtime";
|
|
2
1
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
2
|
import { ReactNode } from "react";
|
|
4
|
-
import { ReplaneClient,
|
|
5
|
-
import {
|
|
3
|
+
import { GetConfigOptions, ReplaneClient, ReplaneClientOptions, ReplaneClientOptions as ReplaneClientOptions$1, ReplaneContext, ReplaneError, ReplaneErrorCode, ReplaneLogger, ReplaneSnapshot, RestoreReplaneClientOptions, createInMemoryReplaneClient, createReplaneClient, restoreReplaneClient } from "@replanejs/sdk";
|
|
4
|
+
import { GetReplaneSnapshotOptions, ReplaneProvider, ReplaneProviderProps, ReplaneProviderWithClientProps, ReplaneProviderWithOptionsProps, clearSnapshotCache, clearSuspenseCache, createConfigHook, createReplaneHook, getReplaneSnapshot, useConfig, useReplane } from "@replanejs/react";
|
|
5
|
+
|
|
6
|
+
//#region src/root.d.ts
|
|
6
7
|
|
|
7
|
-
//#region src/types.d.ts
|
|
8
|
-
/**
|
|
9
|
-
* Connection options for real-time updates.
|
|
10
|
-
*/
|
|
11
|
-
interface ReplaneConnectionOptions {
|
|
12
|
-
/**
|
|
13
|
-
* Base URL of the Replane instance (no trailing slash).
|
|
14
|
-
* Use a NEXT_PUBLIC_ prefixed env var for client-side access.
|
|
15
|
-
*/
|
|
16
|
-
baseUrl: string;
|
|
17
|
-
/**
|
|
18
|
-
* Project SDK key for authorization.
|
|
19
|
-
* Use a NEXT_PUBLIC_ prefixed env var for client-side access.
|
|
20
|
-
*/
|
|
21
|
-
sdkKey: string;
|
|
22
|
-
/**
|
|
23
|
-
* Optional timeout in ms for requests.
|
|
24
|
-
* @default 2000
|
|
25
|
-
*/
|
|
26
|
-
requestTimeoutMs?: number;
|
|
27
|
-
/**
|
|
28
|
-
* Delay between retries in ms.
|
|
29
|
-
* @default 200
|
|
30
|
-
*/
|
|
31
|
-
retryDelayMs?: number;
|
|
32
|
-
/**
|
|
33
|
-
* Timeout in ms for SSE connection inactivity.
|
|
34
|
-
* @default 30000
|
|
35
|
-
*/
|
|
36
|
-
inactivityTimeoutMs?: number;
|
|
37
|
-
}
|
|
38
8
|
/**
|
|
39
|
-
* Props for
|
|
9
|
+
* Props for ReplaneRoot server component
|
|
40
10
|
*/
|
|
41
|
-
interface
|
|
42
|
-
/**
|
|
43
|
-
* Serializable snapshot from the server.
|
|
44
|
-
* Obtained from `getReplaneSnapshot()` in a Server Component or getServerSideProps.
|
|
45
|
-
*/
|
|
46
|
-
snapshot: ReplaneSnapshot$1<T>;
|
|
11
|
+
interface ReplaneRootProps<T extends object> {
|
|
47
12
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* For SSR apps that need real-time updates, provide connection options:
|
|
52
|
-
* ```tsx
|
|
53
|
-
* <ReplaneNextProvider
|
|
54
|
-
* snapshot={snapshot}
|
|
55
|
-
* connection={{
|
|
56
|
-
* baseUrl: process.env.NEXT_PUBLIC_REPLANE_BASE_URL!,
|
|
57
|
-
* sdkKey: process.env.NEXT_PUBLIC_REPLANE_SDK_KEY!,
|
|
58
|
-
* }}
|
|
59
|
-
* >
|
|
60
|
-
* {children}
|
|
61
|
-
* </ReplaneNextProvider>
|
|
62
|
-
* ```
|
|
13
|
+
* Options for Replane client.
|
|
14
|
+
* Used for both server-side fetching and client-side live updates.
|
|
63
15
|
*/
|
|
64
|
-
|
|
16
|
+
options: ReplaneClientOptions$1<T>;
|
|
65
17
|
/**
|
|
66
|
-
*
|
|
67
|
-
* Useful for client-specific context like browser info.
|
|
18
|
+
* React children to render inside the provider
|
|
68
19
|
*/
|
|
69
|
-
context?: ReplaneContext$1;
|
|
70
20
|
children: ReactNode;
|
|
71
21
|
}
|
|
72
|
-
//# sourceMappingURL=types.d.ts.map
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region src/provider.d.ts
|
|
75
22
|
/**
|
|
76
|
-
*
|
|
23
|
+
* Server component that fetches Replane configs and provides them to the app.
|
|
24
|
+
* This is the simplest way to set up Replane in Next.js App Router.
|
|
77
25
|
*
|
|
78
|
-
*
|
|
79
|
-
* 1. Restores the Replane client from a server-side snapshot instantly (no loading state)
|
|
80
|
-
* 2. Optionally connects to Replane for real-time updates
|
|
81
|
-
* 3. Preserves the client across re-renders for minimal latency
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
26
|
+
* @example Basic usage in layout.tsx
|
|
84
27
|
* ```tsx
|
|
85
28
|
* // app/layout.tsx
|
|
86
|
-
* import {
|
|
87
|
-
* import { ReplaneNextProvider } from "@replanejs/next";
|
|
88
|
-
*
|
|
89
|
-
* export default async function RootLayout({ children }) {
|
|
90
|
-
* const snapshot = await getReplaneSnapshot({
|
|
91
|
-
* baseUrl: process.env.REPLANE_BASE_URL!,
|
|
92
|
-
* sdkKey: process.env.REPLANE_SDK_KEY!,
|
|
93
|
-
* });
|
|
29
|
+
* import { ReplaneRoot } from "@replanejs/next";
|
|
94
30
|
*
|
|
31
|
+
* export default function RootLayout({ children }) {
|
|
95
32
|
* return (
|
|
96
33
|
* <html>
|
|
97
34
|
* <body>
|
|
98
|
-
* <
|
|
99
|
-
*
|
|
100
|
-
* connection={{
|
|
35
|
+
* <ReplaneRoot
|
|
36
|
+
* options={{
|
|
101
37
|
* baseUrl: process.env.NEXT_PUBLIC_REPLANE_BASE_URL!,
|
|
102
38
|
* sdkKey: process.env.NEXT_PUBLIC_REPLANE_SDK_KEY!,
|
|
103
39
|
* }}
|
|
104
40
|
* >
|
|
105
41
|
* {children}
|
|
106
|
-
* </
|
|
42
|
+
* </ReplaneRoot>
|
|
107
43
|
* </body>
|
|
108
44
|
* </html>
|
|
109
45
|
* );
|
|
110
46
|
* }
|
|
111
47
|
* ```
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```tsx
|
|
115
|
-
* // Without real-time updates (static snapshot only)
|
|
116
|
-
* <ReplaneNextProvider snapshot={snapshot}>
|
|
117
|
-
* {children}
|
|
118
|
-
* </ReplaneNextProvider>
|
|
119
|
-
* ```
|
|
120
|
-
*/
|
|
121
|
-
declare function ReplaneNextProvider<T extends object = Record<string, unknown>>({
|
|
122
|
-
snapshot,
|
|
123
|
-
connection,
|
|
124
|
-
context,
|
|
125
|
-
children
|
|
126
|
-
}: ReplaneNextProviderProps<T>): react_jsx_runtime0$1.JSX.Element;
|
|
127
|
-
//# sourceMappingURL=provider.d.ts.map
|
|
128
|
-
//#endregion
|
|
129
|
-
//#region src/script.d.ts
|
|
130
|
-
declare const REPLANE_SNAPSHOT_KEY = "__REPLANE_SNAPSHOT__";
|
|
131
|
-
type AnyConfig = Record<string, unknown>;
|
|
132
|
-
declare global {
|
|
133
|
-
interface Window {
|
|
134
|
-
[REPLANE_SNAPSHOT_KEY]?: ReplaneSnapshot$1<AnyConfig>;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Generate the script content for embedding the snapshot.
|
|
139
|
-
*
|
|
140
|
-
* Use this in a Server Component to embed the snapshot in the page:
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```tsx
|
|
144
|
-
* // app/layout.tsx
|
|
145
|
-
* import { getReplaneSnapshot } from "@replanejs/next/server";
|
|
146
|
-
* import { getReplaneSnapshotScript, ReplaneScriptProvider } from "@replanejs/next";
|
|
147
|
-
*
|
|
148
|
-
* export default async function RootLayout({ children }) {
|
|
149
|
-
* const snapshot = await getReplaneSnapshot({ ... });
|
|
150
|
-
*
|
|
151
|
-
* return (
|
|
152
|
-
* <html>
|
|
153
|
-
* <head>
|
|
154
|
-
* <script
|
|
155
|
-
* dangerouslySetInnerHTML={{
|
|
156
|
-
* __html: getReplaneSnapshotScript(snapshot),
|
|
157
|
-
* }}
|
|
158
|
-
* />
|
|
159
|
-
* </head>
|
|
160
|
-
* <body>
|
|
161
|
-
* <ReplaneScriptProvider connection={{ ... }}>
|
|
162
|
-
* {children}
|
|
163
|
-
* </ReplaneScriptProvider>
|
|
164
|
-
* </body>
|
|
165
|
-
* </html>
|
|
166
|
-
* );
|
|
167
|
-
* }
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
declare function getReplaneSnapshotScript<T extends object = AnyConfig>(snapshot: ReplaneSnapshot$1<T>): string;
|
|
171
|
-
/**
|
|
172
|
-
* Props for ReplaneScriptProvider.
|
|
173
|
-
*/
|
|
174
|
-
interface ReplaneScriptProviderProps {
|
|
175
|
-
/**
|
|
176
|
-
* Connection options for real-time updates.
|
|
177
|
-
* If not provided, the client will only use the snapshot data (no live updates).
|
|
178
|
-
*/
|
|
179
|
-
connection?: ReplaneConnectionOptions;
|
|
180
|
-
/**
|
|
181
|
-
* Fallback to render while waiting for the snapshot.
|
|
182
|
-
* This should rarely be needed since the script is in the head.
|
|
183
|
-
*/
|
|
184
|
-
fallback?: ReactNode;
|
|
185
|
-
children: ReactNode;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Provider that reads the snapshot from a script tag.
|
|
189
|
-
*
|
|
190
|
-
* Use this with `getReplaneSnapshotScript()` for an alternative hydration pattern
|
|
191
|
-
* where the snapshot is embedded in a script tag instead of passed as a prop.
|
|
192
|
-
*
|
|
193
|
-
* This pattern can be useful for:
|
|
194
|
-
* - Pages with heavy component trees where prop drilling is inconvenient
|
|
195
|
-
* - Partial hydration scenarios
|
|
196
|
-
* - When you want the snapshot to be available before React hydrates
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* ```tsx
|
|
200
|
-
* // In app/layout.tsx (Server Component)
|
|
201
|
-
* <script dangerouslySetInnerHTML={{ __html: getReplaneSnapshotScript(snapshot) }} />
|
|
202
|
-
*
|
|
203
|
-
* // In a client component
|
|
204
|
-
* <ReplaneScriptProvider connection={{ baseUrl, sdkKey }}>
|
|
205
|
-
* <App />
|
|
206
|
-
* </ReplaneScriptProvider>
|
|
207
|
-
* ```
|
|
208
48
|
*/
|
|
209
|
-
declare function
|
|
210
|
-
|
|
211
|
-
fallback,
|
|
49
|
+
declare function ReplaneRoot<T extends object>({
|
|
50
|
+
options,
|
|
212
51
|
children
|
|
213
|
-
}:
|
|
52
|
+
}: ReplaneRootProps<T>): Promise<react_jsx_runtime0.JSX.Element>;
|
|
53
|
+
//# sourceMappingURL=root.d.ts.map
|
|
214
54
|
//#endregion
|
|
215
|
-
export { type ReplaneClient, type
|
|
55
|
+
export { type GetConfigOptions, type GetReplaneSnapshotOptions, type ReplaneClient, type ReplaneClientOptions, type ReplaneContext, ReplaneError, ReplaneErrorCode, type ReplaneLogger, ReplaneProvider, type ReplaneProviderProps, type ReplaneProviderWithClientProps, type ReplaneProviderWithOptionsProps, ReplaneRoot, type ReplaneRootProps, type ReplaneSnapshot, type RestoreReplaneClientOptions, clearSnapshotCache, clearSuspenseCache, createConfigHook, createInMemoryReplaneClient, createReplaneClient, createReplaneHook, getReplaneSnapshot, restoreReplaneClient, useConfig, useReplane };
|
|
216
56
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/root.tsx"],"sourcesContent":[],"mappings":";;;;;;;AAaA;;;AAKW,UALM,gBAKN,CAAA,UAAA,MAAA,CAAA,CAAA;EAAoB;AAIV;AA8BrB;;EAAiC,OAAqB,EAlC3C,sBAkC2C,CAlCtB,CAkCsB,CAAA;EAAO;;;EAA8B,QAAG,EA9BlF,SA8BkF;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAxE;;;GAAqD,iBAAiB,KAAE,QAAA,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|