fix(core): 레이아웃 버전 변경량 계산의 메모리 초과와 편집기 확장 편집·재로드·충돌 안내·버전 기록 결함 수정
- 버전 이력 변경량(+N/-N 줄) 계산이 변경 영역 (줄 수)² 크기의 LCS 표를 만들어 큰 공통 레이아웃의 첫 편집기 저장이 PHP 기본 메모리 한도(128M) 서버에서 500 으로 끝났다. 두 행 DP 로 길이만 구하도록 바꿔 메모리가 줄 수에 비례하고 표시 숫자는 종전과 같다(참조 구현 동치·메모리 상한 회귀 테스트) - 확장 편집 모드 저장이 overlay 확장의 injections 를 비우던 결함: 서버가 주입 노드 출처 메타에 injection 순번을 싣고, 편집기는 그 순번(없으면 원본 노드 id) 으로 되돌리며, 되돌릴 수 없는 노드가 있으면 저장하지 않고 안내한다 - 서빙 캐시 키를 서버 현재 확장 캐시 버전으로만 조립해 저장·복원 두 번째부터 재로드·「최신 불러오기」가 옛 내용을 받던 결함 수정(요청 v 는 HTTP 캐시 우회용) - 409 충돌 안내가 errors 아래의 버전을 읽지 못해 「최신 버전: -1」 로 표시되던 결함을 세 저장 경로 공용 판독으로 수정 - 버전 저장 시 저장자를 기록하고, 복원 시에도 잠금 번호를 올린다 - 회귀 테스트(PHPUnit·Vitest), 트러블슈팅 사례 32~34, 규정·API 문서, ja 언어팩, 편집기 번들 재빌드, 이력 문서 동반
This commit is contained in:
1 parent
72f46a6468
commit
0b6f329249
34 files changed
+1080
-97
No files matched your search
@@ -5,6 +5,21 @@
|
||||
>
|
||||
> 형식: [Keep a Changelog](https://keepachangelog.com/ko/1.1.0/)
|
||||
|
||||
## [engine-v1.66.1] - 2026-09-09
|
||||
|
||||
### Fixed
|
||||
|
||||
#### 확장 편집 모드 저장 — overlay injections 보존
|
||||
- 호스트 병합 모드에서 추출한 확장 노드에 `__injectionIndex` 가 없어 `reassembleContent` 가 전부 버리고 `injections[].components: []` 를 PUT 하던 결함 수정 — 백엔드가 `__source.injectionIndex` 로 실어 주는 순번을 읽고, 없으면 원본 injection 의 노드 id 로 되돌린다 (useExtensionDocument.ts `reassembleOverlayContent`)
|
||||
- 되돌리지 못한 노드가 있고 원본에 잃을 컴포넌트가 있으면 PUT 하지 않고 `guard_extension_reassembly` 를 돌려준다 — `SaveFeedbackBanner` 가 자동 dismiss 없는 오류 배너로 표시 (`g7le-save-banner-guard-extension-reassembly`)
|
||||
- `NodeSource.injectionIndex` 타입 추가 (layoutTreeUtils.ts)
|
||||
|
||||
#### 409 배너 버전 표기
|
||||
- 서버(`ResponseHelper::error`)가 `errors` 아래에 싣는 `current_version`/`your_version` 을 읽지 못해 「최신 버전: -1」 로 표시되던 결함 수정 — `utils/conflictVersion.ts` `readConflictVersion` 단일 판독(`errors.{key}` 우선, 최상위 폴백)을 레이아웃 저장·확장 저장·inject_props 교차 저장 세 경로가 공유
|
||||
|
||||
### Notes
|
||||
- 편집기 재로드 stale(부팅 시점 `cache_version` 키)은 서버 `PublicLayoutController::serve` 캐시 키를 서버 현재 버전으로 고정해 해소 — 클라이언트 nonce 규약(`?v={cacheVersion}.{nonce}`)은 그대로다
|
||||
|
||||
## [engine-v1.66.0] - 2026-09-08
|
||||
|
||||
### Added
|
||||
|
||||
+145
@@ -681,3 +681,148 @@ describe('useExtensionDocument — 로드/저장', () => {
|
||||
expect(result.current.document.needsHostPicker).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
// ============================================================================
|
||||
// [case:backend-34] overlay 확장 — 호스트 병합 모드 저장이 injections 를 보존해야 한다
|
||||
// ============================================================================
|
||||
describe('[case:backend-34] overlay 확장 호스트 병합 저장 — injections 보존', () => {
|
||||
let fetchSpy: ReturnType<typeof vi.fn>;
|
||||
|
||||
beforeEach(() => {
|
||||
fetchSpy = vi.fn();
|
||||
(global as any).fetch = fetchSpy;
|
||||
if (typeof window !== 'undefined') window.localStorage?.clear();
|
||||
});
|
||||
|
||||
function enterExtension(result: any, extId: string) {
|
||||
act(() => {
|
||||
result.current.editor.dispatch({ type: 'ENTER_EXTENSION_EDIT', extensionId: extId });
|
||||
});
|
||||
}
|
||||
|
||||
const overlayContent = {
|
||||
target_layout: '_user_base',
|
||||
injections: [
|
||||
{ target_id: 'anchor', position: 'append_child', components: [{ id: 'ext-sel', name: 'Div' }] },
|
||||
],
|
||||
priority: 320,
|
||||
};
|
||||
|
||||
/** 확장 GET + 호스트 GET(with_source_meta) mock — 호스트 앵커 아래 주입 노드 1개 */
|
||||
function mockOverlay(hostChild: Record<string, unknown>) {
|
||||
fetchSpy.mockImplementation((url: string) => {
|
||||
if (url.includes('/layout-extensions/')) {
|
||||
return Promise.resolve(
|
||||
extResponse({
|
||||
id: 7,
|
||||
extension_type: 'overlay',
|
||||
lock_version: 0,
|
||||
content: JSON.stringify(overlayContent),
|
||||
host_layouts: ['_user_base'],
|
||||
}),
|
||||
);
|
||||
}
|
||||
return Promise.resolve(
|
||||
hostResponse([{ id: 'anchor', name: 'Div', __source: { kind: 'base' }, children: [hostChild] }]),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
it('reassembleContent — __injectionIndex 없이 백엔드 __source.injectionIndex 만 있어도 원래 injection 으로 분배', () => {
|
||||
const roots = [
|
||||
{ id: 'ext-sel', name: 'Div', __source: { kind: 'extension', extensionId: 7, injectionIndex: 0 } },
|
||||
] as any;
|
||||
const out = reassembleContent(overlayContent as any, roots) as any;
|
||||
expect(out.injections[0].components).toEqual([{ id: 'ext-sel', name: 'Div' }]);
|
||||
});
|
||||
|
||||
it('호스트 병합 모드 무변경 저장 — 주입 컴포넌트가 그대로 PUT 된다(비워지지 않음)', async () => {
|
||||
mockOverlay({
|
||||
id: 'ext-sel',
|
||||
name: 'Div',
|
||||
__source: { kind: 'extension', extensionId: 7, injectionIndex: 0 },
|
||||
});
|
||||
const { result } = renderHook(() => combinedHook(), { wrapper: makeWrapper() });
|
||||
enterExtension(result, '7');
|
||||
await waitFor(() => expect(result.current.document.document).not.toBeNull());
|
||||
expect(result.current.document.document!.editability).toBe('ok');
|
||||
|
||||
fetchSpy.mockImplementationOnce(() =>
|
||||
Promise.resolve({ ok: true, status: 200, json: async () => ({ data: { lock_version: 1 } }) }),
|
||||
);
|
||||
let saveResult: any;
|
||||
await act(async () => {
|
||||
saveResult = await result.current.document.save();
|
||||
});
|
||||
expect(saveResult.kind).toBe('success');
|
||||
const putCall = fetchSpy.mock.calls.find((c) => c[1]?.method === 'PUT')!;
|
||||
const body = JSON.parse(putCall[1].body);
|
||||
// 종전: injections[0].components 가 [] 로 비워져 PUT — 사이트에서 그 확장 UI 가 조용히 사라졌다.
|
||||
expect(body.content.injections[0].components).toEqual([{ id: 'ext-sel', name: 'Div' }]);
|
||||
expect(body.content.priority).toBe(320);
|
||||
expect(body.content.target_layout).toBe('_user_base');
|
||||
});
|
||||
|
||||
it('injection 을 되찾을 수 없는 노드가 있으면 PUT 하지 않고 guard 를 돌려준다(손실 차단)', async () => {
|
||||
// 순번 메타도 없고 id 도 원본 injection 과 맞지 않는 노드 — 어느 injection 인지 알 수 없다.
|
||||
mockOverlay({ id: 'unknown-node', name: 'Div', __source: { kind: 'extension', extensionId: 7 } });
|
||||
const { result } = renderHook(() => combinedHook(), { wrapper: makeWrapper() });
|
||||
enterExtension(result, '7');
|
||||
await waitFor(() => expect(result.current.document.document).not.toBeNull());
|
||||
|
||||
let saveResult: any;
|
||||
await act(async () => {
|
||||
saveResult = await result.current.document.save();
|
||||
});
|
||||
expect(saveResult.kind).toBe('guard_extension_reassembly');
|
||||
expect(fetchSpy.mock.calls.find((c) => c[1]?.method === 'PUT')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('순번 메타가 없어도 id 가 원본 injection 의 노드와 맞으면 그 injection 으로 되돌린다(구 백엔드 호환)', async () => {
|
||||
mockOverlay({ id: 'ext-sel', name: 'Div', __source: { kind: 'extension', extensionId: 7 } });
|
||||
const { result } = renderHook(() => combinedHook(), { wrapper: makeWrapper() });
|
||||
enterExtension(result, '7');
|
||||
await waitFor(() => expect(result.current.document.document).not.toBeNull());
|
||||
fetchSpy.mockImplementationOnce(() =>
|
||||
Promise.resolve({ ok: true, status: 200, json: async () => ({ data: { lock_version: 1 } }) }),
|
||||
);
|
||||
let saveResult: any;
|
||||
await act(async () => {
|
||||
saveResult = await result.current.document.save();
|
||||
});
|
||||
expect(saveResult.kind).toBe('success');
|
||||
const putCall = fetchSpy.mock.calls.find((c) => c[1]?.method === 'PUT')!;
|
||||
expect(JSON.parse(putCall[1].body).content.injections[0].components).toEqual([
|
||||
{ id: 'ext-sel', name: 'Div' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('409 — 서버가 errors 아래에 넣는 current_version/your_version 을 읽는다(종전 -1)', async () => {
|
||||
fetchSpy.mockResolvedValue(
|
||||
extResponse({
|
||||
id: 1,
|
||||
extension_type: 'extension_point',
|
||||
lock_version: 3,
|
||||
content: JSON.stringify({ components: [{ id: 'root' }] }),
|
||||
}),
|
||||
);
|
||||
const { result } = renderHook(() => combinedHook(), { wrapper: makeWrapper() });
|
||||
enterExtension(result, '1');
|
||||
await waitFor(() => expect(result.current.document.document).not.toBeNull());
|
||||
|
||||
fetchSpy.mockResolvedValueOnce({
|
||||
ok: false,
|
||||
status: 409,
|
||||
json: async () => ({
|
||||
success: false,
|
||||
message: '다른 사용자가 먼저 저장했습니다.',
|
||||
errors: { error: 'concurrent_modification', current_version: 5, your_version: 3 },
|
||||
}),
|
||||
});
|
||||
let saveResult: any;
|
||||
await act(async () => {
|
||||
saveResult = await result.current.document.save();
|
||||
});
|
||||
expect(saveResult).toEqual({ kind: 'concurrent_modification', currentVersion: 5, yourVersion: 3 });
|
||||
});
|
||||
});
|
||||
+33
@@ -319,3 +319,36 @@ describe('useLayoutDocument — 중첩 경로 layoutName PUT URL 슬래시 보
|
||||
expect(putUrl).not.toContain('auth%2Fforgot_password');
|
||||
});
|
||||
});
|
||||
|
||||
describe('useLayoutDocument — 409 본문이 errors 아래에 버전을 담는 실제 서버 형식', () => {
|
||||
beforeEach(() => {
|
||||
const fetchMock = vi.fn();
|
||||
fetchMock.mockResolvedValueOnce(initialLoadResponse as any).mockResolvedValueOnce(
|
||||
mockStatus(409, {
|
||||
success: false,
|
||||
message: '다른 사용자가 먼저 저장했습니다. (리소스: template_layouts:1, 현재 버전: 9, 보낸 버전: 7)',
|
||||
errors: { error: 'concurrent_modification', current_version: 9, your_version: 7 },
|
||||
})
|
||||
);
|
||||
(globalThis as any).fetch = fetchMock;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
delete (globalThis as any).fetch;
|
||||
});
|
||||
|
||||
it('ResponseHelper 형식(errors.current_version) 에서도 최신/내 버전을 읽는다 — 종전 배너 「최신 버전: -1」', async () => {
|
||||
const { result } = renderHook(() => useLayoutDocument(), { wrapper });
|
||||
await waitFor(() => expect(result.current.document).not.toBeNull());
|
||||
|
||||
let saveResult: any;
|
||||
await act(async () => {
|
||||
saveResult = await result.current.save();
|
||||
});
|
||||
expect(saveResult).toEqual({
|
||||
kind: 'concurrent_modification',
|
||||
currentVersion: 9,
|
||||
yourVersion: 7,
|
||||
});
|
||||
});
|
||||
});
|
||||
+12
@@ -74,4 +74,16 @@ describe('saveInjectedPropsToExtension', () => {
|
||||
const result = await saveInjectedPropsToExtension(tpl, 99, 'h', {}, fetchMock as any);
|
||||
expect(result.kind).toBe('not_found');
|
||||
});
|
||||
it('409 본문이 errors 아래에 버전을 담아도(ResponseHelper 형식) conflict 버전을 읽는다', async () => {
|
||||
const content = { injections: [{ target_id: 'h', position: 'inject_props', props: {} }] };
|
||||
const fetchMock = vi.fn();
|
||||
fetchMock.mockResolvedValueOnce(
|
||||
jsonRes(200, { data: { id: 2, content: JSON.stringify(content), lock_version: 3 } }),
|
||||
);
|
||||
fetchMock.mockResolvedValueOnce(
|
||||
jsonRes(409, { success: false, errors: { current_version: 7, your_version: 3 } }, false),
|
||||
);
|
||||
const result = await saveInjectedPropsToExtension(tpl, 2, 'h', { a: 1 }, fetchMock as any);
|
||||
expect(result).toEqual({ kind: 'conflict', currentVersion: 7, yourVersion: 3 });
|
||||
});
|
||||
});
|
||||
@@ -38,7 +38,12 @@ export function SaveFeedbackBanner(props: SaveFeedbackBannerProps): React.ReactE
|
||||
// 는 5초 후 자동 dismiss. concurrent / validation 은 사용자가 명시적으로 닫음.
|
||||
useEffect(() => {
|
||||
if (!result) return;
|
||||
if (result.kind === 'concurrent_modification' || result.kind === 'validation_failed') return;
|
||||
if (
|
||||
result.kind === 'concurrent_modification' ||
|
||||
result.kind === 'validation_failed' ||
|
||||
result.kind === 'guard_extension_reassembly'
|
||||
)
|
||||
return;
|
||||
const timer = setTimeout(onDismiss, 5000);
|
||||
return () => clearTimeout(timer);
|
||||
}, [result, onDismiss]);
|
||||
@@ -98,6 +103,22 @@ export function SaveFeedbackBanner(props: SaveFeedbackBannerProps): React.ReactE
|
||||
);
|
||||
}
|
||||
|
||||
if (result.kind === 'guard_extension_reassembly') {
|
||||
// 확장 편집 모드 저장 가드 — 자동 dismiss 없음(저장이 안 됐다는 사실을 운영자가 봐야 한다).
|
||||
return (
|
||||
<BannerShell
|
||||
tone="error"
|
||||
testId="g7le-save-banner-guard-extension-reassembly"
|
||||
onDismiss={onDismiss}
|
||||
>
|
||||
<strong>{t('layout_editor.save.guard_extension_reassembly_title')}</strong>
|
||||
<div style={{ marginTop: 4, fontSize: 12 }}>
|
||||
{t('layout_editor.save.guard_extension_reassembly', { count: String(result.unassigned) })}
|
||||
</div>
|
||||
</BannerShell>
|
||||
);
|
||||
}
|
||||
|
||||
if (result.kind === 'guard_no_document') {
|
||||
return (
|
||||
<BannerShell tone="neutral" testId="g7le-save-banner-guard-no-document" onDismiss={onDismiss}>
|
||||
|
||||
@@ -45,6 +45,7 @@ import type { EditorNode, NodeSource } from '../utils/layoutTreeUtils';
|
||||
import { trackEditorDocument } from '../devtools/editorTrackers';
|
||||
import { readSanctumToken } from '../utils/authToken';
|
||||
import { getCacheBustNonce, bumpCacheBustNonce } from '../utils/editorCacheBust';
|
||||
import { readConflictVersion } from '../utils/conflictVersion';
|
||||
import type { SaveResult } from './useLayoutDocument';
|
||||
import { suffixed } from '../../../support/assetUrl';
|
||||
|
||||
@@ -114,25 +115,92 @@ export function reassembleContent(
|
||||
return { ...content, components: cleaned };
|
||||
}
|
||||
if (Array.isArray(content.injections)) {
|
||||
const injections = (content.injections as any[]).map((inj) => ({ ...inj }));
|
||||
// components 를 가진 injection 의 components 를 비운 뒤 편집 결과로 재분배.
|
||||
injections.forEach((inj) => {
|
||||
if (Array.isArray(inj.components)) inj.components = [];
|
||||
});
|
||||
for (const node of roots) {
|
||||
const idx = (node as any).__injectionIndex;
|
||||
const target =
|
||||
typeof idx === 'number' && idx >= 0 && idx < injections.length ? injections[idx] : null;
|
||||
if (target) {
|
||||
if (!Array.isArray(target.components)) target.components = [];
|
||||
target.components.push(stripExtensionEditorMeta(node));
|
||||
}
|
||||
}
|
||||
return { ...content, injections };
|
||||
return reassembleOverlayContent(content, roots).content;
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
/** overlay 재조립 결과 — 되돌리지 못한 노드 수를 함께 돌려준다(저장 가드 근거). */
|
||||
export interface OverlayReassembly {
|
||||
/** 저장용 content */
|
||||
content: Record<string, unknown>;
|
||||
/** 어느 injection 에서 왔는지 알 수 없어 버려질 뻔한 루트 노드 수 — 0 이 아니면 PUT 하지 않는다 */
|
||||
unassigned: number;
|
||||
}
|
||||
|
||||
/** 트리의 모든 노드 id 를 모은다(원본 injection 의 id 집합 — 순번 메타 없는 노드의 폴백 매칭용). */
|
||||
function collectNodeIds(nodes: unknown, out: Set<string>): void {
|
||||
if (!Array.isArray(nodes)) return;
|
||||
for (const n of nodes) {
|
||||
if (!n || typeof n !== 'object') continue;
|
||||
const id = (n as { id?: unknown }).id;
|
||||
if (typeof id === 'string' && id !== '') out.add(id);
|
||||
collectNodeIds((n as { children?: unknown }).children, out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* overlay content 의 injections 를 편집 결과 루트로 되돌린다.
|
||||
*
|
||||
* 노드가 어느 injection 에서 왔는지는 세 단계로 판정한다 — ① 조각 단독 모드가 붙인
|
||||
* `__injectionIndex` ② 호스트 병합 모드에서 백엔드가 `__source.injectionIndex` 로 실어 준 순번
|
||||
* ③ 둘 다 없으면 원본 injection 의 노드 id 집합과 대조(구 백엔드 응답 호환). 셋 다 실패한
|
||||
* 노드는 **버리지 않고 센다** — 종전엔 조용히 버려져 호스트 병합 모드의 무변경 저장만으로
|
||||
* `injections[].components` 가 통째로 비워졌다(이커머스 → `_user_base` 헤더 통화 선택기 소실).
|
||||
*
|
||||
* @param content 원본 파싱 content(비편집 키 보존용)
|
||||
* @param roots 편집된 루트 노드 배열
|
||||
* @returns 저장용 content + 되돌리지 못한 노드 수
|
||||
*/
|
||||
export function reassembleOverlayContent(
|
||||
content: Record<string, unknown>,
|
||||
roots: EditorNode[],
|
||||
): OverlayReassembly {
|
||||
const original = Array.isArray(content.injections) ? (content.injections as any[]) : [];
|
||||
const injections = original.map((inj) => ({ ...inj }));
|
||||
const originalIds = original.map((inj) => {
|
||||
const ids = new Set<string>();
|
||||
if (inj && Array.isArray(inj.components)) collectNodeIds(inj.components, ids);
|
||||
return ids;
|
||||
});
|
||||
// components 를 가진 injection 의 components 를 비운 뒤 편집 결과로 재분배.
|
||||
injections.forEach((inj) => {
|
||||
if (Array.isArray(inj.components)) inj.components = [];
|
||||
});
|
||||
let unassigned = 0;
|
||||
for (const node of roots) {
|
||||
const explicit = (node as any).__injectionIndex;
|
||||
const fromSource = (node as any).__source?.injectionIndex;
|
||||
let idx: number | undefined =
|
||||
typeof explicit === 'number' ? explicit : typeof fromSource === 'number' ? fromSource : undefined;
|
||||
if (idx === undefined) {
|
||||
const id = (node as { id?: unknown }).id;
|
||||
if (typeof id === 'string') {
|
||||
const found = originalIds.findIndex((ids) => ids.has(id));
|
||||
if (found >= 0) idx = found;
|
||||
}
|
||||
}
|
||||
const target =
|
||||
typeof idx === 'number' && idx >= 0 && idx < injections.length ? injections[idx] : null;
|
||||
if (!target) {
|
||||
unassigned += 1;
|
||||
continue;
|
||||
}
|
||||
if (!Array.isArray(target.components)) target.components = [];
|
||||
target.components.push(stripExtensionEditorMeta(node));
|
||||
}
|
||||
return { content: { ...content, injections }, unassigned };
|
||||
}
|
||||
|
||||
/** 원본 overlay content 가 가진 주입 컴포넌트 루트 수 — 0 이면 잃을 것이 없어 가드가 불필요하다. */
|
||||
function countInjectionComponents(content: Record<string, unknown>): number {
|
||||
if (!Array.isArray(content.injections)) return 0;
|
||||
return (content.injections as any[]).reduce(
|
||||
(n, inj) => n + (inj && Array.isArray(inj.components) ? inj.components.length : 0),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 편집기 전용/호스트 합성 메타(`__injectionIndex`/`__source`/`__injectedProps`/`_fromBase`)를
|
||||
* 노드 트리에서 재귀 제거한다(저장 직렬화 — 확장 content 원본 형태 복원).
|
||||
@@ -641,7 +709,29 @@ export function useExtensionDocument(): UseExtensionDocumentResult {
|
||||
const extracted = extractCurrentExtensionNodes(current.components, current.extensionId);
|
||||
const fragmentRoots = extracted.length > 0 ? extracted : current.components;
|
||||
// 편집한 components 를 원본 content 형태로 재조립(비편집 키 보존, 메타 제거).
|
||||
const contentToSave = reassembleContent(contentRef.current, fragmentRoots);
|
||||
let contentToSave: Record<string, unknown>;
|
||||
const isOverlay =
|
||||
Array.isArray(contentRef.current.injections) && !Array.isArray(contentRef.current.components);
|
||||
if (isOverlay) {
|
||||
// 손실 가드 — 되돌리지 못한 노드가 있고 원본에 잃을 컴포넌트가 있으면 PUT 하지 않는다.
|
||||
// (종전엔 그 노드를 조용히 버려 무변경 저장만으로 injections 가 비워졌다.)
|
||||
const reassembled = reassembleOverlayContent(contentRef.current, fragmentRoots);
|
||||
if (reassembled.unassigned > 0 && countInjectionComponents(contentRef.current) > 0) {
|
||||
trackEditorDocument({
|
||||
op: 'save',
|
||||
layoutName: `extension:${current.extensionId}`,
|
||||
editMode: 'extension',
|
||||
saveTarget: 'layout_extension',
|
||||
endpoint: url,
|
||||
isDirty,
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
return { kind: 'guard_extension_reassembly', unassigned: reassembled.unassigned };
|
||||
}
|
||||
contentToSave = reassembled.content;
|
||||
} else {
|
||||
contentToSave = reassembleContent(contentRef.current, fragmentRoots);
|
||||
}
|
||||
|
||||
trackEditorDocument({
|
||||
op: 'save',
|
||||
@@ -710,8 +800,8 @@ export function useExtensionDocument(): UseExtensionDocumentResult {
|
||||
if (response.status === 409) {
|
||||
return {
|
||||
kind: 'concurrent_modification',
|
||||
currentVersion: (body as any)?.current_version ?? -1,
|
||||
yourVersion: (body as any)?.your_version ?? current.lockVersion,
|
||||
currentVersion: readConflictVersion(body, 'current_version') ?? -1,
|
||||
yourVersion: readConflictVersion(body, 'your_version') ?? current.lockVersion,
|
||||
};
|
||||
}
|
||||
if (response.status === 422) {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { readConflictVersion } from '../utils/conflictVersion';
|
||||
import { useLayoutEditor } from '../LayoutEditorContext';
|
||||
import {
|
||||
buildEditorAccessError,
|
||||
@@ -130,7 +131,12 @@ export type SaveResult =
|
||||
| { kind: 'concurrent_modification'; currentVersion: number; yourVersion: number }
|
||||
| { kind: 'blocked_inactive_extension'; blockedPaths: string[] }
|
||||
| { kind: 'network_error'; message: string }
|
||||
| { kind: 'guard_no_document' };
|
||||
| { kind: 'guard_no_document' }
|
||||
/**
|
||||
* 확장 편집 모드(overlay) 저장 가드 — 추출한 노드 중 어느 injection 에서 왔는지 알 수 없는 것이
|
||||
* 있어 PUT 하지 않았다. 그대로 저장하면 그 노드가 버려져 injections 가 비워진다.
|
||||
*/
|
||||
| { kind: 'guard_extension_reassembly'; unassigned: number };
|
||||
|
||||
export interface UseLayoutDocumentResult {
|
||||
/** 현재 로드된 문서 (null = 로드 전 / 라우트 미선택) */
|
||||
@@ -940,12 +946,13 @@ export function useLayoutDocument(): UseLayoutDocumentResult {
|
||||
};
|
||||
}
|
||||
|
||||
// 409 — 동시 수정
|
||||
// 409 — 동시 수정. 서버(ResponseHelper::error)는 버전을 `errors` 아래에 싣는다 —
|
||||
// 최상위만 읽으면 배너가 「최신 버전: -1」 을 표시한다.
|
||||
if (response.status === 409) {
|
||||
return {
|
||||
kind: 'concurrent_modification',
|
||||
currentVersion: (body as any)?.current_version ?? -1,
|
||||
yourVersion: (body as any)?.your_version ?? current.lockVersion,
|
||||
currentVersion: readConflictVersion(body, 'current_version') ?? -1,
|
||||
yourVersion: readConflictVersion(body, 'your_version') ?? current.lockVersion,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 409(동시 수정) 응답 본문의 버전 번호 판독.
|
||||
*
|
||||
* 서버(`ResponseHelper::error`)는 `current_version`/`your_version` 을 최상위가 아니라 `errors`
|
||||
* 아래에 싣는다. 최상위만 읽으면 값이 없어 -1 로 떨어지고 배너가 「최신 버전: -1」 을 표시한다.
|
||||
* 레이아웃 저장·확장 저장·inject_props 교차 저장 세 경로가 같은 판독을 쓴다.
|
||||
*
|
||||
* @since engine-v1.66.1
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param body 파싱된 응답 본문(형식 미상)
|
||||
* @param key `current_version` | `your_version`
|
||||
* @returns 숫자 또는 undefined — `errors.{key}` 우선, 최상위 폴백(구 응답 형식 호환)
|
||||
*/
|
||||
export function readConflictVersion(
|
||||
body: unknown,
|
||||
key: 'current_version' | 'your_version',
|
||||
): number | undefined {
|
||||
const b = body as ({ errors?: Record<string, unknown> } & Record<string, unknown>) | null | undefined;
|
||||
const nested = b?.errors?.[key];
|
||||
if (typeof nested === 'number') return nested;
|
||||
const top = b?.[key];
|
||||
return typeof top === 'number' ? top : undefined;
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import { buildAuthHeaders } from './authToken';
|
||||
import { readConflictVersion } from './conflictVersion';
|
||||
|
||||
/** 교차 저장 결과 */
|
||||
export type InjectedPropsSaveResult =
|
||||
@@ -112,8 +113,8 @@ export async function saveInjectedPropsToExtension(
|
||||
if (putRes.status === 409) {
|
||||
return {
|
||||
kind: 'conflict',
|
||||
currentVersion: (putBody as any)?.current_version ?? -1,
|
||||
yourVersion: (putBody as any)?.your_version ?? lockVersion,
|
||||
currentVersion: readConflictVersion(putBody, 'current_version') ?? -1,
|
||||
yourVersion: readConflictVersion(putBody, 'your_version') ?? lockVersion,
|
||||
};
|
||||
}
|
||||
return { kind: 'error', message: (putBody as any)?.message ?? `HTTP ${putRes.status}` };
|
||||
|
||||
@@ -31,6 +31,11 @@ export interface NodeSource {
|
||||
extensionIdentifier?: string;
|
||||
/** 확장 로케일 표시명(예: `게시판`) — 식별자와 함께 표시 */
|
||||
extensionName?: string;
|
||||
/**
|
||||
* overlay 확장 `injections[]` 순번 — 백엔드가 주입 시점에 부여. 확장 편집 모드 저장이 호스트
|
||||
* 병합 트리에서 추출한 노드를 원래 injection 으로 되돌리는 열쇠(extension_point 주입은 없음).
|
||||
*/
|
||||
injectionIndex?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user