Apparent bug in Text component when in a ListView

I have this as my source JSON:

[{
  "project_name": "Video 12",
  "project_type": "Video Caption",
  "job_name": "Video 1",
  "tasks": [{
    "job_id": 1,
    "task_id": 4,
    "task_name": "Caption Video",
    "contractor_name": "Fred Flintsone",
    "location": null
  }]
}, {
  "project_name": "Very First Project",
  "project_type": "Video Caption",
  "job_name": "Some Job Name",
  "tasks": null
}]

Now take this Text component:

**{{source.value[1].job_name}}**
Contractor: {{source.value[1].tasks[0].contractor_name}}
Project: {{source.value[1].project_name}}
Job Type: {{source.value[1].project_type}}

tasks.contractor_name does not exist because there is no tasks record in the second element, so that entry remains blank but the component is displaying the rest of the data:

image

Now let's say we take that same Text component and put it into a ListView (change the element reference to i of course):

**{{source.value[i].job_name}}**
Contractor: {{source.value[i].tasks[0].contractor_name}}
Project: {{source.value[i].project_name}}
Job Type: {{source.value[i].project_type}}

We get this as the output:

image

Notice how that second element is simply blank? The entire component fails to display if there is an error in its Value.

Put a tasks.contractor_name in there:

[{
  "project_name": "Video 12",
  "project_type": "Video Caption",
  "job_name": "Video 1",
  "tasks": [{
    "job_id": 1,
    "task_id": 4,
    "task_name": "Caption Video",
    "contractor_name": "Fred Flintsone",
    "location": null
  }]
}, {
  "project_name": "Very First Project",
  "project_type": "Video Caption",
  "job_name": "Some Job Name",
  "tasks":  [{
    "job_id": 1,
    "task_id": 4,
    "task_name": "Caption Video",
    "contractor_name": "Fred Flintsone",
    "location": null
  }]
}]

And all is good:
image

Here is a JSON of an app that demos the problem: Dropbox - ListViewBug.json - Simplify your life

Hey @bradlymathews!

Does optional chaining fix this issue?

Yes that does work. I keep forgetting about that technique which is easier than my workaround which used a ternary.

Still a weird corner case bug though!

Anyway, I have avoided the issue for now as I have moved from ListView to Table for that App as we talked about this morning at Office Hours.

That counts as a plug for Tue/Thu office hours :grinning: :smiley:

1 Like