fix(core): 자동바인딩 키입력이 편집기 본문을 서버 원본으로 되돌리던 문제

자동바인딩은 키입력마다 __g7PendingLocalState 에 저장소 A 기반 전체 스냅샷을
대입해 왔다. 그 base(parentFormContext.state)는 extendedDataContext useMemo 의
결과라, selfManaged 플러그인이 저장소 B 에만 쓴 뒤 memo 가 재계산되지 않은
구간에서는 편집 이전 스냅샷으로 고정된다. 이어지는 setLocal 이
currentSnapshot = pendingState || baseLocal 로 그것을 채택하면 저장소 B 가
통째 교체되어 편집분이 사라진다.

pending 은 getLocal 이 읽는 "화면과 같은 전체 스냅샷" 이므로, 렌더러가
_local 을 만드는 순서(dataContext._local → dynamicState → __g7ForcedLocalFields)를
그대로 따르게 합성한다. 방금 입력한 경로는 마지막에 다시 얹어 오버레이의 직전
값이 입력을 되돌리지 못하게 했다.

저장소 A 경로와 setLocal 의 base 우선순위는 건드리지 않았다. 전자는 2026-04-22 에
로그인 폼 email 손실로 철회된 자리이고, 후자는 _localInit 이 초기 데이터를
pending 에만 싣는 구간을 깨뜨린다.

engine-v1.63.3이 저장 클릭 경로를 고쳤다면 이번 수정은 그 앞의 키입력
경로를 고친다. 성립 조건에는 memo deps 와 무관한 리렌더가 선행해야 하며,
리사이즈 없는 대조군은 수정 전에도 정상이다(브라우저 실측).

트러블슈팅 246 사례 전수 판정: 영향 있음 0 · 개선 3 · 불변 10.
This commit is contained in:
HeuJung committed 2026-09-01 19:57:24 +09:00
1 parent cd189190c2
commit de584ea93f
9 files changed
+498 -21

No files matched your search

