@fragmentsx/render-react 1.5.2 → 1.5.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/dist/index.cjs.js CHANGED
@@ -3314,12 +3314,30 @@ const IDLE_STATE = {
3314
3314
  fetching: false,
3315
3315
  error: null
3316
3316
  };
3317
+ const resolveStateFromCache = (globalManager, areaCode, skip) => {
3318
+ if (skip || !globalManager || !areaCode) return IDLE_STATE;
3319
+ const cache = getSuspenseCache(globalManager);
3320
+ const cacheKey = `area:${areaCode}`;
3321
+ if (cache.has(cacheKey)) {
3322
+ try {
3323
+ const cached = cache.get(cacheKey).read();
3324
+ return { data: cached, fetching: false, error: null };
3325
+ } catch (e) {
3326
+ if (!(e instanceof Promise)) {
3327
+ return { data: null, fetching: false, error: e };
3328
+ }
3329
+ }
3330
+ }
3331
+ return { data: null, fetching: true, error: null };
3332
+ };
3317
3333
  const useAsyncLoadArea = (globalManager, areaCode, skip) => {
3318
- const [state, setState] = react.useState(IDLE_STATE);
3334
+ const [state, setState] = react.useState(
3335
+ () => resolveStateFromCache(globalManager, areaCode, skip)
3336
+ );
3319
3337
  const areaCodeRef = react.useRef(areaCode);
3320
3338
  if (areaCodeRef.current !== areaCode) {
3321
3339
  areaCodeRef.current = areaCode;
3322
- setState(IDLE_STATE);
3340
+ setState(resolveStateFromCache(globalManager, areaCode, skip));
3323
3341
  }
3324
3342
  react.useEffect(() => {
3325
3343
  var _a, _b;
@@ -3341,7 +3359,11 @@ const useAsyncLoadArea = (globalManager, areaCode, skip) => {
3341
3359
  const valueOrPromise = cache.has(cacheKey) ? void 0 : (_b = (_a = globalManager.$load) == null ? void 0 : _a.loadArea) == null ? void 0 : _b.call(_a, areaCode);
3342
3360
  if (valueOrPromise != null && !(valueOrPromise instanceof Promise)) {
3343
3361
  createSuspenseResource(cacheKey, valueOrPromise, cache);
3344
- setState({ data: valueOrPromise, fetching: false, error: null });
3362
+ setState({
3363
+ data: valueOrPromise,
3364
+ fetching: false,
3365
+ error: null
3366
+ });
3345
3367
  return;
3346
3368
  }
3347
3369
  if (valueOrPromise instanceof Promise) {
package/dist/index.es.js CHANGED
@@ -3312,12 +3312,30 @@ const IDLE_STATE = {
3312
3312
  fetching: false,
3313
3313
  error: null
3314
3314
  };
3315
+ const resolveStateFromCache = (globalManager, areaCode, skip) => {
3316
+ if (skip || !globalManager || !areaCode) return IDLE_STATE;
3317
+ const cache = getSuspenseCache(globalManager);
3318
+ const cacheKey = `area:${areaCode}`;
3319
+ if (cache.has(cacheKey)) {
3320
+ try {
3321
+ const cached = cache.get(cacheKey).read();
3322
+ return { data: cached, fetching: false, error: null };
3323
+ } catch (e) {
3324
+ if (!(e instanceof Promise)) {
3325
+ return { data: null, fetching: false, error: e };
3326
+ }
3327
+ }
3328
+ }
3329
+ return { data: null, fetching: true, error: null };
3330
+ };
3315
3331
  const useAsyncLoadArea = (globalManager, areaCode, skip) => {
3316
- const [state, setState] = useState(IDLE_STATE);
3332
+ const [state, setState] = useState(
3333
+ () => resolveStateFromCache(globalManager, areaCode, skip)
3334
+ );
3317
3335
  const areaCodeRef = useRef(areaCode);
3318
3336
  if (areaCodeRef.current !== areaCode) {
3319
3337
  areaCodeRef.current = areaCode;
3320
- setState(IDLE_STATE);
3338
+ setState(resolveStateFromCache(globalManager, areaCode, skip));
3321
3339
  }
3322
3340
  useEffect(() => {
3323
3341
  var _a, _b;
@@ -3339,7 +3357,11 @@ const useAsyncLoadArea = (globalManager, areaCode, skip) => {
3339
3357
  const valueOrPromise = cache.has(cacheKey) ? void 0 : (_b = (_a = globalManager.$load) == null ? void 0 : _a.loadArea) == null ? void 0 : _b.call(_a, areaCode);
3340
3358
  if (valueOrPromise != null && !(valueOrPromise instanceof Promise)) {
3341
3359
  createSuspenseResource(cacheKey, valueOrPromise, cache);
3342
- setState({ data: valueOrPromise, fetching: false, error: null });
3360
+ setState({
3361
+ data: valueOrPromise,
3362
+ fetching: false,
3363
+ error: null
3364
+ });
3343
3365
  return;
3344
3366
  }
3345
3367
  if (valueOrPromise instanceof Promise) {
@@ -1 +1 @@
1
- {"version":3,"file":"useAsyncLoadArea.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Area/hooks/useAsyncLoadArea.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAK/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,UAAU,cAAc;IACtB,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;CAChB;AAQD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,kBACZ,UAAU,GAAG,IAAI,GAAG,SAAS,YAClC,MAAM,QACV,OAAO,KACZ,cAuFF,CAAC"}
1
+ {"version":3,"file":"useAsyncLoadArea.d.ts","sourceRoot":"","sources":["../../../../src/nodes/Area/hooks/useAsyncLoadArea.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,UAAU,cAAc;IACtB,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;CAChB;AAqCD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,kBACZ,UAAU,GAAG,IAAI,GAAG,SAAS,YAClC,MAAM,QACV,OAAO,KACZ,cA6FF,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fragmentsx/render-react",
3
3
  "private": false,
4
- "version": "1.5.2",
4
+ "version": "1.5.3",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"