Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown: hard to identify error on non matching label #3038

Closed
raDiesle opened this issue Jul 6, 2022 · 13 comments · Fixed by #3041
Closed

Dropdown: hard to identify error on non matching label #3038

raDiesle opened this issue Jul 6, 2022 · 13 comments · Fixed by #3041
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@raDiesle
Copy link

raDiesle commented Jul 6, 2022

Describe the bug

On the applications, in special situations, errors happen in the following way:

this.getOptionLabel(...).toLocaleLowerCase is not a function

TypeError
  key: "matchesSearchValue",     
value: function matchesSearchValue(option) {       
var label = this.getOptionLabel(option).toLocaleLowerCase(this.props.filterLocale);       
return label.startsWith(this.searchValue.toLocaleLowerCase(this.props.filterLocale));     
} 

which is logged to the monitoring systems.

Unfortunately, its hard to understand. Instead it would be nice to print the context to value and options its trying to match to.

Its hard in the setup being able to reproduce, otherwise

Reproducer

No response

PrimeReact version

6.5.1

React version

17.x

Language

ES5

Build / Runtime

Create React App (CRA)

Browser(s)

Chrome110

Steps to reproduce the behavior

not so clear, probably when opening the dropdown with non matched value of options

Expected behavior

error is thrown, but with more understandable context information

@raDiesle raDiesle added Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible Type: Bug Issue contains a defect related to a specific component. labels Jul 6, 2022
@melloware
Copy link
Member

Can you try with 8.2.0 or create a code sandbox reproducer to show the issue? I can't reproduce with 8.2.0.

@raDiesle
Copy link
Author

raDiesle commented Jul 6, 2022

Hi, as explain the issue is, that we dont know how to reproduce it, therefore some logging of context would be helpful.

The code in 8.2.0 is still the same. e.g. if options is null, or no optionLabel can be found, it will be thrown:

const label = getOptionLabel(option).toLocaleLowerCase(props.filterLocale);

melloware added a commit to melloware/primereact that referenced this issue Jul 6, 2022
@melloware melloware removed the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jul 6, 2022
@melloware melloware self-assigned this Jul 6, 2022
@melloware melloware added this to the 9.0.0 milestone Jul 6, 2022
@melloware
Copy link
Member

OK i submitted a PR to defend against that error. If the option label is NULL it should return false and not try and lowercase it.

@raDiesle
Copy link
Author

raDiesle commented Jul 6, 2022

Nice. So what will happen in that case?

Probably to show the key value in the dropdown and console error the key , where no label was found

@melloware
Copy link
Member

melloware commented Jul 6, 2022

that method returns true or false whether a match has been found. Throwing an error is not acceptable so returning false in that case means "no match was found".

@raDiesle
Copy link
Author

raDiesle commented Jul 6, 2022

I was not saying to throw an error, but to console log an info, warn or error.

what happens in case its returning false? I guess silently show the user the key value, right ?

@melloware
Copy link
Member

No here was the original method.

const matchesSearchValue = (option) => {
        label = getOptionLabel(option).toLocaleLowerCase(props.filterLocale);
        return label.startsWith(searchValue.current.toLocaleLowerCase(props.filterLocale));
    }

If the call to getOptionLabel(option) returns undefined it will then throw the error you are seeing above trying to do toLocaleLowerCase on it which is NOT acceptable.

The fixed method does this where if the option is undefined the method returns false as its NOT a match.

const matchesSearchValue = (option) => {
        let label = getOptionLabel(option);
        if (!label) {
            return false;
        }
        label = label.toLocaleLowerCase(props.filterLocale);
        return label.startsWith(searchValue.current.toLocaleLowerCase(props.filterLocale));
    }

@raDiesle
Copy link
Author

raDiesle commented Jul 6, 2022

ye, i mean what the other code besides this function will do with the undefined. What is the final result for user and our JavaScript error logging ;)

I dont care about internal implementation, I only care about user and the logging system.

@melloware
Copy link
Member

Once again without a Code Sandbox reproducer i can only fix the item based on the stack trace you provided above that was blowing up. If you can provide a reproducer I can look into more issues. Until then I have properly fixed the defect you reported above.

@mertsincan mertsincan modified the milestones: 9.0.0, 8.3.0 Jul 18, 2022
@raDiesle
Copy link
Author

raDiesle commented Mar 23, 2023

The problem is, that we cant reproduce it, because the javascript error to send to Sentry.io has insufficient information, caused by the PrimeReact component code. Could be case that options is rerendered with old value set on the input - no idea.

Therefore I suggest to create some if statement, and provide some contextual console.error information in case the error happens inside of the component. ( What are the current options, what is the key where primereact tries to get the label from)

getOptionLabel(...).toLocaleLowerCase

@melloware
Copy link
Member

If you look in the component the only places toLocaleLowerCase() are used.

const filterValue = filterState.trim().toLocaleLowerCase(props.filterLocale);

const matchesSearchValue = (option) => {
let label = getOptionLabel(option);
if (!label) {
return false;
}
label = label.toLocaleLowerCase(props.filterLocale);
return label.startsWith(searchValue.current.toLocaleLowerCase(props.filterLocale));
};

@raDiesle
Copy link
Author

Yep I know, still it doesnt help me to understand how our users produce this error, as we miss context information of the situation, which would be possible to enhance in the component - also to implement a fallback behaviour instead of an exception you cannot understand

@melloware
Copy link
Member

well if it helps both are around filtering....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants