Skip to content

fix(plugin-nested-docs): detect circular parent references#16242

Open
fkkehlet wants to merge 1 commit intopayloadcms:mainfrom
fkkehlet:fix/nested-docs-circular-parent
Open

fix(plugin-nested-docs): detect circular parent references#16242
fkkehlet wants to merge 1 commit intopayloadcms:mainfrom
fkkehlet:fix/nested-docs-circular-parent

Conversation

@fkkehlet
Copy link
Copy Markdown

What?

Adds circular reference detection to the getParents utility in the nested-docs plugin.

Why?

Setting a document's parent to one of its own descendants causes getParents to recurse infinitely, hanging the server. For example, if you have pages A → B → C and set A's parent to C, the breadcrumb generation enters an infinite loop.

The parent field already has a filterOptions guard that prevents selecting descendants in the UI, but it relies on breadcrumbs being up-to-date in the database. If breadcrumbs are stale for any reason, the filter won't catch the circular reference, and the server hangs on save. This also doesn't protect against circular references created via the API directly.

How?

Before each recursive call in getParents, check if the parent ID already exists in the collected ancestor chain. If a cycle is detected, throw an APIError instead of recursing.

Two integration tests added:

  • Setting a page as its own parent
  • Creating a circular chain (A → B → C → A)

… infinite recursion

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant