-
Bug
-
Resolution: Fixed
-
Medium
-
2.0.16, 2.4.9
-
Severity 3 - Minor
-
NOTE: This bug report is for Confluence Server. Using Confluence Cloud? See the corresponding bug report.
This bug can be easily reproduced via the following steps. These steps reference answers.atlassian.com for simplicity, but the bug affects all instances of Confluence Questions.
1. Load an anonymous/incognito browser window
2. Go to https://answers.atlassian.com. Observe that the "Popular" filter is selected by default.
3. Open the developer tools and view network traffic (filter to only show XHR traffic)
4. Click on the "Unanswered" filter. Observe that a request to https://answers.atlassian.com/rest/questions/1.0/questions/?startIndex=0&pageSize=20&filter=unanswered is made.
5. Scroll to the bottom of the page and trigger the 'infinite scroll'. Observe that a request to https://answers.atlassian.com/rest/questions/1.0/questions/?startIndex=20&pageSize=15&filter=popular is made.
Not that in Step 5, the browser requests the "popular" filter, but the user has switched to the "unanswered" filter view. The result is that the second page of results displayed in the list does not actually match the view to which they are inserted. This is obvious in the "unanswered" case, because the second page of results may contain questions that are actually answered.
This bug occurs due to an incorrect use of the jQuery API in questionlist.js.
1. When the page is loaded, the selected filter is inserted into the DOM as a data attribute on the main cq-questionlist element, like so:
<ol class="cq-questionlist" data-page-size="20" data-filter="popular"> ... </ol>
2. When the active filter is changed by the user, the current filter is retrieved using $(".cq-questionlist").data("filter") and then, after the update is successful, the DOM is updated to have the new current filter using $(".cq-questionlist").attr("data-filter", "unanswered").
3. When the infinite scroll is triggered, the current filter is again retrieved using $(".cq-questionlist").data("filter").
Savvy jQuery users may notice the problem immediately. The filter value is updated using the attr function, but the filter value is only ever retrieved using the data function. This doesn't work as expected because the data function only queries the corresponding DOM attribute the first time that the data value is populated (see https://api.jquery.com/data/):
The data- attributes are pulled in the first time the data property is accessed and then are no longer accessed or mutated (all data values are then stored internally in jQuery).
Subsequent updates to the DOM will not affect the value stored internally by jQuery for the "filter" data value. Thus, the infinite scroll will continue to use the original filter value when the page was first loaded.
- relates to
-
CONFCLOUD-47082 Second page of question list loads the wrong filter if the active filter is switched after initial page load
-
- Closed
-