@edx/frontend-plugin-learner-dashboard 3.3.4 → 3.3.5
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.
|
@@ -50,20 +50,25 @@ const DynamicExperienceSlot = _ref => {
|
|
|
50
50
|
const UCL = useUCL();
|
|
51
51
|
const [shouldThrow, setShouldThrow] = (0, _react.useState)(false);
|
|
52
52
|
const [error, setError] = (0, _react.useState)(null);
|
|
53
|
+
|
|
54
|
+
// Lock props to prevent unnecessary re-renders
|
|
55
|
+
const restPropsRef = (0, _react.useRef)(rest);
|
|
56
|
+
// Update ref on each render to prevent stale props
|
|
57
|
+
restPropsRef.current = rest;
|
|
53
58
|
(0, _react.useEffect)(() => {
|
|
54
59
|
const refCurrent = ref.current;
|
|
55
60
|
if (!refCurrent || !UCL) {
|
|
56
61
|
return undefined;
|
|
57
62
|
}
|
|
58
63
|
try {
|
|
59
|
-
UCL.mount(widgetName, refCurrent, _objectSpread(_objectSpread({},
|
|
64
|
+
UCL.mount(widgetName, refCurrent, _objectSpread(_objectSpread({}, restPropsRef.current), {}, {
|
|
60
65
|
onFallbackShouldRender: setShouldThrow
|
|
61
66
|
}));
|
|
62
67
|
} catch (e) {
|
|
63
68
|
setError(e);
|
|
64
69
|
}
|
|
65
70
|
return () => UCL.unmount(refCurrent);
|
|
66
|
-
}, [widgetName, UCL
|
|
71
|
+
}, [widgetName, UCL]);
|
|
67
72
|
if (error) {
|
|
68
73
|
throw error;
|
|
69
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicExperienceSlot.js","names":["_react","require","_propTypes","_interopRequireDefault","_jsxRuntime","_excluded","e","__esModule","default","ownKeys","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","_objectWithoutProperties","_objectWithoutPropertiesLoose","n","indexOf","propertyIsEnumerable","hasOwnProperty","useUCL","timeout","ucl","setUcl","useState","window","UCL","useEffect","undefined","start","Date","now","id","setInterval","clearInterval","RenderFallbackSignal","Error","constructor","name","DynamicExperienceSlot","_ref","widgetName","rest","ref","useRef","shouldThrow","setShouldThrow","error","setError","
|
|
1
|
+
{"version":3,"file":"DynamicExperienceSlot.js","names":["_react","require","_propTypes","_interopRequireDefault","_jsxRuntime","_excluded","e","__esModule","default","ownKeys","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","_objectWithoutProperties","_objectWithoutPropertiesLoose","n","indexOf","propertyIsEnumerable","hasOwnProperty","useUCL","timeout","ucl","setUcl","useState","window","UCL","useEffect","undefined","start","Date","now","id","setInterval","clearInterval","RenderFallbackSignal","Error","constructor","name","DynamicExperienceSlot","_ref","widgetName","rest","ref","useRef","shouldThrow","setShouldThrow","error","setError","restPropsRef","current","refCurrent","mount","onFallbackShouldRender","unmount","jsx","propTypes","PropTypes","string","isRequired","_default","exports"],"sources":["../../src/dynamic-experience-slot/DynamicExperienceSlot.jsx"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\nimport PropTypes from 'prop-types';\n\nfunction useUCL(timeout = 5000) {\n const [ucl, setUcl] = useState(() => window.UCL);\n useEffect(() => {\n if (ucl) { return undefined; }\n const start = Date.now();\n const id = setInterval(() => {\n if (window.UCL) {\n setUcl(window.UCL);\n clearInterval(id);\n } else if (Date.now() - start > timeout) {\n clearInterval(id);\n }\n }, 100);\n return () => clearInterval(id);\n }, [ucl, timeout]);\n return ucl;\n}\nclass RenderFallbackSignal extends Error {\n constructor() {\n super('Render fallback requested by widget');\n this.name = 'RenderFallbackSignal';\n }\n}\n\nconst DynamicExperienceSlot = ({ widgetName, ...rest }) => {\n const ref = useRef(null);\n const UCL = useUCL();\n const [shouldThrow, setShouldThrow] = useState(false);\n const [error, setError] = useState(null);\n\n // Lock props to prevent unnecessary re-renders\n const restPropsRef = useRef(rest);\n // Update ref on each render to prevent stale props\n restPropsRef.current = rest;\n\n useEffect(() => {\n const refCurrent = ref.current;\n if (!refCurrent || !UCL) { return undefined; }\n try {\n UCL.mount(widgetName, refCurrent, {\n ...restPropsRef.current,\n onFallbackShouldRender: setShouldThrow,\n });\n } catch (e) {\n setError(e);\n }\n return () => UCL.unmount(refCurrent);\n }, [widgetName, UCL]);\n if (error) { throw error; }\n if (shouldThrow) { throw new RenderFallbackSignal(); }\n return <div ref={ref} />;\n};\n\nDynamicExperienceSlot.propTypes = {\n widgetName: PropTypes.string.isRequired,\n};\n\nexport default DynamicExperienceSlot;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAmC,IAAAG,WAAA,GAAAH,OAAA;AAAA,MAAAI,SAAA;AAAA,SAAAF,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,QAAAH,CAAA,EAAAI,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAP,CAAA,OAAAM,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAR,CAAA,GAAAI,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAX,CAAA,EAAAI,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAf,CAAA,aAAAI,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EAAAzD,aAAA,CAAAA,aAAA,KAC3BuD,YAAY,CAACC,OAAO;QACvBG,sBAAsB,EAAEP;MAAc,EACvC,CAAC;IACJ,CAAC,CAAC,OAAOnE,CAAC,EAAE;MACVqE,QAAQ,CAACrE,CAAC,CAAC;IACb;IACA,OAAO,MAAM+C,GAAG,CAAC4B,OAAO,CAACH,UAAU,CAAC;EACtC,CAAC,EAAE,CAACV,UAAU,EAAEf,GAAG,CAAC,CAAC;EACrB,IAAIqB,KAAK,EAAE;IAAE,MAAMA,KAAK;EAAE;EAC1B,IAAIF,WAAW,EAAE;IAAE,MAAM,IAAIV,oBAAoB,CAAC,CAAC;EAAE;EACrD,oBAAO,IAAA1D,WAAA,CAAA8E,GAAA;IAAKZ,GAAG,EAAEA;EAAI,CAAE,CAAC;AAC1B,CAAC;AAEDJ,qBAAqB,CAACiB,SAAS,GAAG;EAChCf,UAAU,EAAEgB,kBAAS,CAACC,MAAM,CAACC;AAC/B,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAhF,OAAA,GAEa0D,qBAAqB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -24,24 +24,31 @@ class RenderFallbackSignal extends Error {
|
|
|
24
24
|
this.name = 'RenderFallbackSignal';
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
|
|
27
28
|
const DynamicExperienceSlot = ({ widgetName, ...rest }) => {
|
|
28
29
|
const ref = useRef(null);
|
|
29
30
|
const UCL = useUCL();
|
|
30
31
|
const [shouldThrow, setShouldThrow] = useState(false);
|
|
31
32
|
const [error, setError] = useState(null);
|
|
33
|
+
|
|
34
|
+
// Lock props to prevent unnecessary re-renders
|
|
35
|
+
const restPropsRef = useRef(rest);
|
|
36
|
+
// Update ref on each render to prevent stale props
|
|
37
|
+
restPropsRef.current = rest;
|
|
38
|
+
|
|
32
39
|
useEffect(() => {
|
|
33
40
|
const refCurrent = ref.current;
|
|
34
41
|
if (!refCurrent || !UCL) { return undefined; }
|
|
35
42
|
try {
|
|
36
43
|
UCL.mount(widgetName, refCurrent, {
|
|
37
|
-
...
|
|
44
|
+
...restPropsRef.current,
|
|
38
45
|
onFallbackShouldRender: setShouldThrow,
|
|
39
46
|
});
|
|
40
47
|
} catch (e) {
|
|
41
48
|
setError(e);
|
|
42
49
|
}
|
|
43
50
|
return () => UCL.unmount(refCurrent);
|
|
44
|
-
}, [widgetName, UCL
|
|
51
|
+
}, [widgetName, UCL]);
|
|
45
52
|
if (error) { throw error; }
|
|
46
53
|
if (shouldThrow) { throw new RenderFallbackSignal(); }
|
|
47
54
|
return <div ref={ref} />;
|