mapbox / mapbox/mapbox-gl-js

Mapbox Expression using ["format", <TEXT>, {"text-color": "<COLOR>"}] causes toRenderColor error

Open
#13,340 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

**See demo video below of error** which occurs in mapbox studio and on my live map app.

**The cause of the bug**
appears to be the `text-filed` attribute in mapbox studio, which makes use of the mapbox expression [format](https://docs.mapbox.com/style-spec/reference/expressions/#types-format)

The expression 👇
```
[
"case",
[
"all",
["has", "name"],
["has", "name_en"],
[
"!=",
["get", "name"],
["get", "name_en"]
]
],
[
"format",
["get", "name_en"],
{
"font-scale": 1
},
"\n",
["get", "name"],
{
"font-scale": 0.8,
"text-color": "grey"
}
],
["format", ["get", "name"]]
]
```

The error it causes 👇
```
Uncaught TypeError: r.toRenderColor is not a function
at o_._setPaintValue (147.ddd73483.js:8:36290)
at o_.updatePaintArray (147.ddd73483.js:8:36196)
at 147.ddd73483.js:8:41263
```

If I remove the `"text-color": "grey"` condition from the format statement, the error does not occur.

https://github.com/user-attachments/assets/c4e1fa31-84f5-4f72-81f7-0d010871fc22

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied format expression in the mapbox-gl-js rendering path and compare it with the version without text-color. Start from the reported _setPaintValue and updatePaintArray stack trace; done means the expression no longer raises the toRenderColor error and the case is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.