[Bug]: infinite-scroll pagination returns 404 when loop is inside a template-composed page
Summary
Bug description:
Infinite-scroll pagination (pagination: infinite) on base.loop nodes returns a 404 when the loop lives on a page that is rendered through a template chain (e.g. a page using an "everywhere" layout template). The "Load more" button shows "Try again" instead of loading the next page.
Steps to reproduce
------------------------ Steps to reproduce ------------------------
- Create a template with an outlet (e.g. a layout template).
- Create a page that uses this template.
- Add a base.loop node with pagination: infinite and a data.rows source on that page.
- Publish the site.
- Visit the published page and click "Load more".
- The browser console shows:
GET /instatic/loop/c0
----------------------- Root cause ---------------------------
When a page is rendered through a template chain, composeTemplateChain in src/core/templates/templateCompose.ts
prefixes terminal-page node IDs with c0_ (and outer template IDs with t). The published HTML therefore carries
data-instatic-loop="c0
However, the published loop index built by getPublishedLoopIndexForVersion in server/publish/publishedSnapshotCache.ts iterates the original (non-composed) page nodes, so it stores the original ID without any prefix. The direct lookup in handleLoopRequest (server/handlers/cms/loop.ts) misses:
const indexed = loopIndex.loops.get(loopId) // loopId is "c0_
------------------------ for team of INSTATIC . Fix(solution for especific case) ------------------------
The composedNodeSourceId utility in src/core/templates/templateCompose.ts already strips the c0_/t_ prefix. Using it as a fallback in the lookup resolves the original node:
-
import { composedNodeSourceId } from '@core/templates'
// ...
- const indexed = loopIndex.loops.get(loopId)
- // The runtime sends the loop id as it appears in the DOM. When the page
- // is rendered through a template chain,
composeTemplateChainprefixes - // terminal-page node ids with
c0_(and outer template ids witht<i>_), - // so the DOM attribute carries a composed id like
c0_<original>. The - // published loop index is built from the original (non-composed) page
- // nodes, so a direct lookup misses. Strip the composition prefix as a
- // fallback before giving up.
- const indexed =
- loopIndex.loops.get(loopId) ??
- loopIndex.loops.get(composedNodeSourceId(loopId))
File: server/handlers/cms/loop.ts
------------------------ Verification ------------------------
- bun run build passes.
- bun test passes (7005 pass; pre-existing failures in cmsPlugins.test.ts are unrelated).
- Manual test: infinite-scroll pagination now loads subsequent pages correctly on template-composed pages.
------------------------ Environment ------------------------
- Instatic version: 0.0.20
- Reproduced on both SQLite and Postgres modes, local dev and published output.
Expected behavior
When clicking "Load more" on an infinite-scroll loop that lives on a template-composed page, the server should resolve
the composed loop ID (e.g. c0_
Actual behavior
The "Load more" button shows "Try again" instead of loading the next page.
Version or commit
Instatic version: 0.0.20
Deployment mode
None
Logs or screenshots
I would be interested in picking this up. My initial thought is that the pagination request is carrying a composed page ID generated by the template chain, but the lookup logic is searching for the original node ID. I would start by tracing the page ID generation and resolution flow, then add a fallback that strips the composition prefix and retries the lookup against the original node ID. This seems aligned with the root cause described and should help restore the expected infinite scroll behaviour on template composed pages.