@openmrs/esm-react-utils 6.3.1-pre.3058 → 6.3.1-pre.3063

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.
@@ -1,3 +1,3 @@
1
- [0] Successfully compiled: 52 files with swc (162.59ms)
1
+ [0] Successfully compiled: 52 files with swc (133.08ms)
2
2
  [0] swc --strip-leading-paths src -d dist exited with code 0
3
3
  [1] tsc --project tsconfig.build.json exited with code 0
@@ -21,6 +21,7 @@ const defaultOpts = {
21
21
  throwErrorsToConsole: true,
22
22
  disableTranslations: false
23
23
  };
24
+ const swrCache = new Map();
24
25
  // Read more about the available config options here: https://swr.vercel.app/docs/api#configuration
25
26
  const defaultSwrConfig = {
26
27
  // max number of retries after requests have failed
@@ -33,13 +34,18 @@ const defaultSwrConfig = {
33
34
  // disable automatic revalidations by default
34
35
  revalidateOnFocus: false,
35
36
  revalidateOnReconnect: false,
36
- refreshInterval: 0
37
+ refreshInterval: 0,
38
+ provider: ()=>swrCache
37
39
  };
38
40
  export function openmrsComponentDecorator(userOpts) {
39
41
  if (typeof userOpts !== 'object' || typeof userOpts.featureName !== 'string' || typeof userOpts.moduleName !== 'string') {
40
42
  throw new Error('Invalid options');
41
43
  }
42
44
  const opts = Object.assign({}, defaultOpts, userOpts);
45
+ const swrConfig = {
46
+ ...defaultSwrConfig,
47
+ ...opts.swrConfig
48
+ };
43
49
  return function decorateComponent(Comp) {
44
50
  var _React_Component, _OpenmrsReactComponent;
45
51
  return _OpenmrsReactComponent = class OpenmrsReactComponent extends (_React_Component = React.Component) {
@@ -64,10 +70,6 @@ export function openmrsComponentDecorator(userOpts) {
64
70
  // TO-DO have a UX designed for when a catastrophic error occurs
65
71
  return /*#__PURE__*/ React.createElement("div", null, "An error has occurred. Please try reloading the page.");
66
72
  } else {
67
- const swrConfig = {
68
- ...defaultSwrConfig,
69
- ...opts.swrConfig
70
- };
71
73
  const content = /*#__PURE__*/ React.createElement(Suspense, {
72
74
  fallback: null
73
75
  }, /*#__PURE__*/ React.createElement(SWRConfig, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-react-utils",
3
- "version": "6.3.1-pre.3058",
3
+ "version": "6.3.1-pre.3063",
4
4
  "license": "MPL-2.0",
5
5
  "description": "React utilities for OpenMRS.",
6
6
  "type": "module",
@@ -78,17 +78,17 @@
78
78
  "swr": "2.x"
79
79
  },
80
80
  "devDependencies": {
81
- "@openmrs/esm-api": "6.3.1-pre.3058",
82
- "@openmrs/esm-config": "6.3.1-pre.3058",
83
- "@openmrs/esm-context": "6.3.1-pre.3058",
84
- "@openmrs/esm-emr-api": "6.3.1-pre.3058",
85
- "@openmrs/esm-error-handling": "6.3.1-pre.3058",
86
- "@openmrs/esm-extensions": "6.3.1-pre.3058",
87
- "@openmrs/esm-feature-flags": "6.3.1-pre.3058",
88
- "@openmrs/esm-globals": "6.3.1-pre.3058",
89
- "@openmrs/esm-navigation": "6.3.1-pre.3058",
90
- "@openmrs/esm-state": "6.3.1-pre.3058",
91
- "@openmrs/esm-utils": "6.3.1-pre.3058",
81
+ "@openmrs/esm-api": "6.3.1-pre.3063",
82
+ "@openmrs/esm-config": "6.3.1-pre.3063",
83
+ "@openmrs/esm-context": "6.3.1-pre.3063",
84
+ "@openmrs/esm-emr-api": "6.3.1-pre.3063",
85
+ "@openmrs/esm-error-handling": "6.3.1-pre.3063",
86
+ "@openmrs/esm-extensions": "6.3.1-pre.3063",
87
+ "@openmrs/esm-feature-flags": "6.3.1-pre.3063",
88
+ "@openmrs/esm-globals": "6.3.1-pre.3063",
89
+ "@openmrs/esm-navigation": "6.3.1-pre.3063",
90
+ "@openmrs/esm-state": "6.3.1-pre.3063",
91
+ "@openmrs/esm-utils": "6.3.1-pre.3063",
92
92
  "@swc/cli": "^0.7.7",
93
93
  "@swc/core": "^1.11.29",
94
94
  "concurrently": "^9.1.2",
@@ -1,6 +1,6 @@
1
1
  import React, { type ComponentType, type ErrorInfo, Suspense } from 'react';
2
2
  import { I18nextProvider } from 'react-i18next';
3
- import { SWRConfig, type SWRConfiguration } from 'swr';
3
+ import { type Cache, SWRConfig, type SWRConfiguration } from 'swr';
4
4
  import type {} from '@openmrs/esm-globals';
5
5
  import { openmrsFetch } from '@openmrs/esm-api';
6
6
  import { type ComponentConfig, type ExtensionData } from '@openmrs/esm-extensions';
@@ -12,8 +12,10 @@ const defaultOpts = {
12
12
  disableTranslations: false,
13
13
  };
14
14
 
15
+ const swrCache: Cache = new Map();
16
+
15
17
  // Read more about the available config options here: https://swr.vercel.app/docs/api#configuration
16
- const defaultSwrConfig = {
18
+ const defaultSwrConfig: SWRConfiguration = {
17
19
  // max number of retries after requests have failed
18
20
  errorRetryCount: 3,
19
21
  // default fetcher function
@@ -25,6 +27,7 @@ const defaultSwrConfig = {
25
27
  revalidateOnFocus: false,
26
28
  revalidateOnReconnect: false,
27
29
  refreshInterval: 0,
30
+ provider: () => swrCache,
28
31
  };
29
32
 
30
33
  export interface ComponentDecoratorOptions {
@@ -55,6 +58,7 @@ export function openmrsComponentDecorator<T>(userOpts: ComponentDecoratorOptions
55
58
  }
56
59
 
57
60
  const opts = Object.assign({}, defaultOpts, userOpts);
61
+ const swrConfig = { ...defaultSwrConfig, ...opts.swrConfig };
58
62
 
59
63
  return function decorateComponent(Comp: ComponentType<T>): ComponentType<T> {
60
64
  return class OpenmrsReactComponent extends React.Component<
@@ -100,7 +104,6 @@ export function openmrsComponentDecorator<T>(userOpts: ComponentDecoratorOptions
100
104
  // TO-DO have a UX designed for when a catastrophic error occurs
101
105
  return <div>An error has occurred. Please try reloading the page.</div>;
102
106
  } else {
103
- const swrConfig = { ...defaultSwrConfig, ...opts.swrConfig };
104
107
  const content = (
105
108
  <Suspense fallback={null}>
106
109
  <SWRConfig value={swrConfig}>