Skip to content

"[object Object]" text rendered in slides with empty text runs #15

Description

@Gabe-IncentFit

Description

The PPTX preview is rendering the literal text [object Object] in slides where empty <a:t> (text) elements exist in the PPTX XML. This occurs when a text run (<a:r>) contains an empty text element.

Root Cause

The bug is in the text extraction code within the pptx-preview library (v1.0.2). When parsing PPTX XML, the library extracts text using:

t.text = Y.get(e, "a:t") || ""

The issue is that when an <a:t></a:t> element is empty, the Y.get helper function returns an object instead of an empty string or null. Since objects are truthy in JavaScript, the || "" fallback never triggers, and the object is stored as the text value.

Later, when rendering this text with s.innerHTML = i (where i = r.text), JavaScript's implicit string conversion turns the object into the literal string "[object Object]", which is then displayed in the slide.

Example XML

Here's the XML structure that triggers this bug:

<a:p>
  <a:r>
    <a:rPr lang="en-US" sz="2800" dirty="0">
      <a:solidFill>
        <a:srgbClr val="1F3864"/>
      </a:solidFill>
      <a:latin typeface="DM Sans"/>
      <a:ea typeface="DM Sans"/>
      <a:cs typeface="DM Sans"/>
    </a:rPr>
    <a:t></a:t>  <!-- Empty text element returns object instead of empty string -->
  </a:r>
  <a:endParaRPr lang="en-US" dirty="0"/>
</a:p>

Expected Behavior

Empty <a:t> elements should render as empty strings (no visible text).

Actual Behavior

Empty <a:t> elements render as the literal text [object Object].

Recommended Solution

Ensure the text value is always coerced to a string:

Option 1 - Explicit String conversion:

t.text = String(Y.get(e, "a:t") || "")

Option 2 - String concatenation:

t.text = (Y.get(e, "a:t") || "") + ""

Option 3 - Type checking:

var textValue = Y.get(e, "a:t");
t.text = typeof textValue === "string" ? textValue : "";

Any of these approaches will ensure that objects are converted to strings and empty/null values become empty strings.

Workaround

Until this is fixed, the workaround is to ensure PPTX files don't contain empty <a:t></a:t> elements. However, this is difficult to control as various PowerPoint operations can create these elements.

Screenshot

Image

Additional Context

This issue is similar to the line break bug reported in issue #[number] where <a:br> elements render as "undefined". Both stem from the same underlying problem: the rendering code doesn't properly handle non-string values returned by the XML parser.

Environment

  • Library: pptx-preview v1.0.2 (via @vue-office/pptx v1.0.1)
  • Browser: [All browsers affected]
  • PPTX format: Office Open XML (.pptx)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions