Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/web/app/(builder)/lib/core/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ function syncFieldValues(

// Array: always preserve rows
if (field.type === "array") {
if (currentVal !== undefined) {
if (Array.isArray(currentVal)) {
result[name] = currentVal;
} else if (defaultVal !== undefined) {
} else if (Array.isArray(defaultVal)) {
result[name] = defaultVal;
} else {
result[name] = [];
Expand Down
10 changes: 10 additions & 0 deletions apps/web/app/(builder)/lib/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ export function extractDefaults(fields: Field[]): Record<string, unknown> {
const defaults: Record<string, unknown> = {};
for (const field of fields) {
if ("name" in field && field.name) {
// Array values must always be arrays at runtime.
if (field.type === "array") {
const explicitDefault = (field as unknown as Record<string, unknown>)
.defaultValue;
defaults[field.name] = Array.isArray(explicitDefault)
? deepClone(explicitDefault)
: [];
continue;
}

if ("defaultValue" in field) {
// Deep clone to avoid frozen object references from Zustand/immer
defaults[field.name] = deepClone(
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/(builder)/lib/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const builderFieldRegistry: BuilderFieldRegistry = {
icon: CheckmarkSquare02Icon,
category: "selection",
},
defaultProps: { type: "checkbox", label: "Checkbox" },
defaultProps: { type: "checkbox", label: "Checkbox", defaultValue: false },
properties: checkboxFieldProperties,
},
"checkbox-group": {
Expand Down
Loading