@@ -5,6 +5,18 @@
>
> 형식: [Keep a Changelog](https://keepachangelog.com/ko/1.1.0/)
## [engine-v1.63.4] - 2026-09-01
### Fixed
#### 자동바인딩 키입력이 편집기 본문을 서버 원본으로 되돌리던 문제
- 자동바인딩(`performStateUpdate`)이 `__g7PendingLocalState` 에 **저장소 A 기반 전체 스냅샷**을 그대로 대입했다. 그 base(`parentFormContext.state`)는 `extendedDataContext` useMemo 의 결과라, `setLocal({ render:false, selfManaged:true })`(CKEditor5 등)이 저장소 B 에만 쓴 뒤 memo 가 재계산되지 않은 구간에서는 **편집 이전 스냅샷으로 고정**된다. 이어지는 `setLocal` 이 `currentSnapshot = pendingState || baseLocal` 로 그것을 채택해 저장소 B 를 통째 교체하면서 편집분이 사라졌다.
- 이제 pending 은 렌더러가 화면을 만드는 순서(`dataContext._local → dynamicState → __g7ForcedLocalFields`)와 같게 합성한다(`composeAutoBindingPendingSnapshot`). pending 은 `getLocal()` 이 읽는 "화면과 같은 전체 스냅샷" 이므로 이 정합이 맞다. 방금 입력한 경로는 마지막에 다시 얹어, 오버레이의 직전 값이 입력을 되돌리지 못하게 한다.
- 성립 조건에는 **memo deps 와 무관한 리렌더**가 선행해야 한다(브라우저 실측: 폭 변경). 그것이 없으면 손실이 없다 — 리사이즈 없는 대조군은 정상이다. engine-v1.63.3(#130)이 저장 클릭 경로를 고쳤다면 이번 수정은 **그 앞의 키입력 경로**를 고친다.
- 작성 화면은 `내용은 필수입니다` 422 로, **수정 화면은 성공 토스트와 함께 서버 원본이 저장되어** 편집분이 조용히 사라졌다. 화면의 편집기에는 고친 내용이 그대로 보이고 콘솔 에러도 없었다.
- 저장소 A 경로(`parentFormContext.setState`)와 `setLocal` 의 base 우선순위는 **건드리지 않는다**. 전자는 2026-04-22 에 로그인 폼 email 손실로 철회된 수정의 자리이고, 후자는 `_localInit`(engine-v1.49.2)이 초기 데이터를 pending 에만 실어 두는 구간을 깨뜨린다.
## [engine-v1.63.3] - 2026-09-01
### Fixed
@@ -219,6 +219,50 @@ export const deepMergeState = (
return result;
};
/**
* 자동바인딩이 `__g7PendingLocalState` 에 실을 스냅샷을 합성합니다.
*
* 자동바인딩의 base 는 `parentFormContext.state`(= `extendedDataContext._local`)다.
* 그 값은 `useMemo` 결과라, memo 가 재계산되지 않은 구간에서는 **입력 이전 스냅샷으로 고정**된다.
* `setLocal({ render:false, selfManaged:true })`(CKEditor5 등 자체 DOM 관리 플러그인)이
* 저장소 B 에만 쓰면 React 렌더가 0회라 memo 가 갱신되지 않고, 그 뒤 memo deps 와 무관한
* 리렌더(폭 변경 등)가 `__g7PendingLocalState` 를 null 로 지우면 base 가 stale 인 채 남는다.
*
* 그 stale 스냅샷을 그대로 pending 에 실으면, 이어지는 `setLocal` 이
* `currentSnapshot = pendingState || baseLocal`(G7CoreGlobals) 로 그것을 채택해
* 저장소 B 를 통째 교체한다 — 편집기 본문이 예외도 콘솔 에러도 없이 사라진다.
*
* 그래서 pending 은 **렌더러가 화면에 쓰는 것과 같은 순서**로 합성한다.
* `extendedDataContext._local` 이 `dataContext._local → dynamicState → __g7ForcedLocalFields`
* 순으로 합성하는 것과 동형이며, pending 은 `getLocal()` 이 읽는 "화면과 같은 전체 스냅샷"
* 이어야 하므로 이 정합이 맞다.
*
* `__g7ForcedLocalFields` 는 `setLocal` 이 쓴 필드만 담고(engine-v1.17.4 · 사례 11),
* 자동바인딩의 매 키입력이 자기 경로로 그것을 갱신하므로 stale 이 되지 않는다.
* 방금 입력한 경로만 마지막에 다시 얹어, forced 의 직전 값이 입력을 되돌리지 못하게 한다.
*
* 저장소 A 경로(`parentFormContext.setState`)에는 적용하지 않는다 — 그쪽 base 를 바꾸는 것이
* 2026-04-22 에 로그인 폼 email 손실로 철회된 수정이다(사례 36 이력).
*
* @param update 저장소 A 기반 전체 스냅샷 (`setNestedValue(parentFormContext.state, path, value)`)
* @param forced `__g7ForcedLocalFields` — setLocal 이 소유한 필드만 담긴 오버레이
* @param fullPath 방금 입력된 필드 경로 (`${dataKey}.${name}`)
* @param newValue 방금 입력된 값
* @returns pending 에 실을 스냅샷 (인자를 변이하지 않음)
*
* @since engine-v1.63.4
*/
export const composeAutoBindingPendingSnapshot = (
update: Record<string, any>,
forced: unknown,
fullPath: string,
newValue: any
): Record<string, any> => {
if (!forced || typeof forced !== 'object' || Array.isArray(forced)) return update;
const merged = deepMergeState(update, forced as Record<string, any>);
return setNestedValue(merged, fullPath, newValue);
};
/**
* setLocal()이 업데이트한 키를 localDynamicState에서 재귀적으로 제거
*
@@ -3608,7 +3652,18 @@ const DynamicRenderer: React.FC<DynamicRendererProps> = memo(
// 저장소 A: React setState가 비동기이므로, 액션 핸들러에서 즉시 최신 값을 읽을 수 있도록
// 전역 캐시(__g7PendingLocalState)에 업데이트된 상태를 저장. G7Core.state.getLocal()이 이 캐시를 우선 사용.
(window as any).__g7PendingLocalState = update;
//
// engine-v1.63.4 (사례 41): `update` 를 그대로 싣지 않는다. base 인 parentFormContext.state 는
// 재계산되지 않은 useMemo 결과일 수 있어, selfManaged 플러그인이 저장소 B 에만 쓴 편집분을
// 담고 있지 않다. 그 stale 스냅샷이 pending 에 실리면 아래 setLocal 이 그것을 base 로 채택해
// (`currentSnapshot = pendingState || baseLocal`) 저장소 B 를 통째 교체한다.
// 렌더러와 같은 순서로 __g7ForcedLocalFields 를 얹어 화면과 같은 스냅샷을 싣는다.
(window as any).__g7PendingLocalState = composeAutoBindingPendingSnapshot(
update,
(window as any).__g7ForcedLocalFields,
fullPath,
newValue
);
// 저장소 A: React localDynamicState — 해당 Input 트리 리렌더 (기존 경로, 성능 보존)
parentFormContext.setState!(update);
@@ -0,0 +1,296 @@
/**
* DynamicRenderer.autoBindingPendingBase.test.tsx
*
* 사례 41(engine-v1.63.4) — 자동바인딩 키입력이 저장소 B 의 편집기 본문을 되돌리는 결함.
*
* 브라우저 실측(2026-09-01, 관리자 게시글 **수정** 화면)으로 확정된 조건:
*
* ① CKEditor 가 `setLocal({ render:false, selfManaged:true })` 로 저장소 B 에만 편집분을 기록
* → React 렌더 0회 → `extendedDataContext` useMemo 가 재계산되지 않아
* `parentFormContext.state`(저장소 A)는 **편집 이전 스냅샷**으로 고정된다
* ② memo deps 와 무관한 리렌더(폭 변경)가 `__g7PendingLocalState` 를 null 로 지운다
* — 이때 `__g7ForcedLocalFields` 는 **살아남는다**(사례 40 위험 핀이 잠근 사실)
* ③ 그 상태에서 제목 등 자동바인딩 입력에 한 글자 → `performStateUpdate` 가
* `__g7PendingLocalState = setNestedValue(<stale A>, path, v)` 를 대입
* ④ 이어지는 `setLocal(patch, {render:false})` 가
* `currentSnapshot = pendingState || baseLocal` 로 그 stale 스냅샷을 채택
* → 저장소 B 가 통째 교체되어 **편집분이 사라진다**
*
* 실측값(수정 화면, 폭 1051→1032):
* setLocal 진입 시 pending=`<p>F6MARKER-BODY-FIRST</p>`(서버 원본)
* forced =`<p>ZZEDITF6MARKER-BODY-FIRST</p>`(편집분 보유)
* liveB =`<p>ZZEDITF6MARKER-BODY-FIRST</p>`
* 호출 직후 liveB =`<p>F6MARKER-BODY-FIRST</p>` ← ZZEDIT 소실
* 저장 결과 DB content 가 서버 원본 그대로, title 만 반영 (조용한 데이터 손실)
*
* 화면에는 편집분이 그대로 보이고 콘솔 에러도 없다. 저장은 **성공**하므로
* 사용자에게는 아무 신호가 없다.
*
* 이 파일은 ③④를 **실물 렌더 + 실물 `G7Core.state.setLocal`** 로 잠근다.
* 저장소 A 가 stale 인 상태는 `parentFormContextProp.state` 로 그대로 재현한다
* (production 에서 그 값이 곧 재계산되지 않은 useMemo 결과다).
*
* @see 트러블슈팅 사례 41
* @see DynamicRenderer.resizePendingClear.test.tsx (②를 잠그는 사례 40 위험 핀)
*/
import React from 'react';
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { render, cleanup, fireEvent, screen } from '@testing-library/react';
import DynamicRenderer, { ComponentDefinition } from '../DynamicRenderer';
import { ComponentRegistry } from '../ComponentRegistry';
import { DataBindingEngine } from '../DataBindingEngine';
import { TranslationEngine, TranslationContext } from '../TranslationEngine';
import { ActionDispatcher } from '../ActionDispatcher';
import { initializeG7CoreGlobals } from '../G7CoreGlobals';
vi.mock('../ResponsiveManager', async (importOriginal) => {
const actual = await importOriginal<typeof import('../ResponsiveManager')>();
return {
...actual,
responsiveManager: {
getWidth: vi.fn(() => 1440),
subscribe: vi.fn(() => () => {}),
getMatchingKey: vi.fn(() => null),
parseRange: vi.fn(() => null),
},
};
});
/** 자동바인딩 대상 — name/value/onChange 를 그대로 DOM 에 넘긴다 */
const TestInput: React.FC<any> = ({ name, value, onChange }) => (
<input data-testid={`input-${name}`} name={name} value={value ?? ''} onChange={onChange} />
);
const BODY = '<p>ZZEDIT서버원본</p>';
const SERVER_ORIGINAL = '<p>서버원본</p>';
describe('[사례 41] 자동바인딩 키입력이 저장소 B 의 편집분을 되돌리지 않는다 (engine-v1.63.4)', () => {
let registry: ComponentRegistry;
let bindingEngine: DataBindingEngine;
let translationEngine: TranslationEngine;
let actionDispatcher: ActionDispatcher;
let translationContext: TranslationContext;
let globalState: Record<string, any>;
let originalG7Core: any;
/** 저장소 B (TemplateApp 계약대로 최상위 키 얕은 병합) */
const makeTemplateApp = () => ({
getGlobalState: () => globalState,
setGlobalState: (updates: any) => {
globalState = { ...globalState, ...updates };
},
});
const liveB = () => globalState._local;
/**
* `setLocal` **진입 시점**의 `__g7PendingLocalState` 를 포착합니다.
*
* 호출이 끝나면 `debouncedStateUpdate` 의 `onComplete` 가 pending 을 null 로 지우므로
* (DynamicRenderer.tsx:3648·3657) 사후 관측으로는 판정할 수 없다. 브라우저 실측에서도
* 같은 이유로 `setLocal` 을 감싸 진입 시점 값을 잡았다.
*
* @return 호출별 진입 시점 스냅샷 배열
*/
const captureSetLocalEntry = (): Array<Record<string, any> | null> => {
const seen: Array<Record<string, any> | null> = [];
const G7Core = (window as any).G7Core;
const orig = G7Core.state.setLocal;
G7Core.state.setLocal = function (...args: any[]) {
const p = (window as any).__g7PendingLocalState;
seen.push(p == null ? null : JSON.parse(JSON.stringify(p)));
return orig.apply(this, args);
};
return seen;
};
const componentDef: ComponentDefinition = {
id: 'title-input',
type: 'basic',
name: 'Input',
props: { name: 'title' },
};
/**
* 저장소 A 가 stale 인 상태로 자동바인딩 Input 을 렌더합니다.
*
* @param staleA 재계산되지 않은 `extendedDataContext._local` 을 모사한 값
* @return `parentFormContext.setState` 가 받은 값을 담는 배열
*/
const renderInput = (staleA: Record<string, any>) => {
const setStateCalls: any[] = [];
render(
<DynamicRenderer
componentDef={componentDef}
dataContext={{ _local: staleA }}
translationContext={translationContext}
registry={registry}
bindingEngine={bindingEngine}
translationEngine={translationEngine}
actionDispatcher={actionDispatcher}
parentFormContextProp={{
dataKey: 'form',
state: staleA,
setState: (u: any) => setStateCalls.push(u),
trackChanges: true,
} as any}
/>
);
return setStateCalls;
};
beforeEach(() => {
registry = ComponentRegistry.getInstance();
(registry as any).registry = {
Input: { component: TestInput, metadata: { name: 'Input', type: 'basic' } },
};
bindingEngine = new DataBindingEngine();
translationEngine = new TranslationEngine();
actionDispatcher = new ActionDispatcher({ navigate: vi.fn() });
translationContext = { templateId: 'test-template', locale: 'ko' };
originalG7Core = (window as any).G7Core;
delete (window as any).G7Core;
globalState = { _local: {} };
(window as any).__templateApp = makeTemplateApp();
(window as any).__g7PendingLocalState = null;
(window as any).__g7ForcedLocalFields = undefined;
(window as any).__g7SetLocalOverrideKeys = undefined;
(window as any).__g7LayoutContextStack = [];
delete (window as any).__g7ActionContext;
initializeG7CoreGlobals({
getState: vi.fn(() => ({
translationEngine,
translationContext,
bindingEngine,
actionDispatcher,
templateMetadata: { locales: ['ko'] },
})) as any,
transitionManager: { getIsPending: vi.fn(() => false), subscribe: vi.fn(() => () => {}) },
responsiveManager: {},
webSocketManager: {
subscribe: vi.fn(() => 's'),
unsubscribe: vi.fn(),
leaveChannel: vi.fn(),
disconnect: vi.fn(),
isInitialized: vi.fn(() => true),
getSubscriptionCount: vi.fn(() => 0),
},
} as any);
});
afterEach(() => {
cleanup();
vi.restoreAllMocks();
delete (window as any).__templateApp;
delete (window as any).__g7PendingLocalState;
delete (window as any).__g7ForcedLocalFields;
delete (window as any).__g7SetLocalOverrideKeys;
(window as any).__g7LayoutContextStack = [];
if (originalG7Core === undefined) delete (window as any).G7Core;
else (window as any).G7Core = originalG7Core;
});
it('결함 재현 핀: 편집분이 저장소 B 에 남는다', () => {
// @scenario save_flow=edit, resize_kind=same_breakpoint
// @effects autobinding_keystroke_preserves_editor_content
// 저장소 B 는 편집분을 들고 있다 (CKEditor 가 render:false 로 기록)
globalState._local = { form: { title: '제목', content: BODY, content_mode: 'html' } };
(window as any).__g7ForcedLocalFields = { form: { content: BODY, content_mode: 'html' } };
(window as any).__g7SetLocalOverrideKeys = { form: { content: BODY, content_mode: 'html' } };
// 폭 변경 리렌더가 pending 을 지운 뒤다
(window as any).__g7PendingLocalState = null;
// 저장소 A 는 편집 이전 스냅샷으로 고정돼 있다 (memo 미재계산)
renderInput({ form: { title: '제목', content: SERVER_ORIGINAL, content_mode: 'html' } });
fireEvent.change(screen.getByTestId('input-title'), { target: { value: '제목X' } });
expect(liveB().form.content, '자동바인딩 키입력이 편집분을 되돌리면 안 된다').toBe(BODY);
expect(liveB().form.title, '입력한 제목은 반영돼야 한다').toBe('제목X');
});
it('pending 스냅샷 자체가 편집분을 담는다 (후속 setLocal 의 base 가 된다)', () => {
// @scenario save_flow=edit, resize_kind=crossed_breakpoint
// @effects pending_snapshot_carries_forced_overlay
globalState._local = { form: { title: '제목', content: BODY } };
(window as any).__g7ForcedLocalFields = { form: { content: BODY } };
(window as any).__g7SetLocalOverrideKeys = { form: { content: BODY } };
(window as any).__g7PendingLocalState = null;
renderInput({ form: { title: '제목', content: SERVER_ORIGINAL } });
const entries = captureSetLocalEntry();
fireEvent.change(screen.getByTestId('input-title'), { target: { value: 'Q' } });
expect(entries.length, '자동바인딩이 setLocal 로 B 에 써야 한다').toBe(1);
expect(entries[0]?.form?.content, 'pending 이 stale A 를 그대로 실으면 안 된다').toBe(BODY);
expect(entries[0]?.form?.title, '방금 입력한 값도 실려야 한다').toBe('Q');
});
it('방금 입력한 경로는 forced 의 직전 값에 되돌려지지 않는다', () => {
// @scenario save_flow=create, resize_kind=same_breakpoint
// @effects typed_path_wins_over_forced_previous_value
// setLocal 이 과거에 title 을 쓴 적이 있어 forced 에 옛 값이 남은 상태
globalState._local = { form: { title: '옛제목', content: BODY } };
(window as any).__g7ForcedLocalFields = { form: { title: '옛제목', content: BODY } };
(window as any).__g7SetLocalOverrideKeys = { form: { title: '옛제목', content: BODY } };
(window as any).__g7PendingLocalState = null;
renderInput({ form: { title: '옛제목', content: SERVER_ORIGINAL } });
fireEvent.change(screen.getByTestId('input-title'), { target: { value: '새제목' } });
expect(liveB().form.title, '방금 입력한 값이 이겨야 한다').toBe('새제목');
expect(liveB().form.content, '편집분은 그대로 보존').toBe(BODY);
});
it('저장소 A 경로는 종전대로 A 기반이다 (2026-04-22 철회 이력 보호)', () => {
globalState._local = { form: { title: '제목', content: BODY } };
(window as any).__g7ForcedLocalFields = { form: { content: BODY } };
(window as any).__g7SetLocalOverrideKeys = { form: { content: BODY } };
(window as any).__g7PendingLocalState = null;
const staleA = { form: { title: '제목', content: SERVER_ORIGINAL }, expandedRows: [301] };
const setStateCalls = renderInput(staleA);
fireEvent.change(screen.getByTestId('input-title'), { target: { value: 'Z' } });
// parentFormContext.setState 는 A 기반 update 를 받는다 —
// 여기 base 를 B 로 바꾸는 것이 2026-04-22 에 철회된 수정(로그인 폼 email 손실)이다.
expect(setStateCalls.length).toBe(1);
expect(setStateCalls[0].form.title).toBe('Z');
expect(setStateCalls[0].form.content, 'A 경로는 A 기반 그대로').toBe(SERVER_ORIGINAL);
expect(setStateCalls[0].expandedRows, 'React 전용 키가 유지돼야 한다').toEqual([301]);
});
it('forced 가 없으면 종전 동작 (A 기반 스냅샷)', () => {
globalState._local = { form: { title: '제목', content: SERVER_ORIGINAL } };
(window as any).__g7ForcedLocalFields = undefined;
(window as any).__g7PendingLocalState = null;
renderInput({ form: { title: '제목', content: SERVER_ORIGINAL } });
const entries = captureSetLocalEntry();
fireEvent.change(screen.getByTestId('input-title'), { target: { value: 'W' } });
expect(entries[0]?.form?.title).toBe('W');
expect(entries[0]?.form?.content).toBe(SERVER_ORIGINAL);
});
it('다국어 중첩 경로에서도 편집분이 보존된다', () => {
// @scenario save_flow=create, resize_kind=crossed_breakpoint
// @effects autobinding_keystroke_preserves_editor_content
const koBody = '<p>다국어편집분</p>';
globalState._local = { form: { title: '제목', content: { ko: koBody } } };
(window as any).__g7ForcedLocalFields = { form: { content: { ko: koBody } } };
(window as any).__g7SetLocalOverrideKeys = { form: { content: { ko: koBody } } };
(window as any).__g7PendingLocalState = null;
renderInput({ form: { title: '제목', content: { ko: '<p>원본</p>' } } });
fireEvent.change(screen.getByTestId('input-title'), { target: { value: 'M' } });
expect(liveB().form.content.ko, '중첩 경로 편집분 보존').toBe(koBody);
expect(liveB().form.title).toBe('M');
});
});