Skip to content

fix: use appendChild for theme styles to win CSS cascade, remove duplicate theming in app-lob#3930

Merged
ChronosSF merged 3 commits intovnextfrom
copilot/fix-theming-widget-styles
Apr 14, 2026
Merged

fix: use appendChild for theme styles to win CSS cascade, remove duplicate theming in app-lob#3930
ChronosSF merged 3 commits intovnextfrom
copilot/fix-theming-widget-styles

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 9, 2026

The theming widget's generated <style id="igniteui-theme"> was inserted before Angular's global stylesheet (always the last <head> child), causing default styles to override theme styles in the cascade. Additionally, app-lob's DocsLayoutComponent duplicated the theming logic already owned by AppComponent, resulting in competing window:message handlers and duplicate DOM ids. createTypefaceLink() also appended a new <link> on every typeface change instead of reusing one.

Changes

  • app.component.ts — replace insertBefore(..., head.lastElementChild) with appendChild in both createThemeStyle() and createTypefaceLink(); reuse existing <link> element by id instead of appending a new one per typeface; fix misspelled id ignteui-theme-typefaceigniteui-theme-typeface
  • app.component.ts — same fixes
  • docs-layout.component.ts — removed all theming logic (ngOnInit, onMessage, createThemeStyle, createTypefaceLink, and related fields); AppComponent already owns this, aligning with the root project's DocsLayoutComponent which is a bare router outlet
// Before — inserted before Angular's stylesheet, loses cascade; new element on every call
this.document.head.insertBefore(styleEl, this.document.head.lastElementChild);
this.document.head.appendChild(styleEl); // duplicate append

// After — appended last, wins cascade; single element reused
this.document.head.appendChild(styleEl);

// Before — new <link> per typeface, duplicate ids
const typefaceElem = this.document.createElement('link');
typefaceElem.id = 'ignteui-theme-typeface'; // misspelled
this.document.head.appendChild(typefaceElem);

// After — reuse existing element
let typefaceElem = this.document.getElementById('igniteui-theme-typeface') as HTMLLinkElement;
if (!typefaceElem) {
    typefaceElem = this.document.createElement('link');
    typefaceElem.id = 'igniteui-theme-typeface';
    this.document.head.appendChild(typefaceElem);
}
typefaceElem.href = ...;

…re correct CSS cascade order

Agent-Logs-Url: https://github.com/IgniteUI/igniteui-angular-samples/sessions/b7433c38-919d-4392-a94a-cb4ae0dbede8

Co-authored-by: viktorkombov <75325639+viktorkombov@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix theming widget styles insertion order in head fix: use appendChild for theme styles to win CSS cascade Apr 9, 2026
Copilot AI requested a review from viktorkombov April 9, 2026 15:57
@viktorkombov viktorkombov requested a review from Copilot April 14, 2026 10:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts how the theming widget injects its generated theme <style> (and typeface <link>) so that theme styles appear last in <head> and therefore win in the CSS cascade over Angular’s global stylesheet.

Changes:

  • Switch theme <style id="igniteui-theme"> insertion from insertBefore(..., head.lastElementChild) to head.appendChild(...).
  • Switch typeface <link> insertion similarly to head.appendChild(...).
  • Apply the same change across the root app and app-lob variants (including DocsLayoutComponent).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/app/app.component.ts Appends injected theme style/typeface link to the end of <head> to improve cascade priority.
projects/app-lob/src/app/app.component.ts Same injection-order fix for app-lob root component.
projects/app-lob/src/app/index/docs-layout.component.ts Same injection-order fix for the docs layout component.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread projects/app-lob/src/app/app.component.ts
Comment thread projects/app-lob/src/app/app.component.ts Outdated
Comment thread projects/app-lob/src/app/index/docs-layout.component.ts Outdated
Comment thread projects/app-lob/src/app/index/docs-layout.component.ts Outdated
Comment thread src/app/app.component.ts Outdated
@viktorkombov viktorkombov changed the title fix: use appendChild for theme styles to win CSS cascade fix: use appendChild for theme styles to win CSS cascade, remove duplicate theming in app-lob Apr 14, 2026
@viktorkombov viktorkombov changed the title fix: use appendChild for theme styles to win CSS cascade, remove duplicate theming in app-lob fix: use appendChild for theme styles to win CSS cascade, remove duplicate theming in app-lob Apr 14, 2026
@viktorkombov viktorkombov marked this pull request as ready for review April 14, 2026 10:58
@viktorkombov viktorkombov requested a review from ChronosSF April 14, 2026 10:58
@ChronosSF ChronosSF merged commit 5c9f045 into vnext Apr 14, 2026
7 checks passed
@ChronosSF ChronosSF deleted the copilot/fix-theming-widget-styles branch April 14, 2026 12:49
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.

Theming widget styles not applied due to incorrect <style> insertion order

4 participants