@djangocfg/api 2.1.548 → 2.1.550
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/dist/auth.cjs +9 -4
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.mjs +9 -4
- package/dist/auth.mjs.map +1 -1
- package/package.json +2 -2
- package/src/auth/context/AccountsContext.tsx +17 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/api",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.550",
|
|
4
4
|
"description": "Auto-generated TypeScript API client with React hooks, SWR integration, and Zod validation for Django REST Framework backends",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"django",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"zod": "^4.3.6"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
88
|
+
"@djangocfg/typescript-config": "^2.1.550",
|
|
89
89
|
"@testing-library/react": "^16.3.2",
|
|
90
90
|
"@types/node": "^25.9.5",
|
|
91
91
|
"@types/react": "19.2.15",
|
|
@@ -101,6 +101,9 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
|
|
|
101
101
|
|
|
102
102
|
const profileRef = useRef<User | undefined>(profile);
|
|
103
103
|
const isLoadingRef = useRef(false);
|
|
104
|
+
// Monotonic id per fetch. A forced re-read can now overlap the bootstrap
|
|
105
|
+
// one, and the slower response must not overwrite the newer profile.
|
|
106
|
+
const fetchSeqRef = useRef(0);
|
|
104
107
|
|
|
105
108
|
useEffect(() => {
|
|
106
109
|
profileRef.current = profile;
|
|
@@ -129,11 +132,16 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
|
|
|
129
132
|
return undefined;
|
|
130
133
|
}
|
|
131
134
|
|
|
132
|
-
|
|
135
|
+
// `force` is how a write says "I just changed the server, re-read it".
|
|
136
|
+
// Honouring the in-flight guard there would hand the caller back the
|
|
137
|
+
// pre-write profile and never fetch again, so the UI keeps showing the
|
|
138
|
+
// old value indefinitely.
|
|
139
|
+
if (isLoadingRef.current && !force) {
|
|
133
140
|
authLogger.debug(`Profile loading in progress, skipping (caller: ${callerId})`);
|
|
134
141
|
return profileRef.current;
|
|
135
142
|
}
|
|
136
143
|
|
|
144
|
+
const seq = ++fetchSeqRef.current;
|
|
137
145
|
setIsLoadingProfile(true);
|
|
138
146
|
isLoadingRef.current = true;
|
|
139
147
|
setProfileError(null);
|
|
@@ -141,17 +149,22 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
|
|
|
141
149
|
authLogger.debug(`Fetching profile from API (caller: ${callerId}, force: ${force})`);
|
|
142
150
|
const res = await CfgAccountsProfile.cfgAccountsProfileRetrieve({ throwOnError: true });
|
|
143
151
|
const result = res.data;
|
|
152
|
+
// A newer fetch already landed — its profile is the current one, and
|
|
153
|
+
// this older response would roll it back.
|
|
154
|
+
if (seq !== fetchSeqRef.current) return result;
|
|
144
155
|
setProfile(result);
|
|
145
156
|
profileRef.current = result;
|
|
146
157
|
setCachedProfile(result);
|
|
147
158
|
return result;
|
|
148
159
|
} catch (error) {
|
|
149
160
|
const err = error instanceof Error ? error : new Error('Failed to fetch profile');
|
|
150
|
-
setProfileError(err);
|
|
161
|
+
if (seq === fetchSeqRef.current) setProfileError(err);
|
|
151
162
|
throw err;
|
|
152
163
|
} finally {
|
|
153
|
-
|
|
154
|
-
|
|
164
|
+
if (seq === fetchSeqRef.current) {
|
|
165
|
+
setIsLoadingProfile(false);
|
|
166
|
+
isLoadingRef.current = false;
|
|
167
|
+
}
|
|
155
168
|
}
|
|
156
169
|
}, []);
|
|
157
170
|
|