plone / volto

React-based frontend for the Plone Content Management System
https://demo.plone.org/
MIT License
474 stars 642 forks source link

"Exception: No query supplied" in the listing block #3839

Closed wesleybl closed 1 week ago

wesleybl commented 2 years ago

Describe the bug When we load a page that has a listing block, without a search criteria, we get the error below in Plone:

2022-11-04 16:51:47 ERROR [Zope.SiteErrorLog:35][waitress-3] Exception: http://localhost:3000/@querystring-search
Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 167, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 376, in publish_module
  Module ZPublisher.WSGIPublisher, line 271, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 68, in call_object
  Module plone.rest.service, line 22, in __call__
  Module plone.restapi.services, line 19, in render
  Module plone.restapi.services.querystringsearch.get, line 30, in reply
Exception: No query supplied

Who makes this call is getAsyncData.js

It sends the query parameter as an empty list.

It looks like it's an attempt to render the block server-side, but I don't quite understand it. The fact is that the block works without getAsyncData. So I'm not quite sure what the idea is here.

To Reproduce Steps to reproduce the behavior:

  1. Create a listing block at home, without any search criteria.
  2. Press F5 on home.
  3. See the Plone log.

Expected behavior No error in Plone.

Software (please complete the following information):

tiberiuichim commented 2 years ago

@wesleybl It's related to the server-side rendering of the listing block, see https://6.dev-docs.plone.org/volto/blocks/ssr.html

It's probably a bug, that code needs to be brought more in line with the rest of the listing block data fetching preparations.

wesleybl commented 2 years ago

@tiberiuichim i'm trying to modify the listing block, to return more calalog metadata. But I saw that there are requests in getAsyncData.js and in withQuerystringResults.jsx. Which of these files should I make changes to? Or on both?

tiberiuichim commented 2 years ago

@wesleybl both.

getAsyncData is only used on the server-side rendering path. It's meant to populate the Redux store that will be used by the listing block components. Here's a page that hopefully will explain this mechanism: https://training.plone.org/effective-volto/addons/asyncconnect.html

withQuerystringResults is used by the listing block to fetch the data.

In principle these two functions should produce exactly the same query (pagination excluded, as there's no URL-based set current page). If they don't, it's a bug in the getAsyncData and should be fixed.

wesleybl commented 2 years ago

@tiberiuichim as I understand it, this is a mechanism to prevent the page from loading without the listing. But on the Browser side, the listing can be modified, after server rendering. That's it?

Well it looks like the way it is today, when we don't have a criterion, nothing is rendered on the server side (getAsyncData.js), since the query parameter is empty here (causing the described error).

The listing only appears because withQuerystringResults.js has a fallback:

https://github.com/plone/volto/blob/20840fdc5fc5a80e77e53ac04a028b613d444eaf/src/components/manage/Blocks/Listing/withQuerystringResults.jsx#L104-L106

when we don't have query.

It may be necessary to create a "default query", both in withQuerystringResults.js and in getAsyncData.js, when there is no query. Maybe in editing this "default query" should already be saved.

wesleybl commented 2 years ago

@tiberiuichim @sneridagh any opinions here? I propose the default query:

const defaultQuery = [
  {
    i: 'path',
    o: 'plone.app.querystring.operation.string.relativePath',
    v: '::1',
  },
];

when we have no defined criteria. This query will have the same result as the items key of the content.

tiberiuichim commented 2 years ago

@wesleybl Ok, +1