mirror of
https://github.com/docmost/docmost.git
synced 2026-05-18 15:34:05 +08:00
fix(base): stop jsonb char-key corruption in seed and guard view config spread
This commit is contained in:
@@ -181,6 +181,12 @@ export function buildViewConfigFromTable(
|
|||||||
base: ViewConfig | undefined,
|
base: ViewConfig | undefined,
|
||||||
overrides: Partial<ViewConfig> = {},
|
overrides: Partial<ViewConfig> = {},
|
||||||
): ViewConfig {
|
): ViewConfig {
|
||||||
|
// Guard against corrupted persisted configs — if `base` ever comes
|
||||||
|
// back as something other than a plain object (e.g. a jsonb-stored
|
||||||
|
// string `"{}"` from a buggy seed), spreading it would iterate its
|
||||||
|
// characters into keys `0`, `1`, … and poison the config forever.
|
||||||
|
const safeBase =
|
||||||
|
base && typeof base === "object" && !Array.isArray(base) ? base : {};
|
||||||
const state = table.getState();
|
const state = table.getState();
|
||||||
|
|
||||||
const sorts = state.sorting.map((s) => ({
|
const sorts = state.sorting.map((s) => ({
|
||||||
@@ -200,7 +206,7 @@ export function buildViewConfigFromTable(
|
|||||||
.map(([id]) => id);
|
.map(([id]) => id);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...base,
|
...safeBase,
|
||||||
sorts,
|
sorts,
|
||||||
propertyWidths,
|
propertyWidths,
|
||||||
propertyOrder,
|
propertyOrder,
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ async function createBase(workspaceId: string, spaceId: string, creatorId: strin
|
|||||||
name: def.name,
|
name: def.name,
|
||||||
type: def.type,
|
type: def.type,
|
||||||
position: propPosition,
|
position: propPosition,
|
||||||
type_options: def.typeOptions ? JSON.stringify(def.typeOptions) : null,
|
type_options: def.typeOptions ?? null,
|
||||||
is_primary: def.isPrimary ?? false,
|
is_primary: def.isPrimary ?? false,
|
||||||
workspace_id: workspaceId,
|
workspace_id: workspaceId,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
@@ -219,7 +219,7 @@ async function createBase(workspaceId: string, spaceId: string, creatorId: strin
|
|||||||
name: 'Table View 1',
|
name: 'Table View 1',
|
||||||
type: 'table',
|
type: 'table',
|
||||||
position: generateJitteredKeyBetween(null, null),
|
position: generateJitteredKeyBetween(null, null),
|
||||||
config: JSON.stringify({}),
|
config: {},
|
||||||
workspace_id: workspaceId,
|
workspace_id: workspaceId,
|
||||||
creator_id: creatorId,
|
creator_id: creatorId,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
|
|||||||
Reference in New Issue
Block a user