feat(solution): 발행 워커·버전 관리와 예약·미리보기 정리

상시 프리렌더와 중복 예약 안내를 없애고, 검수된 발행 버전을 보존한다. 미리보기는 실제 렌더 완료까지 스피너를 표시한다.

사이트 81건, 발행·롤백·서치콘솔 45건, 프로세스 수명 3건 통과. 빌더·사이트 빌드 및 compose 설정 검증 통과.
This commit is contained in:
minaChoi committed 2026-09-15 16:12:16 +09:00
1 parent 0f7d22750f
commit f2087aad5e
207 files changed
+8424 -4429

No files matched your search

+24 -1
View File
@@ -1,4 +1,4 @@
import {StrictMode} from 'react';
import {StrictMode, useEffect} from 'react';
import {createRoot, hydrateRoot} from 'react-dom/client';
import type {SitePayload} from '@o2o/shared';
import {App} from './App';
@@ -15,6 +15,22 @@ declare global {
const container = document.getElementById('root')!;
const injected = window.__SITE_PAYLOAD__;
/**
* 미리보기를 띄운 빌더에게 "이제 그림이 나왔다" 고 알린다.
*
* ★ 빌더는 iframe 의 `load` 만으로는 이 시점을 알 수 없다. `load` 는 **셸이 뜬** 순간이고,
* 그 뒤에 payload fetch + 웹폰트 대기(최대 2.5s) + `document.fonts.ready` 가 남아 있다.
* 그 사이 iframe 은 흰 화면인데, load 를 완료로 읽으면 로딩 표시가 바로 사라져
* 사장님은 "다 됐다는데 아무것도 없는" 화면을 본다.
* ★ 두 번의 rAF 를 기다린다 — 첫 프레임은 React 가 DOM 을 붙인 직후라 아직 그려지기 전이다.
* ★ 실패해도 보낸다(ok=false). 안 보내면 빌더의 로딩 표시가 영영 안 걷힌다.
*/
function signalPreviewPainted(ok: boolean) {
if (window.parent === window) return;
const post = () => window.parent.postMessage({type: 'o2o:preview-painted', ok}, window.location.origin);
requestAnimationFrame(() => requestAnimationFrame(post));
}
/**
* 빌더 미리보기(iframe)가 여는 셸에서만 쓰는 경로 — `/preview?placeId=…`.
*
@@ -30,6 +46,11 @@ const injected = window.__SITE_PAYLOAD__;
* 떨어진다. 실측(2026-09-09): 간판체(Gugi)가 안 실려 픽셀 차이가 92% 였는데
* 지오메트리(header·hero·h1 위치)는 발행본과 완전히 같았다.
*/
function PreviewReady() {
useEffect(() => signalPreviewPainted(true), []);
return null;
}
async function renderPreview(placeId: string) {
const token = (() => {
try {
@@ -68,6 +89,7 @@ async function renderPreview(placeId: string) {
createRoot(container).render(
<StrictMode>
<App payload={payload} />
<PreviewReady />
</StrictMode>,
);
}
@@ -87,6 +109,7 @@ if (injected) {
void renderPreview(previewPlaceId).catch((ex: unknown) => {
// 미리보기가 못 떠도 편집은 계속돼야 한다. 부모 창이 읽을 수 있게 이유를 남긴다.
container.textContent = `미리보기를 불러오지 못했습니다 — ${ex instanceof Error ? ex.message : String(ex)}`;
signalPreviewPainted(false);
});
} else {
// 개발 서버(vite dev) — 데모 payload 로 CSR 렌더. 프로덕션 경로가 아니다.
@@ -99,6 +99,7 @@ export const MOONLIGHT_STAY_PAYLOAD: SitePayload = {
publishedAt: '2026-08-20T10:00:00+09:00',
updatedAt: UPDATED_AT,
version: 3,
publish: true,
},
place: {
-1
View File
@@ -615,7 +615,6 @@ export function stayBookingView(payload: SitePayload): StayBookingView | null {
const empty =
view.offers.length === 0 &&
view.notices.length === 0 &&
view.links.length === 0 &&
view.contacts.length === 0 &&
!view.phone;
+1 -9
View File
@@ -1,7 +1,6 @@
import {PlaceCategory} from '@o2o/shared';
import {
AboutSection,
AnswerBlock,
BookingSection,
EssentialInfoSection,
ExhibitionSection,
@@ -26,12 +25,7 @@ import {hasSection, isSectionEnabled} from '@site/lib/derive';
* 홈.
*
* 섹션 순서는 관리자 에디터가 정한 것(theme.sections)을 따른다.
* ★ AnswerBlock('예약 전 확인')은 **소개 바로 다음**이다 (2026-09-04, 사장님 지시).
* 전에는 히어로 바로 밑이었다. 첫 화면에서 상호를 본 손님이 곧바로 체크인 시각·환불 규정
* 표를 만나면 "여기가 어떤 집인가"를 못 읽고 값부터 본다 — 소개 한 문단을 먼저 세운다.
* 순서 설정과 무관하게 이 자리에 고정인 것은 그대로다. AI 검색이 답을 뽑아 가는 자리라
* 더 아래로 내려가면 인용률이 떨어진다.
* ★ 소개가 꺼져 있으면 히어로 바로 다음으로 올라온다 — 빈자리를 기다리지 않는다.
* 예약 전 확인은 EssentialInfoSection 한 곳에 모은다(2026-09-15 요청).
*
* ★ variantId 는 아직 해석하지 않는다.
* `SectionSetting.variantId` 에 사장님이 [디자인] 탭에서 고른 배리에이션 키
@@ -101,7 +95,6 @@ export function HomePage() {
return (
<main className="w-full flex-1">
<HeroSection />
{!isSectionEnabled(payload, 'intro') && <AnswerBlock />}
{payload.theme.sections
.filter((section) => section.enabled && section.id !== 'hero')
@@ -123,7 +116,6 @@ export function HomePage() {
{/* 사진이 한 장도 없으면 만들 엽서가 없으므로 컴포넌트가 스스로 빠진다. */}
{section.id === 'festival' && <PostcardMakerSection />}
<Component />
{section.id === 'intro' && <AnswerBlock />}
</div>
);
})}
+66
View File
@@ -0,0 +1,66 @@
import {afterEach, expect, it} from 'vitest';
import {spawnSync} from 'node:child_process';
import {existsSync, mkdtempSync, mkdirSync, readFileSync, readlinkSync, rmSync, writeFileSync} from 'node:fs';
import {tmpdir} from 'node:os';
import {join, resolve} from 'node:path';
import {MOONLIGHT_STAY_PAYLOAD} from './fixtures/moonlight-stay';
const scratch: string[] = [];
afterEach(() => scratch.splice(0).forEach((dir) => rmSync(dir, {recursive: true, force: true})));
it('검수 전 비공개·버전 전환·롤백·실패 격리·목업 보존', () => {
const root = mkdtempSync(join(tmpdir(), 'web4ai-version-test-'));
scratch.push(root);
const out = join(root, 'out');
const payloadFile = join(root, 'test-pension.json');
const run = (...args: string[]) => spawnSync(process.execPath, [
resolve('dist/prerender/prerender.js'), `--out=${out}`, ...args,
], {encoding: 'utf8', timeout: 20000});
const payload = structuredClone(MOONLIGHT_STAY_PAYLOAD);
payload.site.slug = 'test-pension';
payload.site.basePath = '/s/test-pension';
payload.site.publish = true;
payload.site.version = 1;
payload.media.forEach((media) => {media.url = `/test/${media.mediaId}.jpg`;});
const save = () => writeFileSync(payloadFile, JSON.stringify(payload));
const stage = () => run(`--payload=${payloadFile}`, '--stage-only');
mkdirSync(join(out, 's/stay'), {recursive: true});
mkdirSync(join(out, 'assets'), {recursive: true});
writeFileSync(join(out, 's/stay/index.html'), '<link href="/assets/mock.css">protected');
writeFileSync(join(out, 'assets/mock.css'), 'mock css');
save();
let result = stage();
expect(result.status, result.stderr).toBe(0);
expect(existsSync(join(out, 's/test-pension'))).toBe(false);
result = run('--activate=test-pension:1');
expect(result.status, result.stderr).toBe(0);
const v1 = readFileSync(join(out, 's/test-pension/index.html'), 'utf8');
expect(readlinkSync(join(out, 's/test-pension'))).toBe('../versions/test-pension/1');
expect(readFileSync(join(out, 'sitemap.xml'), 'utf8')).toContain('/s/test-pension');
payload.site.version = 2;
payload.place.name = '새 이름 테스트 펜션';
save();
result = stage();
expect(result.status, result.stderr).toBe(0);
expect(readFileSync(join(out, 's/test-pension/index.html'), 'utf8')).toBe(v1);
expect(run('--activate=test-pension:2').status).toBe(0);
expect(readFileSync(join(out, 's/test-pension/index.html'), 'utf8')).toContain('새 이름 테스트 펜션');
payload.site.version = 1;
save();
expect(stage().status).toBe(0);
expect(run('--activate=test-pension:1').status).toBe(0);
expect(readFileSync(join(out, 's/test-pension/index.html'), 'utf8')).toBe(v1);
payload.site.version = 3;
payload.schemaVersion = 99 as 1;
save();
expect(stage().status).not.toBe(0);
expect(run('--activate=test-pension:3').status).not.toBe(0);
expect(readFileSync(join(out, 's/test-pension/index.html'), 'utf8')).toBe(v1);
expect(run('--activate=stay:1').status).not.toBe(0);
expect(run('--seed-assets').status).toBe(0);
expect(readFileSync(join(out, 's/stay/index.html'), 'utf8')).toBe('<link href="/assets/mock.css">protected');
expect(readFileSync(join(out, 'assets/mock.css'), 'utf8')).toBe('mock css');
}, 60000);
@@ -1,6 +1,8 @@
import {Phone} from 'lucide-react';
import {selectPublishable} from '@o2o/shared';
import {useSite} from '@site/lib/site-context';
import {bookingActionLabel, bookingLinks, essentialRows} from '@site/lib/derive';
import {factualSummary} from '@site/seo/meta';
import {formatKoreanDate} from '@site/lib/format';
import type {InfoRow} from '@site/lib/derive';
import {Section} from '@site/lib/ui';
@@ -8,7 +10,7 @@ import {Section} from '@site/lib/ui';
/**
* 이용 정보 표 전체.
*
* AnswerBlock 이 상위 6개만 보여준다면 여기는 확인된 것 전부를 낸다.
* 예약 전 확인은 이 섹션 한 곳에서 확인된 항목 전체를 낸다.
* ★ "확인 안 된 항목이 N개 있다"를 숨기지 않는다 — 없는 척하면
* 손님이 다른 데서 틀린 값을 찾아 온다. 있다고 말하고 문의로 보낸다.
*
@@ -43,6 +45,8 @@ const RULE_LABELS = new Set([
export function EssentialInfoSection() {
const payload = useSite();
const rows = essentialRows(payload);
const intro = selectPublishable(payload.facts).find((fact) => fact.key === 'intro');
const summary = intro?.summary?.trim() || payload.narrative.summary || factualSummary(payload);
const guides = payload.links.filter((link) => link.confirmed &&
[link.stayGuide?.policy, link.stayGuide?.service, link.stayGuide?.reservation].some((text) => text?.trim()));
const structured = guides.flatMap((link) => link.stayGuide?.fields ?? []);
@@ -104,6 +108,7 @@ export function EssentialInfoSection() {
}
>
<div className="space-y-8">
{summary && <p className="measure text-[length:var(--fs-body)] leading-relaxed">{summary}</p>}
{ruleRows.length > 0 && <Rows title="예약 전 확인" rows={ruleRows} emphasis />}
{otherRows.length > 0 && <Rows title="시설 · 편의" rows={otherRows} />}
{guides.filter((link) => link.stayGuide?.reservation).map((link) => (
@@ -1,4 +1,4 @@
import {ArrowUpRight, BedDouble, CalendarCheck, Phone, ShieldCheck} from 'lucide-react';
import {ArrowUpRight, BedDouble, CalendarCheck, Phone} from 'lucide-react';
import {useSite} from '@site/lib/site-context';
import {bookingCtaLabel, channelLabel, sectionName, stayBookingView} from '@site/lib/derive';
import {StayBookingDemo} from './StayBookingDemo';
@@ -31,7 +31,7 @@ export function StayBookingSection() {
if (!view) return null;
const {offers, notices, links, contacts, phone} = view;
const {offers, links, contacts, phone} = view;
return (
<section
@@ -178,31 +178,6 @@ export function StayBookingSection() {
{/* ── 날짜 · 시간 선택 (화면 안에서만 도는 목업) ────────── */}
<StayBookingDemo />
{/* ── 예약 전 확인 ────────────────────────────────────── */}
{notices.length > 0 && (
<div
className="mt-4 overflow-hidden rounded-2xl border border-black/8 lg:mt-6"
style={{backgroundColor: 'var(--color-surface)'}}
>
<p className="flex items-center gap-2 border-b border-black/8 px-4 py-3 text-xs font-bold sm:px-5">
<ShieldCheck className="size-3.5 opacity-50" />
<span>예약 전 확인</span>
</p>
{/* 확인된 fact 만 줄이 된다 — "확인 중" 이라는 빈 줄을 그리면 손님은 그걸 규정으로 읽는다. */}
<dl className="grid grid-cols-1 divide-y divide-black/5 sm:grid-cols-2 sm:divide-y-0">
{notices.map((row) => (
<div
key={row.label}
className="flex flex-col gap-1 p-4 sm:flex-row sm:items-start sm:justify-between sm:gap-4 sm:p-5"
>
<dt className="shrink-0 text-xs opacity-55">{row.label}</dt>
<dd className="text-xs font-semibold sm:max-w-[60%] sm:text-right">{row.value}</dd>
</div>
))}
</dl>
</div>
)}
</div>
</section>
);
@@ -14,7 +14,7 @@
* ★ 갈래(문학·역사·…)로 묶어 세우지 않는다. 갈래는 카드 위 이름표로만 쓰고, 뽑기는
* 갈래를 가리지 않는다 — 갈래마다 3~4개씩 뽑던 판은 한 번에 15~19개가 떴다.
*/
import {useEffect, useState} from 'react';
import {useEffect, useMemo, useState} from 'react';
import type {ReadingItem} from '@o2o/shared';
import {useSite} from '@site/lib/site-context';
import {sectionItems, sectionName} from '@site/lib/derive';
@@ -35,13 +35,17 @@ function shuffled<T>(list: readonly T[]): T[] {
export function ReadingSection() {
const payload = useSite();
const parsed = sectionItems<ReadingItem>(payload, 'reading');
// 파서가 매번 새 배열을 만들면 effect가 다시 추첨하며 무한 렌더링한다.
const parsed = useMemo(() => sectionItems<ReadingItem>(payload, 'reading'), [payload]);
const all = parsed.items;
// 서버·첫 렌더가 같아야 한다. 섞기는 아래 useEffect 가 붙은 뒤에 한 번만.
const [picked, setPicked] = useState<ReadingItem[]>(() => all.slice(0, MAX_PICK));
useEffect(() => {
if (all.length <= MIN_PICK) return;
if (all.length <= MIN_PICK) {
setPicked(all);
return;
}
const count = Math.random() < 0.5 ? MIN_PICK : MAX_PICK;
setPicked(shuffled(all).slice(0, count));
// 더미 전체가 바뀔 때만 다시 뽑는다(발행본에서는 한 번뿐이다).
@@ -106,6 +106,15 @@ describe('stayBookingView — 예약에 쓸 값을 고르는 자리', () => {
});
describe('발행 HTML — 예약 섹션이 실제로 나가는가', () => {
it('예약 전 확인은 이용안내 안에 한 번만 표시한다', () => {
const baked = html();
expect(baked.match(/예약 전 확인/g)).toHaveLength(1);
expect(baked).not.toContain('id="summary"');
const booking = baked.slice(baked.indexOf('id="booking"'));
expect(booking).not.toContain('예약 전 확인');
expect(baked).toContain('취소·환불 규정');
expect(baked).toContain('체크인 시간');
});
it('요금 · 인원 · 취소 규정 · 예약 창구가 한자리에 있다', () => {
const text = visibleText(html());
expect(text).toContain('예약 창구');