@autobusal/providers 1.29.2 → 1.29.3
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/CHANGELOG.md +31 -0
- package/Errors/BootstrapError.tsx +107 -0
- package/Providers.tsx +13 -0
- package/Queries/Queries.tsx +48 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.29.3
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- **A failed settings fetch white-screened the entire app.** `useGetSettings`
|
|
8
|
+
is a *suspense* query, so a failure throws during render rather than
|
|
9
|
+
resolving to an error state — and nothing in `Providers` caught it, so the
|
|
10
|
+
whole tree unmounted and left a blank page with no message, no retry and
|
|
11
|
+
nothing in the console. A rate limit, a brief API blip or a restart
|
|
12
|
+
mid-deploy all produced the same silent nothing. Reproduced in a browser,
|
|
13
|
+
not deduced.
|
|
14
|
+
|
|
15
|
+
Fixed with a new **`BootstrapError`** boundary wrapping everything. It
|
|
16
|
+
cannot be the existing `ErrorBoundary`: that renders `Errors/Message`,
|
|
17
|
+
which calls `useGetSettings()` itself and `useNavigate` — above the
|
|
18
|
+
settings fetch it would rethrow inside its own fallback. An error screen
|
|
19
|
+
for "nothing loaded" cannot depend on anything having loaded, so this one
|
|
20
|
+
uses no settings, no i18next, no router and no theme — inline styles and
|
|
21
|
+
the static `@lang/errors` map, with a reload button.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- **Queries retry what can plausibly differ, and only that.** `retry: false`
|
|
26
|
+
was wrong in both directions: a single dropped connection or 500 was fatal
|
|
27
|
+
(and on the suspense bootstrap path, fatal meant the whole app), while
|
|
28
|
+
nothing distinguished that from a 401/403/404 — a decided answer that
|
|
29
|
+
repeats identically while spending the rate-limit budget a 429 exists to
|
|
30
|
+
protect. Now 5xx, 408, 425, 429 and network-level failures get two retries
|
|
31
|
+
at 700ms then 1400ms; everything else fails at once, so a real 403 surfaces
|
|
32
|
+
as a real 403 instead of three seconds of spinner.
|
|
33
|
+
|
|
3
34
|
|
|
4
35
|
## 1.29.2
|
|
5
36
|
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { getLanguage } from '../Setup/languages';
|
|
3
|
+
import errors from '@lang/errors';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
children: JSX.Element[] | JSX.Element
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The last thing standing when the app cannot start at all.
|
|
11
|
+
*
|
|
12
|
+
* Ferjolt Ozuni - Date: 2026-08-06
|
|
13
|
+
*
|
|
14
|
+
* `useGetSettings` is a SUSPENSE query, so a failure throws during render
|
|
15
|
+
* rather than resolving to an error state. It sits above everything in
|
|
16
|
+
* Providers, and there was no error boundary over it - so any failure of
|
|
17
|
+
* /api/settings/get unmounted the entire tree and left a **blank white page**
|
|
18
|
+
* with no message, no retry and nothing in the console. A rate limit, a
|
|
19
|
+
* five-second API blip or a restart mid-deploy all produced the same silent
|
|
20
|
+
* nothing. Reproduced in the browser, not deduced.
|
|
21
|
+
*
|
|
22
|
+
* Why this is not @autobusal/providers' own ErrorBoundary: that one renders
|
|
23
|
+
* `Errors/Message`, and Message calls `useGetSettings()` itself - the very
|
|
24
|
+
* query that just failed - plus `useNavigate`, which needs a Router. Putting
|
|
25
|
+
* it above the settings fetch would rethrow inside the fallback. An error
|
|
26
|
+
* screen for "nothing loaded" cannot depend on anything having loaded.
|
|
27
|
+
*
|
|
28
|
+
* So this deliberately uses NO settings, NO i18next, NO router and NO
|
|
29
|
+
* styled-components theme - inline styles and the static `@lang/errors` map,
|
|
30
|
+
* which is a plain object kept for exactly this purpose (it is what the
|
|
31
|
+
* toast and Message already read before i18next is guaranteed to exist).
|
|
32
|
+
*
|
|
33
|
+
* Reload rather than a retry button wired to react-query: whatever failed
|
|
34
|
+
* happened during bootstrap, so there is no reliable app state left to retry
|
|
35
|
+
* *into*. A full reload is the honest recovery, and it is what a visitor
|
|
36
|
+
* would do anyway.
|
|
37
|
+
*/
|
|
38
|
+
class BootstrapError extends React.Component<Props, { failed: boolean }> {
|
|
39
|
+
state = { failed: false };
|
|
40
|
+
|
|
41
|
+
static getDerivedStateFromError() {
|
|
42
|
+
return { failed: true };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
componentDidCatch(error: Error, info: React.ErrorInfo): void {
|
|
46
|
+
// Kept as console.error, not console.log: this is the one place that
|
|
47
|
+
// knows the app failed to start, and a white page with a `log` entry is
|
|
48
|
+
// easy to miss when somebody finally does open the console.
|
|
49
|
+
console.error('[bootstrap] the application could not start', error, info);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
render() {
|
|
53
|
+
if (!this.state.failed) {
|
|
54
|
+
return this.props.children;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Same fallback rule as Message: any language without an entry reads
|
|
58
|
+
// English rather than rendering `undefined`.
|
|
59
|
+
const language = getLanguage('en');
|
|
60
|
+
const copy = errors[language as keyof typeof errors] ?? errors.en;
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<div
|
|
64
|
+
role="alert"
|
|
65
|
+
style={ {
|
|
66
|
+
minHeight: '100vh',
|
|
67
|
+
display: 'flex',
|
|
68
|
+
alignItems: 'center',
|
|
69
|
+
justifyContent: 'center',
|
|
70
|
+
padding: '24px',
|
|
71
|
+
fontFamily: 'system-ui, -apple-system, Segoe UI, Roboto, sans-serif',
|
|
72
|
+
background: '#1c1c1c',
|
|
73
|
+
color: '#f5f5f5'
|
|
74
|
+
} }
|
|
75
|
+
>
|
|
76
|
+
<div style={ { maxWidth: '460px', textAlign: 'center' } }>
|
|
77
|
+
<h1 style={ { fontSize: '20px', lineHeight: 1.4, margin: '0 0 12px' } }>
|
|
78
|
+
{ copy.system }
|
|
79
|
+
</h1>
|
|
80
|
+
|
|
81
|
+
<p style={ { fontSize: '15px', lineHeight: 1.6, margin: '0 0 24px', opacity: 0.8 } }>
|
|
82
|
+
{ copy.system_detail }
|
|
83
|
+
</p>
|
|
84
|
+
|
|
85
|
+
<button
|
|
86
|
+
type="button"
|
|
87
|
+
onClick={ () => window.location.reload() }
|
|
88
|
+
style={ {
|
|
89
|
+
font: 'inherit',
|
|
90
|
+
fontWeight: 600,
|
|
91
|
+
padding: '10px 24px',
|
|
92
|
+
borderRadius: '999px',
|
|
93
|
+
border: 0,
|
|
94
|
+
cursor: 'pointer',
|
|
95
|
+
background: '#f0b323',
|
|
96
|
+
color: '#1c1c1c'
|
|
97
|
+
} }
|
|
98
|
+
>
|
|
99
|
+
{ copy.back }
|
|
100
|
+
</button>
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export default BootstrapError;
|
package/Providers.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Suspense, useEffect } from 'react';
|
|
2
2
|
import Queries from './Queries/Queries';
|
|
3
|
+
import BootstrapError from './Errors/BootstrapError';
|
|
3
4
|
import Styles from './Styles/Styles';
|
|
4
5
|
import Notifications from './Notifications/Notifications';
|
|
5
6
|
import Setup from './Setup/Setup';
|
|
@@ -78,6 +79,17 @@ const Providers = ({ type, loading, children }: Props): JSX.Element => {
|
|
|
78
79
|
// remount it once ready - harmless for Styles/Notifications themselves,
|
|
79
80
|
// but a needless remount of anything stateful sitting there is worth
|
|
80
81
|
// avoiding on principle.
|
|
82
|
+
// Edited: Ferjolt Ozuni - Date: 2026-08-06
|
|
83
|
+
// OUTERMOST, above the settings fetch. useGetSettings is a suspense
|
|
84
|
+
// query, so a failure throws during render rather than resolving to an
|
|
85
|
+
// error state - and with nothing catching it the whole tree unmounted
|
|
86
|
+
// and left a blank white page. A rate limit, a brief API blip or a
|
|
87
|
+
// restart mid-deploy all looked identical: nothing at all.
|
|
88
|
+
//
|
|
89
|
+
// Not providers' own ErrorBoundary, which renders Errors/Message -
|
|
90
|
+
// Message calls useGetSettings() itself and useNavigate, so above this
|
|
91
|
+
// point it would rethrow inside its own fallback. See BootstrapError.
|
|
92
|
+
<BootstrapError>
|
|
81
93
|
<Suspense fallback={ loading }>
|
|
82
94
|
<Queries>
|
|
83
95
|
<Styles>
|
|
@@ -93,6 +105,7 @@ const Providers = ({ type, loading, children }: Props): JSX.Element => {
|
|
|
93
105
|
</Styles>
|
|
94
106
|
</Queries>
|
|
95
107
|
</Suspense>
|
|
108
|
+
</BootstrapError>
|
|
96
109
|
);
|
|
97
110
|
};
|
|
98
111
|
|
package/Queries/Queries.tsx
CHANGED
|
@@ -1,10 +1,56 @@
|
|
|
1
1
|
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { AxiosError } from 'axios';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Edited: Ferjolt Ozuni - Date: 2026-08-06
|
|
6
|
+
*
|
|
7
|
+
* Was `retry: false` for everything, which is wrong in both directions.
|
|
8
|
+
*
|
|
9
|
+
* Too strict: a single blip - a restart mid-deploy, a dropped connection, a
|
|
10
|
+
* 500 - was fatal to any query, and for the SUSPENSE queries on the bootstrap
|
|
11
|
+
* path (settings, menu) fatal meant the whole app. One unlucky request and
|
|
12
|
+
* the visitor got nothing.
|
|
13
|
+
*
|
|
14
|
+
* Too loose: it also said nothing about WHICH failures are worth repeating. A
|
|
15
|
+
* 401, 403 or 404 is a decided answer - the server has considered the request
|
|
16
|
+
* and refused it, and asking again produces the same refusal while spending
|
|
17
|
+
* the rate-limit budget that a 429 exists to protect.
|
|
18
|
+
*
|
|
19
|
+
* So: repeat only what can plausibly differ next time - a 5xx, a timeout, a
|
|
20
|
+
* rate limit, or a network error with no response at all - and back off
|
|
21
|
+
* between attempts so a burst is not answered with more burst. Everything
|
|
22
|
+
* else fails immediately, which is what makes a real 403 surface as a real
|
|
23
|
+
* 403 rather than as three seconds of spinner.
|
|
24
|
+
*/
|
|
25
|
+
const RETRYABLE = [ 408, 425, 429, 500, 502, 503, 504 ];
|
|
26
|
+
|
|
27
|
+
const retry = (failureCount: number, error: Error): boolean => {
|
|
28
|
+
if (failureCount >= 2) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const status = (error as AxiosError)?.response?.status;
|
|
33
|
+
|
|
34
|
+
// No response at all - a dropped connection or a DNS hiccup, not an answer.
|
|
35
|
+
if (status === undefined) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return RETRYABLE.includes(status);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// 700ms, then 1400ms. Deliberately short: these sit behind a suspense
|
|
43
|
+
// fallback the visitor is watching, so the ceiling on "how long may this look
|
|
44
|
+
// broken before it gives up and says so" is about two seconds, not the ~30
|
|
45
|
+
// an unbounded exponential backoff reaches.
|
|
46
|
+
const retryDelay = (attempt: number): number => 700 * 2 ** attempt;
|
|
2
47
|
|
|
3
48
|
const queryClient = new QueryClient({
|
|
4
49
|
defaultOptions: {
|
|
5
50
|
queries: {
|
|
6
51
|
refetchOnWindowFocus: false,
|
|
7
|
-
retry
|
|
52
|
+
retry,
|
|
53
|
+
retryDelay
|
|
8
54
|
}
|
|
9
55
|
}
|
|
10
56
|
});
|
|
@@ -19,4 +65,4 @@ const Queries = ({ children }: Props): JSX.Element => (
|
|
|
19
65
|
</QueryClientProvider>
|
|
20
66
|
);
|
|
21
67
|
|
|
22
|
-
export default Queries;
|
|
68
|
+
export default Queries;
|