Skip to content

Fix style tag accumulation when loading dialogs#179

Merged
EndoHizumi merged 5 commits intomainfrom
copilot/fix-incrementing-style-tags
Mar 22, 2026
Merged

Fix style tag accumulation when loading dialogs#179
EndoHizumi merged 5 commits intomainfrom
copilot/fix-incrementing-style-tags

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 22, 2025

Style tags were accumulating in document.head each time a dialog was loaded, causing the style sheet to grow indefinitely.

Root Cause

In loadScreen(), old style tags were removed only for regular scenes, but new style tags were always appended regardless of whether it was a dialog or regular scene:

if (!isDialog) {
  // Remove old style tags
  const styleTags = document.head.getElementsByTagName('style')
  for (const styleTag of styleTags) {
    document.head.removeChild(styleTag)
  }
}
// But always append new style tag
const styleElement = doc.head.getElementsByTagName('style')[0]
document.head.appendChild(styleElement)  // ← Appends every time

This caused dialog styles to accumulate, and dialogs also need their own styles to render properly.

Changes

For regular scenes (!isDialog):

  • Remove ALL style tags
  • Add the new style tag
  • Added null check for templates without style tags

For dialogs (isDialog):

  • Remove only old dialog style tags (marked with data-dialog-style attribute)
  • Add new dialog style tag with data-dialog-style="true" marker
  • This prevents accumulation while ensuring dialog styles are properly applied
if (!isDialog) {
  // Remove old style tags
  const styleTags = document.head.getElementsByTagName('style')
  for (const styleTag of styleTags) {
    document.head.removeChild(styleTag)
  }
  this.gameContainer.innerHTML = mainDiv.innerHTML
  this.drawer.setScreen(this.gameContainer, engineConfig.resolution)
  // Only append style tag for regular scenes
  const styleElement = doc.head.getElementsByTagName('style')[0]
  if (styleElement) {
    document.head.appendChild(styleElement)
  }
} else {
  // ダイアログの場合、古いダイアログ用のスタイルを削除する
  const oldDialogStyles = document.head.querySelectorAll('style[data-dialog-style]')
  oldDialogStyles.forEach((styleTag) => {
    document.head.removeChild(styleTag)
  })
  this.gameContainer.appendChild(mainDiv)
  // ダイアログ用のStyleタグを取り出して、マークを付けてheadタグに追加する
  const styleElement = doc.head.getElementsByTagName('style')[0]
  if (styleElement) {
    styleElement.setAttribute('data-dialog-style', 'true')
    document.head.appendChild(styleElement)
  }
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Styleタグが増殖する</issue_title>
<issue_description>


Trelloから移行 (doing): https://trello.com/c/J1KHS9hw</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits December 22, 2025 04:56
Co-authored-by: EndoHizumi <5486808+EndoHizumi@users.noreply.github.com>
Co-authored-by: EndoHizumi <5486808+EndoHizumi@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue of proliferating style tags Fix style tag accumulation when loading dialogs Dec 22, 2025
Copilot AI requested a review from EndoHizumi December 22, 2025 05:00
@EndoHizumi EndoHizumi marked this pull request as ready for review March 22, 2026 15:51
Copy link
Copy Markdown
Owner

@EndoHizumi EndoHizumi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot ダイアログ表示時に古いスタイルが残ってるので、修正をお願いします。

Co-authored-by: EndoHizumi <5486808+EndoHizumi@users.noreply.github.com>
Agent-Logs-Url: https://github.com/EndoHizumi/webTaleKit/sessions/a2bf2795-d1ae-4666-9c20-6a7d7f86b958
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
webtalekit-demo Error Error Mar 22, 2026 4:49pm

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 22, 2026

@copilot ダイアログ表示時に古いスタイルが残ってるので、修正をお願いします。

修正しました。ダイアログのスタイルタグに data-dialog-style マーカーを追加し、新しいダイアログを表示する際に古いダイアログのスタイルを削除するようにしました。これにより、ダイアログのスタイルが正しく適用されながら、古いスタイルが残らないようになります。(commit: bb04104)

Copy link
Copy Markdown
Owner

@EndoHizumi EndoHizumi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@EndoHizumi EndoHizumi merged commit af9c966 into main Mar 22, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Styleタグが増殖する

2 participants