@openg2p/registry-widgets 1.1.0-dev.11 → 1.1.0-dev.12

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.js CHANGED
@@ -5197,6 +5197,11 @@ const SectionsContainer = ({ sections, dataSourceRequestHandler: propDataSourceR
5197
5197
  // Stable ref for namespace so formHandle useMemo doesn't depend on the (possibly inline) function identity
5198
5198
  const namespaceRef = React.useRef(namespace);
5199
5199
  namespaceRef.current = namespace;
5200
+ // Stable ref for sections so formHandle useMemo doesn't depend on the (possibly unstable) array reference.
5201
+ // Without this, an inline sections={[...]} prop would recreate formHandle every render, causing
5202
+ // onFormReady to fire every render → host setState → infinite re-render loop.
5203
+ const safeSectionsRef = React.useRef(safeSections);
5204
+ safeSectionsRef.current = safeSections;
5200
5205
  // Stable refs so formHandle closure can access current mode and accordion setter without stale captures
5201
5206
  const modeRef = React.useRef(mode);
5202
5207
  modeRef.current = mode;
@@ -5245,6 +5250,9 @@ const SectionsContainer = ({ sections, dataSourceRequestHandler: propDataSourceR
5245
5250
  }, [mode, safeSections.length, expandedSectionIndex]);
5246
5251
  const UNSAVED_CHANGES_ERROR = 'Unsaved changes detected. Please save all sections before submitting.';
5247
5252
  // Form handle for onFormReady - allows host to validate and get all section data from its own Submit button
5253
+ // IMPORTANT: safeSections is intentionally accessed via safeSectionsRef.current (not closed over directly)
5254
+ // so that this memo never depends on the sections array reference. This prevents an infinite re-render
5255
+ // loop when the host passes an unstable sections prop (e.g. inline array or derived state).
5248
5256
  const formHandle = React.useMemo(() => {
5249
5257
  const getValues = () => store.getState().widget?.values || {};
5250
5258
  const getNamespace = (section, index) => {
@@ -5266,10 +5274,11 @@ const SectionsContainer = ({ sections, dataSourceRequestHandler: propDataSourceR
5266
5274
  if (modeRef.current !== 'IntakeForm')
5267
5275
  checkNoUnsavedChanges();
5268
5276
  const values = getValues();
5277
+ const sections = safeSectionsRef.current;
5269
5278
  let allValid = true;
5270
5279
  let firstInvalidIndex = null;
5271
- for (let i = 0; i < safeSections.length; i++) {
5272
- const section = safeSections[i];
5280
+ for (let i = 0; i < sections.length; i++) {
5281
+ const section = sections[i];
5273
5282
  const ns = getNamespace(section, i);
5274
5283
  const sectionToValidate = ns ? namespaceSectionConfig(section, ns) : section;
5275
5284
  const valid = sectionValidate(sectionToValidate, values, dispatch);
@@ -5289,10 +5298,11 @@ const SectionsContainer = ({ sections, dataSourceRequestHandler: propDataSourceR
5289
5298
  if (modeRef.current !== 'IntakeForm')
5290
5299
  checkNoUnsavedChanges();
5291
5300
  const values = getValues();
5301
+ const sections = safeSectionsRef.current;
5292
5302
  const results = [];
5293
5303
  let firstInvalidIndex = null;
5294
- for (let i = 0; i < safeSections.length; i++) {
5295
- const section = safeSections[i];
5304
+ for (let i = 0; i < sections.length; i++) {
5305
+ const section = sections[i];
5296
5306
  const ns = getNamespace(section, i);
5297
5307
  const sectionToValidate = ns ? namespaceSectionConfig(section, ns) : section;
5298
5308
  const valid = sectionValidate(sectionToValidate, values, dispatch);
@@ -5314,16 +5324,18 @@ const SectionsContainer = ({ sections, dataSourceRequestHandler: propDataSourceR
5314
5324
  },
5315
5325
  getStructuredData: () => {
5316
5326
  const values = getValues();
5327
+ const sections = safeSectionsRef.current;
5317
5328
  const results = [];
5318
- for (let i = 0; i < safeSections.length; i++) {
5319
- const section = safeSections[i];
5329
+ for (let i = 0; i < sections.length; i++) {
5330
+ const section = sections[i];
5320
5331
  const ns = getNamespace(section, i);
5321
5332
  results.push(buildSectionChanges(section, values, ns));
5322
5333
  }
5323
5334
  return results;
5324
5335
  },
5325
5336
  };
5326
- }, [store, dispatch, safeSections]);
5337
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5338
+ }, [store, dispatch]); // safeSections intentionally omitted — accessed via safeSectionsRef
5327
5339
  // Call onFormReady when form is ready (sections loaded)
5328
5340
  React.useEffect(() => {
5329
5341
  if (onFormReady && safeSections.length > 0) {