Skip to content

Commit 1be3b75

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/dev' into stable
2 parents 65e6e86 + a9313d6 commit 1be3b75

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

packages/app-admin/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ export { AaclPermission } from "@webiny/app-wcp/types";
6262
export { useTheme, ThemeProvider } from "@webiny/app-theme";
6363

6464
export * from "@webiny/app/renderApp";
65+
66+
// Exporting chosen utils from `@webiny/app` package.
67+
export * from "@webiny/app/utils/getApiUrl";
68+
export * from "@webiny/app/utils/getGqlApiUrl";
69+
export * from "@webiny/app/utils/getHeadlessCmsGqlApiUrl";
70+
export * from "@webiny/app/utils/getLocaleCode";
71+
export * from "@webiny/app/utils/getTenantId";
72+
export * from "@webiny/app/utils/isLocalhost";

packages/app-page-builder-elements/src/hooks/useLoader.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ import { useEffect, useMemo, useState, type DependencyList } from "react";
22
import { createObjectHash } from "./useLoader/createObjectHash";
33
import { useRenderer } from "..";
44

5-
export interface RendererLoader<TData = unknown> {
5+
export interface RendererLoader<TData = unknown, TError = unknown> {
66
data: TData | null;
77
loading: boolean;
88
cacheHit: boolean;
99
cacheKey: null | string;
10+
error: null | TError;
1011
}
1112

1213
export interface UseLoaderOptions {
1314
cacheKey?: DependencyList;
1415
}
1516

16-
export function useLoader<TData = unknown>(
17+
export function useLoader<TData = unknown, TError = unknown>(
1718
loaderFn: () => Promise<TData>,
1819
options?: UseLoaderOptions
19-
): RendererLoader<TData> {
20+
): RendererLoader<TData, TError> {
2021
const { getElement, loaderCache } = useRenderer();
2122

2223
const element = getElement();
@@ -29,15 +30,16 @@ export function useLoader<TData = unknown>(
2930
return loaderCache.read<TData>(cacheKey);
3031
}, [cacheKey]);
3132

32-
const [loader, setLoader] = useState<RendererLoader<TData>>(
33+
const [loader, setLoader] = useState<RendererLoader<TData, TError>>(
3334
cachedData
3435
? {
3536
data: cachedData,
3637
loading: false,
3738
cacheHit: true,
38-
cacheKey
39+
cacheKey,
40+
error: null
3941
}
40-
: { data: null, loading: true, cacheHit: false, cacheKey: null }
42+
: { data: null, loading: true, cacheHit: false, cacheKey: null, error: null }
4143
);
4244

4345
useEffect(() => {
@@ -46,15 +48,25 @@ export function useLoader<TData = unknown>(
4648
}
4749

4850
if (cachedData) {
49-
setLoader({ data: cachedData, loading: false, cacheKey, cacheHit: true });
51+
setLoader({ data: cachedData, loading: false, cacheKey, cacheHit: true, error: null });
5052
return;
5153
}
5254

53-
setLoader({ data: loader.data, loading: true, cacheKey, cacheHit: false });
54-
loaderFn().then(data => {
55-
loaderCache.write(cacheKey, data);
56-
setLoader({ data, loading: false, cacheKey, cacheHit: false });
55+
setLoader({
56+
data: loader.data,
57+
error: loader.error,
58+
loading: true,
59+
cacheKey,
60+
cacheHit: false
5761
});
62+
loaderFn()
63+
.then(data => {
64+
loaderCache.write(cacheKey, data);
65+
setLoader({ data, error: null, loading: false, cacheKey, cacheHit: false });
66+
})
67+
.catch(error => {
68+
setLoader({ data: null, error, loading: false, cacheKey, cacheHit: false });
69+
});
5870
}, [cacheKey]);
5971

6072
return loader;

packages/cli-plugin-extensions/templates/pbElement/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
{
22
"name": "PACKAGE_NAME",
3-
"exports": {
4-
"./admin": "./src/admin.tsx",
5-
"./website": "./src/website.tsx"
6-
},
73
"version": "1.0.0",
84
"keywords": [
95
"webiny-extension",

0 commit comments

Comments
 (0)