Mapbox Expression using ["format", <TEXT>, {"text-color": "<COLOR>"}] causes toRenderColor error
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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