-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-node-tree-minimal.html
More file actions
398 lines (334 loc) · 15.1 KB
/
debug-node-tree-minimal.html
File metadata and controls
398 lines (334 loc) · 15.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🚨 NodeTreeView 緊急デバッグ - 最小限テスト</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
margin: 20px;
background: #f0f0f0;
}
.debug-controls {
background: #fff;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
border: 2px solid #dc3545;
}
.test-container {
background: #fff;
padding: 20px;
border-radius: 8px;
border: 1px solid #ddd;
min-height: 400px;
}
.memory-monitor {
position: fixed;
top: 10px;
right: 10px;
background: #dc3545;
color: white;
padding: 10px;
border-radius: 4px;
font-weight: bold;
z-index: 9999;
}
button {
margin: 5px;
padding: 8px 16px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.btn-danger { background: #dc3545; color: white; }
.btn-primary { background: #007bff; color: white; }
.btn-success { background: #28a745; color: white; }
.btn-warning { background: #ffc107; color: black; }
.log-output {
background: #f8f9fa;
border: 1px solid #ddd;
padding: 10px;
margin-top: 10px;
max-height: 200px;
overflow-y: auto;
font-family: 'Courier New', monospace;
font-size: 12px;
}
</style>
</head>
<body>
<div class="memory-monitor" id="memoryMonitor">
Memory: Monitoring...
</div>
<h1>🚨 NodeTreeView 緊急デバッグ - 段階的テスト</h1>
<div class="debug-controls">
<h3>⚠️ 危険!メモリリーク調査中</h3>
<p><strong>注意:</strong> 各テストは慎重に実行してください。メモリ暴走の可能性があります。</p>
<div>
<button class="btn-primary" onclick="testPhase1()">Phase 1: 基本DOM生成</button>
<button class="btn-primary" onclick="testPhase2()">Phase 2: 最小ツリー構造</button>
<button class="btn-warning" onclick="testPhase3()">Phase 3: イベントリスナー追加</button>
<button class="btn-danger" onclick="testPhase4()">Phase 4: renderTree()実行</button>
</div>
<div style="margin-top: 10px;">
<button class="btn-success" onclick="clearTest()">🧹 テスト領域クリア</button>
<button class="btn-danger" onclick="forceGC()">🗑️ 強制ガベージコレクション</button>
<button class="btn-danger" onclick="stopAllTimers()">⏹️ 全タイマー停止</button>
</div>
</div>
<div class="test-container" id="testContainer">
<p>テスト領域 - ここに段階的にNodeTreeView要素を生成します</p>
</div>
<div class="log-output" id="logOutput"></div>
<script>
// グローバル変数
let memoryMonitorInterval = null;
let activeTimers = new Set();
let activeIntervals = new Set();
let testPhase = 0;
let testData = {
nodes: new Map(),
expandedNodes: new Set(),
selectedNodes: new Set()
};
// メモリ監視開始
function startMemoryMonitor() {
memoryMonitorInterval = setInterval(() => {
if (performance.memory) {
const used = Math.round(performance.memory.usedJSHeapSize / 1024 / 1024);
const total = Math.round(performance.memory.totalJSHeapSize / 1024 / 1024);
document.getElementById('memoryMonitor').textContent =
`Memory: ${used}MB / ${total}MB`;
// 危険レベル警告
if (used > 100) {
document.getElementById('memoryMonitor').style.background = '#dc3545';
if (used > 500) {
log(`🚨 CRITICAL: Memory usage ${used}MB!`, 'error');
}
} else {
document.getElementById('memoryMonitor').style.background = '#28a745';
}
}
}, 1000);
}
// ログ出力
function log(message, type = 'info') {
const timestamp = new Date().toISOString().substr(11, 12);
const logOutput = document.getElementById('logOutput');
const color = type === 'error' ? '#dc3545' : type === 'warn' ? '#ffc107' : '#28a745';
logOutput.innerHTML += `<div style="color: ${color}">[${timestamp}] ${message}</div>`;
logOutput.scrollTop = logOutput.scrollHeight;
console.log(`[NodeTreeDebug] ${message}`);
}
// Phase 1: 基本DOM生成テスト
function testPhase1() {
log('🧪 Phase 1: 基本DOM生成テスト開始');
testPhase = 1;
try {
const container = document.getElementById('testContainer');
container.innerHTML = `
<div class="node-tree-minimal" style="
background: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 20px;
max-width: 350px;
">
<h4>🌳 NodeTreeView 最小版</h4>
<div class="tree-content">
<p>基本DOM構造生成完了</p>
<div>Memory Check: 基本要素のみ</div>
</div>
</div>
`;
log('✅ Phase 1 完了: 基本DOM要素生成成功');
} catch (error) {
log(`❌ Phase 1 失敗: ${error.message}`, 'error');
}
}
// Phase 2: 最小ツリー構造テスト
function testPhase2() {
log('🧪 Phase 2: 最小ツリー構造テスト開始');
testPhase = 2;
try {
// テストデータ作成
testData.nodes.clear();
testData.nodes.set('node-1', {
id: 'node-1',
name: 'Test Node 1',
type: 'test',
children: []
});
testData.nodes.set('node-2', {
id: 'node-2',
name: 'Test Node 2',
type: 'test',
children: []
});
const container = document.getElementById('testContainer');
let treeHTML = '<div class="tree-nodes">';
for (const [id, node] of testData.nodes) {
treeHTML += `
<div class="tree-node" data-node-id="${id}" style="
padding: 8px;
margin: 4px 0;
background: #ffffff;
border: 1px solid #ddd;
border-radius: 4px;
cursor: pointer;
">
📦 ${node.name} (${node.type})
</div>
`;
}
treeHTML += '</div>';
container.innerHTML = `
<div class="node-tree-minimal">
<h4>🌳 NodeTreeView - ツリー構造</h4>
${treeHTML}
<div style="margin-top: 10px; font-size: 12px; color: #666;">
ノード数: ${testData.nodes.size}
</div>
</div>
`;
log(`✅ Phase 2 完了: ${testData.nodes.size}個のノード生成成功`);
} catch (error) {
log(`❌ Phase 2 失敗: ${error.message}`, 'error');
}
}
// Phase 3: イベントリスナー追加テスト(⚠️注意)
function testPhase3() {
log('🧪 Phase 3: イベントリスナー追加テスト開始');
testPhase = 3;
try {
// 既存のリスナーをクリア
const oldNodes = document.querySelectorAll('.tree-node');
oldNodes.forEach(node => {
// 新しい要素で置き換えてリスナークリア
const newNode = node.cloneNode(true);
node.parentNode.replaceChild(newNode, node);
});
// 新しいリスナー追加
const treeNodes = document.querySelectorAll('.tree-node');
let listenerCount = 0;
treeNodes.forEach(node => {
const nodeId = node.dataset.nodeId;
// クリックリスナー
const clickHandler = (e) => {
log(`🖱️ Node clicked: ${nodeId}`);
node.style.background = node.style.background === 'rgb(227, 242, 253)' ? '#ffffff' : '#e3f2fd';
};
node.addEventListener('click', clickHandler);
listenerCount++;
});
log(`✅ Phase 3 完了: ${listenerCount}個のイベントリスナー追加成功`);
log('💡 ノードをクリックしてテストしてください');
} catch (error) {
log(`❌ Phase 3 失敗: ${error.message}`, 'error');
}
}
// Phase 4: renderTree()模擬実行(🚨危険)
function testPhase4() {
log('🚨 Phase 4: renderTree()模擬実行開始 - 危険テスト!');
testPhase = 4;
if (!confirm('⚠️ 警告: この操作はメモリリークを引き起こす可能性があります。続行しますか?')) {
log('❌ Phase 4 キャンセル: ユーザーによる中断');
return;
}
try {
let renderCount = 0;
const maxRenders = 10; // 安全のため制限
function mockRenderTree() {
renderCount++;
log(`🔄 Render ${renderCount}/${maxRenders}`);
if (renderCount >= maxRenders) {
log('✅ Phase 4 完了: 制限回数到達で自動停止');
return;
}
// DOM要素再生成(問題の可能性箇所)
const container = document.getElementById('testContainer');
const treeContainer = container.querySelector('.tree-nodes');
if (treeContainer) {
treeContainer.innerHTML = '';
// ノード再生成
for (const [id, node] of testData.nodes) {
const nodeElement = document.createElement('div');
nodeElement.className = 'tree-node';
nodeElement.dataset.nodeId = id;
nodeElement.style.cssText = `
padding: 8px;
margin: 4px 0;
background: #ffffff;
border: 1px solid #ddd;
border-radius: 4px;
cursor: pointer;
`;
nodeElement.innerHTML = `📦 ${node.name} (${node.type}) - Render ${renderCount}`;
treeContainer.appendChild(nodeElement);
}
// 🚨 危険: タイマーによる再帰実行(NodeTreeViewの問題模擬)
const timerId = setTimeout(() => {
mockRenderTree(); // 再帰呼び出し
}, 100);
activeTimers.add(timerId);
}
}
// 初回実行
mockRenderTree();
} catch (error) {
log(`❌ Phase 4 失敗: ${error.message}`, 'error');
}
}
// テスト領域クリア
function clearTest() {
log('🧹 テスト領域クリア実行');
// タイマー全停止
stopAllTimers();
// DOM クリア
document.getElementById('testContainer').innerHTML = '<p>テスト領域 - クリア完了</p>';
// データクリア
testData.nodes.clear();
testData.expandedNodes.clear();
testData.selectedNodes.clear();
testPhase = 0;
log('✅ テスト領域クリア完了');
}
// 強制ガベージコレクション
function forceGC() {
if (window.gc) {
window.gc();
log('🗑️ 強制ガベージコレクション実行');
} else {
log('⚠️ ガベージコレクション利用不可 (Chrome: --js-flags="--expose-gc")', 'warn');
}
}
// 全タイマー停止
function stopAllTimers() {
log(`⏹️ アクティブタイマー停止: ${activeTimers.size}個`);
activeTimers.forEach(timerId => {
clearTimeout(timerId);
});
activeTimers.clear();
activeIntervals.forEach(intervalId => {
clearInterval(intervalId);
});
activeIntervals.clear();
log('✅ 全タイマー停止完了');
}
// 初期化
document.addEventListener('DOMContentLoaded', () => {
log('🚀 NodeTreeView デバッグツール初期化完了');
startMemoryMonitor();
});
// ページ離脱時のクリーンアップ
window.addEventListener('beforeunload', () => {
stopAllTimers();
if (memoryMonitorInterval) {
clearInterval(memoryMonitorInterval);
}
});
</script>
</body>
</html>