Collab Notes: Defer the full comments fetch behind preloaded count probes#78557
Collab Notes: Defer the full comments fetch behind preloaded count probes#78557ellatrix wants to merge 1 commit into
Conversation
…obes The collab-notes hook fires `GET /wp/v2/comments?type=note&per_page=-1` on every editor mount, even when the post has no notes. The full response feeds two sidebar gates (All Notes sidebar presence, floating sidebar auto-open) — both of which only care about counts, not full threads. For the common case of a post with no notes, today we still pay the eager fetch. Replace with two small preloadable presence probes plus a gated full fetch: 1. `useNoteThreads` adds two `useEntityRecords` calls with `per_page=1&_fields=id`, one each for `status=all` and `status=hold`. Their `X-WP-Total` populates `notesCount` / `unresolvedCount`. 2. The full per-page fetch is gated on `notesCount > 0` — so posts with no notes never fire it. 3. `NotesSidebar` reads `hasNotes` / `hasUnresolvedNotes` from the hook instead of `notes.length` / `unresolvedNotes.length`, so the gates work even before the (now-conditional) full fetch resolves. 4. The two count URLs are added to `block_editor_rest_api_preload_paths` for the post-editor context, and driven in the kickoff alongside the other per-post resolvers so they consume the preload entries before `clearPreloadedData` runs. Empirical verification on a fresh draft (no notes): - Before: full `GET /wp/v2/comments?…&type=note&per_page=100` request fires post-mount. - After: `[api-fetch][preload] All preloads consumed.` (the count probes are cache-hits), and **no** `/wp/v2/comments` request fires. With at least one note on the post: - Count probes still cache-hit (same preload entries). - Full fetch fires the same as today — drives indicators + sidebar content rendering. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +192 B (0%) Total Size: 8.04 MB 📦 View Changed
ℹ️ View Unchanged
|
What?
The collab notes feature fires `GET /wp/v2/comments?type=note&per_page=-1` on every editor mount of every post supporting `editor.notes`. The full response only feeds two pieces of UI that need counts, not threads:
(Per-block indicators and the All Notes sidebar contents are gated by user interaction — block selection / sidebar open — so they don't run on mount.)
For the common case of a post with no notes, today we still pay the eager fetch on every mount.
How?
Replace with two small preloadable presence probes plus a gated full fetch:
Test results
Post with no notes (the common case)
Before:
```
GET /wp-json/wp/v2/comments?context=edit&post=…&type=note&status=all&per_page=100
```
After:
```
[api-fetch][preload] All preloads consumed.
(no /wp/v2/comments request)
```
Post with at least one note
Count probes cache-hit via the kickoff. Full fetch fires the same as today — drives indicators + sidebar content rendering.
```
[api-fetch][preload] All preloads consumed.
GET /wp-json/wp/v2/comments?context=edit&post=…&type=note&status=all&per_page=100
```
Testing Instructions
Follow-ups
The full fetch is still eager when there's at least one note. Future work could defer it to either (a) the user opening the All Notes sidebar, or (b) per-block-selection single-comment fetches with placeholders. This PR is the smallest step that covers the no-notes case (which is most posts).
🤖 Generated with Claude Code