Skip to content

Commit d628cbd

Browse files
Code cleanup and PR feedback
1 parent 626c244 commit d628cbd

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/connect-react/src/components/ControlSelect.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ export function ControlSelect<T extends PropOptionValue>({
9595
// Extract the actual option from __lv wrapper and sanitize to LV
9696
// Handle both single objects and arrays wrapped in __lv
9797
const lvContent = (rawValue as Record<string, unknown>).__lv;
98+
if (!lvContent) {
99+
console.warn("Invalid __lv content:", rawValue);
100+
return null;
101+
}
98102
if (Array.isArray(lvContent)) {
99103
return lvContent.map((item) => sanitizeOption(item as T));
100104
}

packages/connect-react/src/hooks/form-context.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export const FormContextProvider = <T extends ConfigurableProps>({
282282
const propsToEnable: Record<string, boolean> = {};
283283

284284
for (const prop of configurableProps) {
285-
if (prop.optional) {
285+
if (prop.optional && !enabledOptionalProps[prop.name]) {
286286
const value = configuredProps[prop.name as keyof ConfiguredProps<T>];
287287
if (value !== undefined) {
288288
propsToEnable[prop.name] = true;
@@ -300,6 +300,7 @@ export const FormContextProvider = <T extends ConfigurableProps>({
300300
component.key,
301301
configurableProps,
302302
configuredProps,
303+
enabledOptionalProps,
303304
]);
304305

305306
// these validations are necessary because they might override PropInput for number case for instance
@@ -388,6 +389,8 @@ export const FormContextProvider = <T extends ConfigurableProps>({
388389
updateConfiguredPropsQueryDisabledIdx(configuredProps)
389390
}, [
390391
component.key,
392+
configurableProps,
393+
enabledOptionalProps,
391394
]);
392395

393396
// Update queryDisabledIdx reactively when configuredProps changes.
@@ -397,6 +400,8 @@ export const FormContextProvider = <T extends ConfigurableProps>({
397400
updateConfiguredPropsQueryDisabledIdx(configuredProps);
398401
}, [
399402
configuredProps,
403+
configurableProps,
404+
enabledOptionalProps,
400405
]);
401406

402407
useEffect(() => {
@@ -442,6 +447,9 @@ export const FormContextProvider = <T extends ConfigurableProps>({
442447
// Preserve label-value format from remote options dropdowns
443448
// Remote options store values as {__lv: {label: "...", value: ...}}
444449
// For multi-select fields, this will be an array of __lv objects
450+
// IMPORTANT: Integer props with remote options (like IDs) can be stored in __lv format
451+
// to preserve the display label. We only delete the value if it's NOT in __lv format
452+
// AND not a number, which indicates invalid/corrupted data.
445453
const isLabelValue = value && typeof value === "object" && "__lv" in value;
446454
const isArrayOfLabelValues = Array.isArray(value) && value.length > 0 &&
447455
value.every((item) => item && typeof item === "object" && "__lv" in item);
@@ -461,6 +469,8 @@ export const FormContextProvider = <T extends ConfigurableProps>({
461469
}
462470
}, [
463471
configurableProps,
472+
enabledOptionalProps,
473+
configuredProps,
464474
]);
465475

466476
// clear all props on user change

0 commit comments

Comments
 (0)