pnp / pnp/sp-dev-fx-controls-react

[ModernTaxonomyPicker] getLabelsForCurrentLanguage returns empty array

Open
#2,028 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
433
Forks
418
Avg merge
5d 6m
Merged PRs (30d)
19

Description

Category

[ ] Enhancement

[X] Bug

[ ] Question

Version

Please specify what version of the library you are using: [3.21.0]

Observed Behavior

I noticed a crash of the DynamicForm control on my mixed language test site and traced it to the getLabelsForCurrentLanguage method of the ModernTaxonomyPicker.tsx.
After uploading some pictures to my test doc lib SharePoint added a new column called Image Tags of type TaxonomyFieldTypeMulti and assigned terms like "Screenshot". According to the data returned, the terms are labeled in German de-DE only and the only labels returned are marked as default, but the default language for the site is en-US. In the current code this will lead to no labels being found and onRenderItem to crash when accessing labels[0].name:

Image

I suggest to add more fallbacks to prevent this behavior, e.g.
let labels = item.labels.filter((name) => name.languageTag === currentLanguageTag && name.isDefault);
if (labels.length === 0) {
labels = item.labels.filter((name) => name.languageTag === currentTermStoreInfo.defaultLanguageTag && name.isDefault);
}
if (labels.length === 0) {
labels = item.labels.filter((name) => name.isDefault);
}
if (labels.length === 0) {
labels.push(item.labels[0]);
}
return labels;

Contributor guide

No contributing guide indexed for this repository

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

Start in ModernTaxonomyPicker.tsx at getLabelsForCurrentLanguage and reproduce the mixed-language taxonomy case described, where only default German labels are returned while the site language is en-US. Confirm the fallback behavior prevents onRenderItem from accessing an empty labels array, and verify the control no longer crashes.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.