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
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)
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-previewlibrary (v1.0.2). When parsing PPTX XML, the library extracts text using:The issue is that when an
<a:t></a:t>element is empty, theY.gethelper function returns an object instead of an empty string ornull. 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(wherei = 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:
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:
Option 2 - String concatenation:
Option 3 - Type checking:
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
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
pptx-previewv1.0.2 (via@vue-office/pptxv1.0.1)