ryanwelcher / advanced-query-loop

WordPress plugin that introduces a Query Loop block variation that can create advanced queries.
87 stars 10 forks source link

Remove useState hook for the excluded current post that was causing Maximum update depth exceeded errors. #53

Closed ryanwelcher closed 5 months ago

ryanwelcher commented 5 months ago

This PR fixes an issue that was introduced with #40 where a useState hook causing the block to crash in certain cases. The variable created for the state was not being used other than to set the state so I have removed it.

CC @jenniferfarhat, just wanted to be sure that I didn't miss anything with this PR

jenniferfarhat commented 5 months ago

@ryanwelcher I added the exclude_current attribute to the useEffect hook because I was encountering cases where I had selected the current id and then used the Exclude Current Post toggle and it will still be selected. While this worked, when I got back to the original state of the exclude_current attribute nothing would happen (toggle Off for example) that is why I added another variable to save the current value of the exclude_current attribute.

Unfortunately, I never encountered any issues after I added this conditional during testing.

https://github.com/ryanwelcher/advanced-query-loop/assets/129080124/5a937f12-e430-4a17-a3b0-743870515d86

ryanwelcher commented 5 months ago

Thanks for the follow up @jenniferfarhat. The issue seemed to manifest with a fresh instance of AQL only (at least in my testing). For the time being, I've merged this to address the issue but if the issue that you're talking about manifests, we'll revisit this.

Thanks again for your contributions here :)