-
Notifications
You must be signed in to change notification settings - Fork 524
Repro: snippet self-import causes infinite recursion #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Blargian
wants to merge
1
commit into
mintlify:main
Choose a base branch
from
Blargian:snippet-self-import-recursion-repro
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,8 @@ | |
| "pages": [ | ||
| "index", | ||
| "quickstart", | ||
| "development" | ||
| "development", | ||
| "snippet-recursion-repro" | ||
| ] | ||
| }, | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 /> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 indocs.jsonnavigation. If merged, it triggers infinite recursion in Mintlify's snippet loader —mint devhangs, 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)
docs.json#L21-L22snippet-recursion-repro.mdx#L5-L22Reviewed by Cursor Bugbot for commit 76883b4. Configure here.