dompdf/dompdf · error · Exception

Parent table not found for table row group

Error message

Parent table not found for table row group

What it means

Thrown at the tail of TableRowGroup::reflow(): a tbody-like group reads its final size and position from the ancestor table's cellmap, found via TableFrameDecorator::find_parent_table(). When no table ancestor exists, the group frame is orphaned and the exception aborts render(). Same family as the row/cell 'Parent table not found' errors, one level up the table structure.

Source

Thrown at src/FrameReflower/TableRowGroup.php:66

        foreach ($frame->get_children() as $child) {
            $child->set_containing_block($cb["x"], $cb["y"], $cb["w"], $cb["h"]);
            $child->reflow();

            // Check if a split has occurred
            $page->check_page_break($child);

            if ($page->is_full()) {
                break;
            }
        }

        if ($page->is_full() && $dompdf_generated && $frame->get_parent() === null) {
            return;
        }

        $table = TableFrameDecorator::find_parent_table($frame);
        if ($table === null) {
            throw new Exception("Parent table not found for table row group");
        }
        $cellmap = $table->get_cellmap();

        // Stop reflow if a page break has occurred before the frame, in which
        // case it is not part of its parent table's cell map yet
        if ($page->is_full() && !$cellmap->frame_exists_in_cellmap($frame)) {
            return;
        }

        $style->set_used("width", $cellmap->get_frame_width($frame));
        $style->set_used("height", $cellmap->get_frame_height($frame));

        $frame->set_position($cellmap->get_frame_position($frame));
    }
}

View on GitHub (pinned to b14267808b)

Solutions

  1. Fix the source HTML so every <tbody> is inside <table>
  2. Run user content through an HTML5 normalizer (tidy, masterminds/html5) before load_html()
  3. Avoid page-break-inside:avoid on very large tbody groups that must split across pages
  4. Update dompdf to benefit from row-group split fixes

Example fix

// before
$html = '<tbody><tr><td>a</td></tr></tbody>';

// after
$html = '<table><tbody><tr><td>a</td></tr></tbody></table>';
Defensive patterns

Strategy: validation

Validate before calling

function rowGroupsHaveTables(string $html): bool {
    $doc = new DOMDocument();
    $doc->loadHTML($html, LIBXML_NOWARNING | LIBXML_NOERROR);
    foreach ($doc->getElementsByTagName('tbody') as $tb) {
        for ($n = $tb->parentNode; $n !== null; $n = $n->parentNode) {
            if (strtolower($n->nodeName) === 'table') continue 2;
        }
        return false;
    }
    return true;
}

Try / catch

try {
    $dompdf->render();
} catch (\Exception $e) {
    if (str_contains($e->getMessage(), 'Parent table not found for table row group')) {
        throw new DocumentValidationException('Malformed table: row group outside table.', 0, $e);
    }
    throw $e;
}

Prevention

When it happens

Trigger: A display:table-row-group frame (a <tbody>, or element styled that way) is reflowed without any table ancestor — stray <tbody> in markup, or a group frame detached from its table during page-break/split handling. Note the preceding code already returns early for dompdf-generated groups on full pages, so this throw is for genuinely table-less groups.

Common situations: Templates or sanitizers that strip <table> but leave <tbody>; HTML built by string concatenation where the opening <table> tag is lost; page-break-inside:avoid on large tbody groups triggering split edge cases in older dompdf builds.

Related errors


AI-assisted analysis of dompdf/dompdf@b14267808b (2026-08-21). Data as JSON: /api/errors/3c83a0cc8c6cdfab. Report an issue: GitHub.