Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions REPRO.md
Original file line number Diff line number Diff line change
@@ -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 `<Self />` 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 <this repo>
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 `<Self />` below.

<Self />
```

`snippet-recursion-repro.mdx`:

```mdx
---
title: "Snippet self-import recursion repro"
---

import Self from '/snippets/self.mdx';

<Self />
```

## 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.
3 changes: 2 additions & 1 deletion docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"pages": [
"index",
"quickstart",
"development"
"development",
"snippet-recursion-repro"
]
},
{
Expand Down
36 changes: 36 additions & 0 deletions snippet-recursion-repro.mdx
Original file line number Diff line number Diff line change
@@ -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 `<Self />` below.

<Self />
```

This page imports and renders that snippet:

<Self />

## 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.
6 changes: 6 additions & 0 deletions snippets/self.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Self from '/snippets/self.mdx';

This snippet imports itself on the line above and renders `<Self />` below.
A correct loader should detect the self-reference and stop; Mintlify recurses.

<Self />
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-importing snippet causes infinite recursion if merged

High Severity

This PR adds a snippet (snippets/self.mdx) that imports itself and renders <Self />, registered in docs.json navigation. If merged, it triggers infinite recursion in Mintlify's snippet loader — mint dev hangs, production builds fail, and the Node process pins a CPU core at 100%. The PR description states it is "not intended to be merged," making this reproducer-only code that would be destructive in production.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 76883b4. Configure here.