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

TypeError Cannot read properties of null (reading 'length') on this.searchText.length > 0 #1854

Open
johanrd opened this issue Sep 12, 2024 · 3 comments

Comments

@johanrd
Copy link
Contributor

johanrd commented Sep 12, 2024

Hi. In sentry I have some reports on Cannot read properties of null (reading 'length') on this.searchText.length > 0 on get results()

Not sure if I am stretching the usage here, but anyways, I think ember-power-select should be resilient towards this.

Two fixes I can think of:

  1. Optional chaining on all consumers of this.searchText.length (i.e. this.searchText?.length)
  get results(): any[] {
-    if (this.searchText.length > 0) {
+    if (this.searchText?.length > 0) {
      if (this.args.search) {
        return toPlainArray(this._searchResult || this.options);
  1. Nullish coalescing on all assignments to this.searchText to ensure it is not null or undefined?
 @action
  _search(term: string): void {
    if (this.searchText === term) return;
-    this.searchText = term;
+    this.searchText = term ?? '';
    if (!this.args.search) {
      this.lastSearchedText = term;
      this._resetHighlighted();
    }
  }
@mkszepp
Copy link
Collaborator

mkszepp commented Sep 12, 2024

I'm not sure if this is really an issue of EPS, because from type we allow only string for searchTerm.
This means that when the app is not passing a string, its an incorrect using, which should be fixed inside app.

In the typed world you issue will never appear, but in JS its always everything possible.

@johanrd
Copy link
Contributor Author

johanrd commented Sep 13, 2024

ok, thanks. FYI: I am in a fully typed world (all .gts) and do not get any glint errors in my component usage. Still this issue appears in sentry.

@mkszepp
Copy link
Collaborator

mkszepp commented Sep 13, 2024

Hmm... can you share the example like you are using? Because with TS it should bring an error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants