diff --git a/REPRO.md b/REPRO.md new file mode 100644 index 000000000..44b9f8fd5 --- /dev/null +++ b/REPRO.md @@ -0,0 +1,70 @@ +# Snippet self-import causes infinite recursion + +## Summary + +When a snippet imports itself (or two snippets import each other), Mintlify's +snippet loader recurses without detecting the cycle. The CLI hangs at +"preparing local preview…" and the Node process pins a CPU core at 100%. + +## Repro + +This repo is forked from https://github.com/mintlify/starter and adds: + +- `snippets/self.mdx` — imports itself and renders `` inside its own body. +- `snippet-recursion-repro.mdx` — page that imports `snippets/self.mdx`. +- `docs.json` — the page added to the "Getting started" group. + +### Steps + +```bash +git clone +cd mintlify-snippet-recursion-repro +mint dev +``` + +Then open `http://localhost:3939/snippet-recursion-repro`. + +### Observed + +- `mint dev` never reaches "✓ preview ready"; the underlying + `@mintlify/cli` Node process sits at 100% CPU indefinitely. +- `mint broken-links` never completes. +- Production builds on Mintlify's hosted platform hang / fail. + +### Expected + +The loader should detect a snippet importing itself (or any cycle in the +snippet import graph) and either: + +1. Surface a clear error pointing at the offending snippet, or +2. Stop recursion at the first level so the rest of the build can succeed. + +## Minimal files + +`snippets/self.mdx`: + +```mdx +import Self from '/snippets/self.mdx'; + +This snippet imports itself on the line above and renders `` below. + + +``` + +`snippet-recursion-repro.mdx`: + +```mdx +--- +title: "Snippet self-import recursion repro" +--- + +import Self from '/snippets/self.mdx'; + + +``` + +## Notes + +- The same shape applies to mutual cycles: `A` imports `B`, `B` imports `A`. +- A linear chain (page → A → B, no cycle) renders correctly — the bug is + specifically cycle detection in the snippet loader. diff --git a/docs.json b/docs.json index 66b3f40c3..a4323e74b 100644 --- a/docs.json +++ b/docs.json @@ -18,7 +18,8 @@ "pages": [ "index", "quickstart", - "development" + "development", + "snippet-recursion-repro" ] }, { diff --git a/snippet-recursion-repro.mdx b/snippet-recursion-repro.mdx new file mode 100644 index 000000000..d0f2e6b2f --- /dev/null +++ b/snippet-recursion-repro.mdx @@ -0,0 +1,36 @@ +--- +title: "Snippet self-import recursion repro" +description: "A snippet that imports itself causes infinite recursion in Mintlify." +--- + +import Self from '/snippets/self.mdx'; + +## Reproduction + +`snippets/self.mdx` contains: + +```mdx +import Self from '/snippets/self.mdx'; + +This snippet imports itself on the line above and renders `` below. + + +``` + +This page imports and renders that snippet: + + + +## Expected + +Mintlify detects the self-reference (or any cycle in snippet imports) and either errors out with a clear message or stops at the first level. + +## Actual + +- `mint dev` — local preview hangs / crashes when this page is requested. +- `mint broken-links` — never completes. +- Production build on Mintlify hosted — hangs / fails. + +## Notes + +The same shape applies to mutual cycles (`A` imports `B`, `B` imports `A`). Any cycle in snippet imports should be detected and broken by the loader. \ No newline at end of file diff --git a/snippets/self.mdx b/snippets/self.mdx new file mode 100644 index 000000000..18319f34e --- /dev/null +++ b/snippets/self.mdx @@ -0,0 +1,6 @@ +import Self from '/snippets/self.mdx'; + +This snippet imports itself on the line above and renders `` below. +A correct loader should detect the self-reference and stop; Mintlify recurses. + + \ No newline at end of file