block-components icon indicating copy to clipboard operation
block-components copied to clipboard

ContentPicker search for a custom post type post crashes block

Open Spoygg opened this issue 1 year ago • 5 comments

Describe the bug

When searching for a custom post type post in ContentPicker javscript error triggers and block that uses ContentPicker crashes. Expecting search results to show without crashing the block.

Steps to Reproduce

  1. create a custom post type
  2. add some posts of that post type
  3. create a block that uses ContentPicker and set contentTypes to be custom post type created in step 1
  4. go to editor and add block created in step 3
  5. search for posts
  6. every other or third time block will crash

Screenshots, screen recording, code snippet

Untitled

In console this error gets triggered:

react-dom.min.js?ver=18.2.0:10 TypeError: Cannot set properties of undefined (setting 'results')
    at index.js:70:2558

Where index.js is node_modules/@10up/block-components/dist/index.js

Timing seems to be an issue, when I type a letter then wait for results to load, then type another letter and wait for results to load, and so on, the error never happens. Only if I type a couple of letters then it will crash. It's not consistently crashing, maybe every other or third time. Seems that canceled requests cause this issue, when several letters are typed, previous letters (word so far) search requests get canceled.

Environment information

No response

WordPress information

Versions above 6.0, though I think I've seen this on versions below 6.0 too.

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

Spoygg avatar Sep 20 '23 10:09 Spoygg

Hey @Spoygg 👋

Are you able to provide a screenshot / the value of the network request that happens when you type in the content search?

fabiankaegy avatar Sep 20 '23 11:09 fabiankaegy

@fabiankaegy sure. Here's gif of all request made while I'm typing "unity". Not sure if that's an issue but the last one is sent twice (containing "unity" as search string). Untitled

I can try debugging with uncompressed library to see what's actually going on.

Spoygg avatar Sep 20 '23 12:09 Spoygg

Also it happens with ContentPicker being in InspectorControls or in the block body.

Spoygg avatar Sep 20 '23 12:09 Spoygg

Here I was looking for "cult". It seems to try to store results for "cu" although that request was canceled already. First time it hits that line it's not an issue, but second time it breaks. Not very clear what's happening since code is compressed. I can take a look later in the week.

Untitled

Spoygg avatar Sep 20 '23 13:09 Spoygg

Hi any updates on this issue?

Same thing happens on me as Spoygg

ngoclx avatar Dec 22 '23 02:12 ngoclx

This issue should be closed with version 1.19.0 of the block components. Thanks for your patience

fabiankaegy avatar Jul 01 '24 19:07 fabiankaegy