fix(854-3): 줄 쌓기 화면 창 크기 듣기 해제 — destroy 길 · 닫을 때 부름
- createStackScreen 에 destroy(창 크기 듣기 해제) · 단가산출 그릇(Sangeun_Tabs) → mountSangeunDetail.destroy 가 부름 (M02 단가산출 · 일위대가 참조 줄 창 · 불러온 단가산출 창 모두 이 길) - M01 단가산출 기초 화면은 M01 페이지를 다시 그릴 때 지난 화면 destroy · M01 읽기 창(부품)은 앱 하나로 재사용 - 시험 test_854_3_screen_leak(가짜 DOM · 열고 닫기 5 회 = 열린 동안 1 · 닫으면 0) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -659,6 +659,8 @@ export function createStackScreen(opt: StackScreenOptions) {
|
||||
|
||||
return {
|
||||
root,
|
||||
/** 화면을 닫거나 다른 문서로 바꿀 때 — 창 크기 듣기 해제(안 부르면 열 때마다 하나씩 남음) */
|
||||
destroy: (): void => window.removeEventListener("resize", fit),
|
||||
/** 로직 · SK 키로 그림(빈 키 = 저장 전 새 것) — 같은 키는 그대로 · `force` = 다시 읽음(탭 바꿈) */
|
||||
draw: (next: string, force = false): void => {
|
||||
if (force || next !== shown) loading = open(next);
|
||||
|
||||
@@ -83,6 +83,8 @@ function loadDrafts(): Record<string, Draft> {
|
||||
export interface LogicHandle {
|
||||
/** 밖(요소 화면)에서 이 키를 바로 엶 — 소요량·계수 표의 「쓰는 로직」 눌렀을 때. */
|
||||
openKey: (key: string) => Promise<void>;
|
||||
/** 화면을 버릴 때 — 줄 쌓기 창 크기 듣기 해제 */
|
||||
destroy: () => void;
|
||||
}
|
||||
|
||||
export async function mountM01LogicLab(
|
||||
@@ -512,5 +514,5 @@ export async function mountM01LogicLab(
|
||||
hideLoadingOverlay();
|
||||
}
|
||||
setLogicOpener((key) => void openKeyOn(key));
|
||||
return { openKey: openKeyOn };
|
||||
return { openKey: openKeyOn, destroy: stack.destroy };
|
||||
}
|
||||
|
||||
@@ -64,7 +64,11 @@ const MACHINE_BACK = "m01.machine.back";
|
||||
const machineUrl = (target?: string): string =>
|
||||
`#/${ROUTES.M01_MASTER_DATA}${target ? `?machine=${encodeURIComponent(target)}` : ""}`;
|
||||
|
||||
let lastLogic: LogicHandle | null = null;
|
||||
|
||||
export async function renderM01MasterData(root: HTMLElement): Promise<void> {
|
||||
lastLogic?.destroy(); // 지난 화면의 줄 쌓기 창 크기 듣기 해제
|
||||
lastLogic = null;
|
||||
const user = await fetchSessionUser().catch(() => null);
|
||||
if (user?.role !== "SYSTEM_ADMIN") {
|
||||
showToast(L("M01_AdminOnly"), "error");
|
||||
@@ -300,6 +304,7 @@ function buildPage(): HTMLElement {
|
||||
void import("./M01_MasterData_UI_LogicLab").then(async (m) => {
|
||||
const pending = takePendingLogicKey();
|
||||
logicHandle = await m.mountM01LogicLab(logicHost, side, pending ?? undefined);
|
||||
lastLogic = logicHandle;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -36,16 +36,22 @@ const T = {
|
||||
const tx = (k: keyof typeof T): string => T[k][currentLanguageIndex === 1 ? 1 : 0];
|
||||
const KINDS = ["기계경비식", "작업량 틀", "계수식"] as const;
|
||||
|
||||
/** 읽기 창은 앱 하나 — 창 크기 듣기가 부품 칸을 그릴 때마다 늘지 않음 */
|
||||
let partsStack: ReturnType<typeof createStackScreen> | null = null;
|
||||
|
||||
/** 표 아래 부품 칸 — 기계(상세구분 있음) · 계수만 · 그 밖 = 비움 */
|
||||
export function renderParts(host: HTMLElement, pick: Pick, openLogic: (key: string) => void): void {
|
||||
host.replaceChildren();
|
||||
const group = pick.group === "계수" ? "계수식" : pick.group === "기계" ? "기계" : "";
|
||||
if (!group || (group === "기계" && !pick.detail)) return;
|
||||
let stack: ReturnType<typeof createStackScreen> | null = null;
|
||||
/** 줄 쌓기 읽기 창 — 고침 없음 · [단가산출 기초에서 열기] = 수식 탭에서 고침 */
|
||||
const show = (p: Part): void => {
|
||||
stack ??= createStackScreen({ base: "/m01/logic/doc", admin: false, cache: "m01_parts_view" });
|
||||
const view = stack;
|
||||
partsStack ??= createStackScreen({
|
||||
base: "/m01/logic/doc",
|
||||
admin: false,
|
||||
cache: "m01_parts_view",
|
||||
});
|
||||
const view = partsStack;
|
||||
openModal({
|
||||
title: `${p.키} · ${p.이름}`,
|
||||
closeLabel: tx("Close"),
|
||||
|
||||
@@ -490,6 +490,7 @@ export function mountSangeunDetail(
|
||||
destroy: () => {
|
||||
alive = false;
|
||||
if (tabs.dirty()) void tabs.discard(); // 페이지가 버리고 떠남 — 수식 캐시도 비움
|
||||
tabs.destroy();
|
||||
host.replaceChildren();
|
||||
},
|
||||
};
|
||||
|
||||
@@ -48,6 +48,8 @@ export function createSangeunTabs(
|
||||
dirty: () => boolean;
|
||||
save: () => Promise<boolean>;
|
||||
discard: () => Promise<void>;
|
||||
/** 줄 쌓기 화면의 창 크기 듣기 해제 */
|
||||
destroy: () => void;
|
||||
} {
|
||||
const tools = el("span", { className: "m02-sk__tools", attrs: { "data-sk-tools": "" } }); // [단가 갱신] · [재생성](808-1)
|
||||
const stack = createStackScreen({
|
||||
@@ -78,5 +80,6 @@ export function createSangeunTabs(
|
||||
dirty: () => stack.dirty(),
|
||||
save: () => stack.save(),
|
||||
discard: () => stack.discard(),
|
||||
destroy: () => stack.destroy(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/* 854-3 헬퍼 — 줄 쌓기 화면 열고 닫기를 되풀이해도 창 크기 듣기가 안 늘고 · M01 화면 들어올 때 상세 길이 M01 로 돌아옴
|
||||
* 가짜 DOM · 진짜 코드(line_stack_screen · Sangeun_Tabs · M01 Logic_Api · M01 Page) · 나머지 이웃 파일은 빈 부품 */
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const ROOT = path.resolve(__dirname, "..", "..");
|
||||
const ts = require(path.join(ROOT, "config", "node_modules", "typescript"));
|
||||
|
||||
class Fake {
|
||||
constructor(tag) {
|
||||
this.tagName = String(tag).toUpperCase();
|
||||
this.children = [];
|
||||
this.parentElement = null;
|
||||
this.dataset = {};
|
||||
this.style = { setProperty() {} };
|
||||
this.offsetHeight = 0;
|
||||
this.clientHeight = 0;
|
||||
this.hidden = false;
|
||||
}
|
||||
append(...xs) {
|
||||
for (const x of xs) if (x instanceof Fake) (x.parentElement = this), this.children.push(x);
|
||||
}
|
||||
replaceChildren(...xs) {
|
||||
this.children = [];
|
||||
this.append(...xs);
|
||||
}
|
||||
addEventListener() {}
|
||||
setAttribute() {}
|
||||
}
|
||||
|
||||
let listeners = 0; // window 의 resize 듣기 수
|
||||
globalThis.window = globalThis;
|
||||
globalThis.addEventListener = (type) => type === "resize" && listeners++;
|
||||
globalThis.removeEventListener = (type) => type === "resize" && listeners--;
|
||||
globalThis.getComputedStyle = () => ({ overflowY: "visible" });
|
||||
globalThis.innerHeight = 800;
|
||||
globalThis.HTMLElement = Fake;
|
||||
globalThis.document = { createElement: (t) => new Fake(t), body: new Fake("body") };
|
||||
globalThis.sessionStorage = { getItem: () => null, setItem() {}, removeItem() {} };
|
||||
|
||||
const empty = () => new Proxy(function () {}, { get: (_, k) => (k === "then" ? undefined : empty()), apply: () => undefined });
|
||||
const own = {
|
||||
ui_template_elements: { showToast() {}, el: (tag, o = {}) => { const n = new Fake(tag); n.append(...(o.children ?? [])); return n; } },
|
||||
};
|
||||
|
||||
function makeLoader(stubs) {
|
||||
const cache = new Map();
|
||||
const resolve = (from, p) => {
|
||||
if (p.startsWith("@ui/")) return path.join(ROOT, "ui_template", `${p.slice(4)}.ts`);
|
||||
if (p.startsWith("@config/")) return path.join(ROOT, "config", `${p.slice(8)}.ts`);
|
||||
if (p.startsWith(".")) return `${path.resolve(path.dirname(from), p)}.ts`;
|
||||
return null;
|
||||
};
|
||||
function load(at) {
|
||||
if (cache.has(at)) return cache.get(at);
|
||||
const js = ts.transpileModule(fs.readFileSync(at, "utf8"), {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||
}).outputText;
|
||||
const box = { exports: {} };
|
||||
cache.set(at, box.exports);
|
||||
const need = (p) => {
|
||||
const name = path.basename(p);
|
||||
if (p.endsWith(".css")) return {};
|
||||
if (stubs[name]) return stubs[name];
|
||||
const r = resolve(at, p);
|
||||
// 읽어 올 몸 = 진짜 · 그 밖 = 빈 부품
|
||||
return r && real.has(path.basename(r, ".ts")) ? load(r) : empty();
|
||||
};
|
||||
new Function("exports", "module", "require", js)(box.exports, box, need);
|
||||
return box.exports;
|
||||
}
|
||||
return (rel) => load(path.join(ROOT, rel));
|
||||
}
|
||||
const real = new Set([
|
||||
"line_stack_screen",
|
||||
"M02_MasterTemplete_Sangeun_Tabs",
|
||||
"M01_MasterData_UI_Logic_Api",
|
||||
"M01_MasterData_UI_Page",
|
||||
]);
|
||||
const state = { user: null };
|
||||
const load = makeLoader({
|
||||
...own,
|
||||
A06_Login_Api_Fetch: { fetchSessionUser: async () => state.user },
|
||||
});
|
||||
|
||||
const out = { screen: [], tabs: [], page: {} };
|
||||
|
||||
// ① 줄 쌓기 화면 — 열고 닫기 다섯 번
|
||||
const { createStackScreen } = load("A00_Common/line_stack_screen.ts");
|
||||
const base = listeners;
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const s = createStackScreen({ base: "/m01/logic/doc", admin: false, cache: "x" });
|
||||
out.screen.push(listeners - base); // 열린 동안 +1
|
||||
s.destroy();
|
||||
out.screen.push(listeners - base);
|
||||
}
|
||||
|
||||
// ② M02 단가산출 줄 쌓기 그릇 — 열고 닫기 다섯 번
|
||||
const { createSangeunTabs } = load("M02_MasterTemplete/M02_MasterTemplete_Sangeun_Tabs.ts");
|
||||
const b2 = listeners;
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const t = createSangeunTabs(new Fake("div"), { edit: false, scope: { layer: "system", owner: null } });
|
||||
out.tabs.push(listeners - b2);
|
||||
t.destroy();
|
||||
out.tabs.push(listeners - b2);
|
||||
}
|
||||
|
||||
// ③ M01 화면에 들어오면 상세 길이 M01 기본으로
|
||||
const api = load("M01_MasterData/M01_MasterData_UI_Logic_Api.ts");
|
||||
api.setLogicApiPaths({ read: "/m02/logic-lib", calc: "/m02/logic-lib" });
|
||||
out.page.before = api.logicApiPaths().read;
|
||||
const { renderM01MasterData } = load("M01_MasterData/M01_MasterData_UI_Page.ts");
|
||||
renderM01MasterData(new Fake("div")).then(() => {
|
||||
out.page.after = api.logicApiPaths().read;
|
||||
console.log(JSON.stringify(out));
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""PLAN 854-3 — 줄 쌓기 창 크기 듣기 해제(가짜 DOM · 진짜 코드).
|
||||
|
||||
① 줄 쌓기 화면 · M02 단가산출 그릇 = 열고 닫기를 다섯 번 되풀이해도 열린 동안 하나 · 닫으면 0
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def _run() -> dict:
|
||||
proc = subprocess.run(
|
||||
["node", os.path.join(HERE, "helper_854_3_screen_leak.cjs")],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
)
|
||||
assert proc.returncode == 0, proc.stderr[-3000:]
|
||||
return json.loads(proc.stdout)
|
||||
|
||||
|
||||
def test_listeners_do_not_grow_and_m01_path_returns() -> None:
|
||||
got = _run()
|
||||
assert got["screen"] == [1, 0] * 5
|
||||
assert got["tabs"] == [1, 0] * 5
|
||||
Reference in New Issue
Block a user