[Bug]: Back-link loop between an item's detail page and its Copy/Edit sub-page
What happened
"Back to Collection" can get stuck looping between an item's detail page and its Copy to new entry (or Edit) form, with no way back to the actual collection listing.
Steps to reproduce
- Open a collection, click an item to open its detail page.
- Click Copy to new entry. The form's back link reads "Cancel and Back".
- Click Cancel and Back → lands on the original item's detail page (expected). Its back link now reads "Back to Collection".
- Click Back to Collection → instead of the collection, it goes back to the Copy form.
- From there you can bounce between the two indefinitely.
(Same mechanism applies to the Edit form reached from a detail page.)
Cause
In the detail route (core/routes/itemRoutes.ts), when there's no explicit ?from=, backUrl falls back to the Referer, unless the Referer looks like another item page — that check is itemPagePattern:
const itemPagePattern = new RegExp(
`^${escapeRegExp(BASE_URL)}${escapeRegExp(plugin.routePrefix)}/[a-f0-9]{24}(?:[/?#]|$)`, 'i'
);
const backUrl = safeReturnPath(req.query.from, req.get('host'))
|| (itemPagePattern.test(refererPath) ? '' : refererPath);
That pattern matches a bare detail URL (/{prefix}/{id}) and correctly drops it as a back target. But the Copy and Edit sub-routes are /{prefix}/copy/{id} and /{prefix}/edit/{id} — they do not match the pattern, so when you arrive on the detail page from the copy/edit form, the Referer (the copy/edit URL) passes the test and becomes backUrl. "Back to Collection" then points at the copy/edit page → loop.
Verified the regex against the three Referer shapes: /{prefix}/{id} matches (filtered out, good), but /{prefix}/copy/{id} and /{prefix}/edit/{id} do not match (wrongly kept as the back target).
Suggested fix
Broaden itemPagePattern so the item sub-pages (copy, edit, and the label page) are also treated as non-listing Referers — i.e. allow an optional copy/, edit/, etc. segment before the id, or more simply treat any path under /{prefix}/ that isn't the collection as not-a-listing. Happy to open a PR for it.
Environment
Reproduced on 3.3.0 (the generic copy-to-new-entry route). The code is the same on current main.
Hey! Thanks for this. I'll review your PR asap!
Hi! Your fix (#201) is in 4.0.0. Thanks!