@djangocfg/layouts 2.1.664 → 2.1.665
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 +50 -15
- package/package.json +14 -14
- package/src/layouts/AppLayout/README.md +27 -17
package/README.md
CHANGED
|
@@ -18,7 +18,8 @@ pnpm add @djangocfg/layouts
|
|
|
18
18
|
@import "@djangocfg/layouts/styles";
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
Peers: `@djangocfg/ui-core`,
|
|
21
|
+
Peers: `@djangocfg/ui-core`, `@djangocfg/api`, `@djangocfg/realtime`, `@tanstack/react-query` 5, React 19,
|
|
22
|
+
Next.js 16+, Tailwind CSS 4. List each one in every app that mounts `BaseApp`, so the page holds one copy.
|
|
22
23
|
|
|
23
24
|
---
|
|
24
25
|
|
|
@@ -26,10 +27,9 @@ Peers: `@djangocfg/ui-core`, React 19, Next.js 16+, Tailwind CSS 4.
|
|
|
26
27
|
|
|
27
28
|
Two responsibilities, kept separate:
|
|
28
29
|
|
|
29
|
-
1. **Providers** — mount `BaseApp` ONCE at the app root (theme,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
in Wails/Vite too).
|
|
30
|
+
1. **Providers** — mount `BaseApp` ONCE at the app root (theme, the React
|
|
31
|
+
Query client, auth, i18n, realtime, monitor, toasts). It's framework-agnostic
|
|
32
|
+
(works in Wails/Vite too).
|
|
33
33
|
2. **Per-section shell** — each Next.js **route-group `layout.tsx`** imports the
|
|
34
34
|
matching shell (`PrivateLayout` / `PublicLayout`) and passes its own config.
|
|
35
35
|
No runtime layout-router, no `enabledPath` matching.
|
|
@@ -191,18 +191,53 @@ Wraps `Boundary` from `@djangocfg/ui-core` — same `variant`/`fallback`/`resetK
|
|
|
191
191
|
|
|
192
192
|
For local UI widgets that should not report to backend, use `Boundary` from `@djangocfg/ui-core` directly.
|
|
193
193
|
|
|
194
|
+
## React Query
|
|
195
|
+
|
|
196
|
+
`BaseApp` owns the page's one QueryClient. The generated hooks of `@djangocfg/api` and of an app's own client use
|
|
197
|
+
it; an app mounts no provider of its own.
|
|
198
|
+
|
|
199
|
+
- A `queryClient` prop wins and is used as it is (its defaults are not merged).
|
|
200
|
+
- Else a QueryClient already provided above `BaseApp` is reused, never nested.
|
|
201
|
+
- Else `createAppQueryClient()` makes one per mount (`useState`), never at module scope. Defaults: no retry on a 4xx
|
|
202
|
+
or a non-network error, up to 2 on a network error or a 5xx (`shouldRetryQuery`), `throwOnError: false`,
|
|
203
|
+
`staleTime` 30 s, refetch on focus, mutations not retried.
|
|
204
|
+
- `queryDevtools={() => import('@tanstack/react-query-devtools')}` mounts React Query Devtools in development only,
|
|
205
|
+
loaded on demand. The app installs the package.
|
|
206
|
+
|
|
207
|
+
```tsx
|
|
208
|
+
import { BaseApp } from '@djangocfg/layouts';
|
|
209
|
+
import type { ReactNode } from 'react';
|
|
210
|
+
|
|
211
|
+
export function AppLayout({ children }: { children: ReactNode }) {
|
|
212
|
+
return (
|
|
213
|
+
<BaseApp project="my-app" queryDevtools={() => import('@tanstack/react-query-devtools')}>
|
|
214
|
+
{children}
|
|
215
|
+
</BaseApp>
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
`createAppQueryClient` and `shouldRetryQuery` are exported for an app that builds its own client with the same
|
|
221
|
+
defaults, for example in tests. There is no SWR in layouts: no `swr` prop, no `SWRConfig`, no SWR peer.
|
|
222
|
+
|
|
194
223
|
## Realtime
|
|
195
224
|
|
|
196
|
-
`BaseApp` mounts `RealtimeProvider` from `@djangocfg/realtime` inside `AuthProvider`. It opens no
|
|
197
|
-
|
|
198
|
-
`/ws` (`ws:`/`wss:` by scheme).
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
225
|
+
`BaseApp` mounts `RealtimeProvider` from `@djangocfg/realtime` inside the QueryClient and `AuthProvider`. It opens no
|
|
226
|
+
socket until something subscribes, so a page that never subscribes costs nothing. The socket URL is the API origin
|
|
227
|
+
plus `/ws` (`ws:`/`wss:` by scheme).
|
|
228
|
+
|
|
229
|
+
- **REST refresh, no code.** A generated query whose view is marked `@invalidated_by("topic")` carries the concrete
|
|
230
|
+
topic names in `meta.realtimeTopics` (`REALTIME_META_KEY`). `BaseApp` watches the QueryCache: while such a query
|
|
231
|
+
has an observer its topics stay subscribed, and a message, a gap or a fresh subscription going live invalidates
|
|
232
|
+
the queries tagged with that topic, once per burst. `topicsOfQuery(query)` reads the tags.
|
|
233
|
+
- **Events.** `useTopic(topic, onEvent)` from `@djangocfg/realtime/react` for data pushed in the event itself.
|
|
234
|
+
- **Gaps.** Unless `realtime.onGap` is set, a gap on a `useTopic` subscription invalidates the queries tagged with
|
|
235
|
+
that topic too.
|
|
236
|
+
- **Issues** (a 4401/4403/4500 close, five failed handshakes in a row, a refused topic, a protocol error, a dev
|
|
237
|
+
schema failure) go to `@djangocfg/devtools` like any other frontend error; normal drops are not reported.
|
|
238
|
+
|
|
239
|
+
`realtime={{ url, path, onGap, onIssue }}` tunes it, `realtime={false}` removes it. A QueryClient passed explicitly to
|
|
240
|
+
a generated hook (its second argument) is a second cache that this bridge never sees. Usage:
|
|
206
241
|
[`@djangocfg/realtime`](../realtime/README.md).
|
|
207
242
|
|
|
208
243
|
## Analytics and auth funnels
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/layouts",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.665",
|
|
4
4
|
"description": "Simple, straightforward layout components for Next.js - import and use with props",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"layouts",
|
|
@@ -91,12 +91,12 @@
|
|
|
91
91
|
"test": "vitest run"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
|
-
"@djangocfg/analytics": "^2.1.
|
|
95
|
-
"@djangocfg/api": "^2.1.
|
|
96
|
-
"@djangocfg/devtools": "^2.1.
|
|
97
|
-
"@djangocfg/i18n": "^2.1.
|
|
98
|
-
"@djangocfg/realtime": "^2.1.
|
|
99
|
-
"@djangocfg/ui-core": "^2.1.
|
|
94
|
+
"@djangocfg/analytics": "^2.1.665",
|
|
95
|
+
"@djangocfg/api": "^2.1.665",
|
|
96
|
+
"@djangocfg/devtools": "^2.1.665",
|
|
97
|
+
"@djangocfg/i18n": "^2.1.665",
|
|
98
|
+
"@djangocfg/realtime": "^2.1.665",
|
|
99
|
+
"@djangocfg/ui-core": "^2.1.665",
|
|
100
100
|
"@hookform/resolvers": "^5.2.2 || ^7.0.2",
|
|
101
101
|
"@tanstack/react-query": "^5.108.2",
|
|
102
102
|
"consola": "^3.4.2",
|
|
@@ -123,13 +123,13 @@
|
|
|
123
123
|
"qrcode.react": "^4.2.0"
|
|
124
124
|
},
|
|
125
125
|
"devDependencies": {
|
|
126
|
-
"@djangocfg/analytics": "^2.1.
|
|
127
|
-
"@djangocfg/api": "^2.1.
|
|
128
|
-
"@djangocfg/devtools": "^2.1.
|
|
129
|
-
"@djangocfg/i18n": "^2.1.
|
|
130
|
-
"@djangocfg/realtime": "^2.1.
|
|
131
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
132
|
-
"@djangocfg/ui-core": "^2.1.
|
|
126
|
+
"@djangocfg/analytics": "^2.1.665",
|
|
127
|
+
"@djangocfg/api": "^2.1.665",
|
|
128
|
+
"@djangocfg/devtools": "^2.1.665",
|
|
129
|
+
"@djangocfg/i18n": "^2.1.665",
|
|
130
|
+
"@djangocfg/realtime": "^2.1.665",
|
|
131
|
+
"@djangocfg/typescript-config": "^2.1.665",
|
|
132
|
+
"@djangocfg/ui-core": "^2.1.665",
|
|
133
133
|
"@storybook/react-vite": "^10.6.5",
|
|
134
134
|
"@tanstack/react-query": "5.108.2",
|
|
135
135
|
"@types/node": "^25.9.5",
|
|
@@ -74,38 +74,48 @@ export function App() {
|
|
|
74
74
|
## Config surface
|
|
75
75
|
|
|
76
76
|
```ts
|
|
77
|
+
// BaseAppProps = BaseLayoutProps (src/layouts/types/layout.types.ts), abridged
|
|
77
78
|
interface BaseAppProps {
|
|
78
79
|
children: ReactNode;
|
|
79
|
-
project?: string; //
|
|
80
|
-
theme?: ThemeConfig; // defaultTheme, storageKey
|
|
80
|
+
project?: string; // devtools project + debug panel title default
|
|
81
|
+
theme?: ThemeConfig; // defaultTheme, storageKey
|
|
81
82
|
auth?: AuthConfig | false; // false = no AuthProvider (fully public app); `{ sso: true }` = one sign-in host (auth.<apex>) for the subdomains
|
|
83
|
+
apiUrl?: string; // API origin for devtools and realtime when auth={false}
|
|
82
84
|
analytics?: AnalyticsConfig; // Google Analytics
|
|
83
85
|
errorTracking?: ErrorTrackingConfig;
|
|
86
|
+
queryClient?: QueryClient; // the app's own; else one above BaseApp is reused, else one with our defaults
|
|
87
|
+
queryDevtools?: QueryDevtoolsLoader; // () => import('@tanstack/react-query-devtools'), dev builds only, lazy
|
|
84
88
|
errorBoundary?: ErrorBoundaryConfig; // enabled by default
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
monitor?: MonitorConfig;
|
|
88
|
-
debug?: DebugConfig; // debug panel (auto in dev / ?debug=1 in prod)
|
|
89
|
+
devtools?: DevtoolsConfig; // capture, ingest, debug panel
|
|
90
|
+
realtime?: RealtimeConfig | false; // lazy WebSocket; issues go to devtools; false removes it
|
|
89
91
|
i18n?: I18nLayoutConfig; // locale + routing for the link bridge
|
|
90
|
-
|
|
92
|
+
pwaMeta?: boolean; // installed-app meta tags, on by default
|
|
93
|
+
progressBar?: boolean | RouteProgressOptions;
|
|
94
|
+
debug?: boolean; // the viewport diagnostic dot
|
|
91
95
|
}
|
|
92
96
|
```
|
|
93
97
|
|
|
94
98
|
## React Query and realtime refresh
|
|
95
99
|
|
|
96
|
-
`BaseApp` owns the page's one QueryClient
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
`BaseApp` owns the page's one QueryClient (`query/AppQueryProvider.tsx`):
|
|
101
|
+
|
|
102
|
+
- a `queryClient` prop wins and is used as it is, its defaults unmerged;
|
|
103
|
+
- else a QueryClient already provided above `BaseApp` is reused, so a page never holds two caches;
|
|
104
|
+
- else `createAppQueryClient()` makes one per mount (`useState`), never at module scope.
|
|
105
|
+
|
|
106
|
+
Its defaults: no retry on a 4xx or a non-network error, up to 2 on a network error or a 5xx (`shouldRetryQuery`),
|
|
107
|
+
`throwOnError: false`, `staleTime` 30 s, refetch on focus, and mutations are not retried. `queryDevtools` renders
|
|
108
|
+
React Query Devtools in development builds only, loaded lazily; the app installs `@tanstack/react-query-devtools`.
|
|
109
|
+
`@tanstack/react-query` is a peer: every app that mounts `BaseApp` lists it. There is no SWR here.
|
|
102
110
|
|
|
103
111
|
A generated query whose view is marked `@invalidated_by("topic")` carries the
|
|
104
112
|
concrete topic names in `meta.realtimeTopics` (the generated
|
|
105
|
-
`runtime/realtime-query.ts`). `RealtimeMount`
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
113
|
+
`runtime/realtime-query.ts`). `RealtimeMount` (`realtime/queryRealtime.ts`,
|
|
114
|
+
`bridgeQueryCache`) watches the QueryCache. While such a query has an observer,
|
|
115
|
+
its topics stay subscribed (released lazily, 1.5 s after the last one goes). A
|
|
116
|
+
message, a gap or a fresh subscription going live invalidates the queries tagged
|
|
117
|
+
with that topic. The page needs no code. A QueryClient passed to a hook as its
|
|
118
|
+
second argument is not this cache, and its queries never refresh this way.
|
|
109
119
|
|
|
110
120
|
## Per-route forced theme (optional)
|
|
111
121
|
|