Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 4, 2026

The entities package uses String.prototype.substr(), which was removed from modern JavaScript engines including Hermes (default in React Native/Expo 54). This causes TypeError: str.charAt is not a function when importing echarts v6.

Changes

  • Removed entities dependency from package.json
  • Implemented custom encodeXML function in src/svg/SVGCore.ts using substring() instead of deprecated substr()
  • Maintains identical XML entity encoding behavior (special chars → named entities, non-ASCII → hex references)

Implementation

// Before: import { encodeXML } from 'entities';

// After: Custom implementation
function encodeXML(str: string): string {
  let ret = '';
  let lastIdx = 0;
  let match;
  while ((match = xmlReplacer.exec(str)) !== null) {
    // ... encoding logic
    ret += str.substring(lastIdx, i); // Uses substring() not substr()
  }
  return ret + str.substring(lastIdx); // Fixed: was str.substr(lastIdx)
}

This affects only SVG text node encoding for React Native SVG/Skia rendering.

Original prompt

This section details on the original issue you should resolve

<issue_title>TypeError: str.charAt is not a function (it is undefined)</issue_title>
<issue_description>I am upgrading my project from expo 53 to expo 54,
in upgrade process, I am upgrading
@wuba/react-native-echarts from ^2.0.3 to latest
echarts from v5 to v6
and also skia

When build is successful and I try to run application, I get following error:

TypeError: str.charAt is not a function (it is undefined)

And it points to echarts import statement.

Image</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 4, 2026 10:22
- Remove entities dependency from package.json
- Add custom encodeXML function in SVGCore.ts that uses substring instead of deprecated substr
- Fixes TypeError when using echarts v6 with Expo 54 and React Native with Hermes

Co-authored-by: zhiqingchen <[email protected]>
Copilot AI changed the title [WIP] Fix TypeError related to echarts import after upgrade Replace entities package to fix TypeError with Hermes/Expo 54 Jan 4, 2026
Copilot AI requested a review from zhiqingchen January 4, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: str.charAt is not a function (it is undefined)

2 participants