Skip to content

Angular SSR critical CSS inlining can exhaust memory with deeply nested HTML #34157

Closed as not planned
made-in-common/beasties
#435

Description

@SkyZeroZx

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Angular SSR can exhaust the Node.js heap while inlining critical CSS when server-rendered HTML contains deeply nested elements that match descendant selectors from the application's stylesheet.

This can happen with a normal sanitized [innerHTML] binding.

Minimal Reproduction

For example:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `<article class="rich-text" [innerHTML]="content"></article>`,
})
export class App {
  readonly content = '<ul>'.repeat(674);
}

The application stylesheet only needs normal descendant selectors. The reproduction uses nested-list rules similar to:

$list-nesting-depth: 8;

@function nested-lists($levels) {
  $selector: '';

  @for $i from 1 through $levels {
    $selector: '#{$selector} ul';
  }

  @return $selector;
}

@for $level from 1 through $list-nesting-depth {
  .rich-text#{nested-lists($level)} li {
    margin-top: 0.2em;

    p {
      margin: 0 0 0.4em;
    }

    code {
      padding: 0.15em 0.4em;
    }

    blockquote {
      padding-left: 1em;
    }

    .mention {
      font-weight: 600;
    }

    .badge {
      padding: 0 0.6em;
    }

    .footnote-ref {
      vertical-align: super;
    }

    .task-list-item {
      list-style-type: none;
    }
  }
}

With optimization.styles.inlineCritical enabled, a single request containing 2,696 bytes of nested <ul> markup consistently terminates a worker using a 512 MiB V8 heap:

FATAL ERROR: Ineffective mark-compacts near heap limit
Allocation failed - JavaScript heap out of memory

An equal-size control only changes the tag:

candidate: '<ul>'.repeat(674)
control:   '<ol>'.repeat(674)

Both inputs have the same nesting depth, element count, payload size and Angular sanitization path.

Exception or Error


Your Environment

Angular 22.2.0

More context : https://issuetracker.google.com/issues/564537085

Activity

  1. added
    gemini-triaged
    on Sep 24, 2026
  2. added this to the needsTriage milestone on Sep 24, 2026
  3. alan-agius4 commented on Sep 24, 2026

    @alan-agius4
    Collaborator

    This is a not caused by Angular, this is a 3rd party dependency issue.

  4. angular-automatic-lock-bot commented on Oct 25, 2026

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  5. locked and limited conversation to collaborators on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: @angular/ssrgemini-triaged

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions