Skip to content

addEditableTags cannot convert undefined or null to object in getTag #193

@mccarthyk

Description

@mccarthyk

🐛 Bug: TypeError: Cannot convert undefined or null to object in getTag function

Location:
inside the getTag function

Error message:

TypeError: Cannot convert undefined or null to object
    at Function.entries (<anonymous>)
    at getTag
    ...

💡 Root Cause

This error occurs because the check typeof obj === "object" passes for null, which is a known JavaScript quirk (i.e., typeof null === "object" is true). This results in Object.entries(null) being called, which throws a TypeError.


🔍 Where it's happening

In the getTag function:

Object.entries(content).forEach(([key, value]) => {
    ...
})

If content is null, this line throws because Object.entries(null) is invalid.


✅ Suggested Fix

Update the type check before Object.entries() to explicitly guard against null:

if (content == null) {
    return {};
}

🧪 How to Reproduce

Pass null as the content parameter to getTag:

getTag(null, 'some.prefix', true, 'en-us', { ...appliedVariants });

This will reliably produce the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions