Skip to content

Conversation

@siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Nov 7, 2025

Root Cause

Before: https://mui.com/material-ui/migration/upgrade-to-v7.md (show native color content which is wrong)

The findNonComponentMarkdownFiles() function uses findPagesMarkdown() which strips the filename from the path to create a "pathname". When multiple markdown files exist in the same directory, they produce identical pathnames:

docs/data/material/migration/upgrade-to-v7/
├── upgrade-to-v7.md          → pathname: /material/migration/upgrade-to-v7
└── upgrade-to-native-color.md → pathname: /material/migration/upgrade-to-v7  (collision!)

The find() method then returns the first alphabetically ordered file (upgrade-to-native-color.md), causing upgrade-to-v7.md to be generated with the wrong content.

Solution

Updated the file matching logic to use:

  1. Filename basename match - Compare the actual filename (e.g., upgrade-to-v7)
  2. Parent path verification - Ensure the file is in the expected directory

This prevents collisions while maintaining compatibility with the existing file structure.

Testing

Verified all 13 migration files generate with correct content:

  • upgrade-to-v7.md → "Upgrade to v7" content
  • upgrade-to-native-color.md → "Upgrade to native color" content

When multiple markdown files exist in the same directory, findPagesMarkdown()
strips filenames causing pathname collisions. This resulted in the wrong file
content being used (e.g., upgrade-to-v7.md incorrectly contained content from
upgrade-to-native-color.md).

Fix by matching files based on filename basename + parent path verification
instead of relying solely on the stripped pathname.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@siriwatknp siriwatknp requested a review from Janpot November 7, 2025 15:08
@siriwatknp siriwatknp added the scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305). label Nov 7, 2025
@mui-bot
Copy link

mui-bot commented Nov 7, 2025

Netlify deploy preview

https://deploy-preview-47209--material-ui.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/material 0B(0.00%) 0B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against 494320a

@Janpot Janpot requested a review from Copilot November 7, 2025 16:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR modifies the file matching logic in the findNonComponentMarkdownFiles function to fix pathname collision issues when multiple markdown files exist in the same directory.

Key Changes:

  • Replaced simple pathname equality check with a more sophisticated matching algorithm that compares file basenames and verifies parent directory paths
  • Added logic to extract the last segment from pathnames and match against actual file basenames
  • Introduced parent path verification to ensure files are located in the correct directory structure

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// exist in the same directory (e.g., upgrade-to-v7.md and upgrade-to-native-color.md)
const lastSegment = pathname.split('/').filter(Boolean).pop();
const page = allMarkdownFiles.find((p) => {
const fileBasename = path.basename(p.filename, '.md');
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The path.basename() call only strips the .md extension, but findPagesMarkdown() also returns files with .mdx extensions. For .mdx files, the basename will incorrectly include the .mdx suffix, causing the comparison to fail. Use path.basename(p.filename).replace(/\.mdx?$/, '') to handle both .md and .mdx files.

Suggested change
const fileBasename = path.basename(p.filename, '.md');
const fileBasename = path.basename(p.filename).replace(/\.mdx?$/, '');

Copilot uses AI. Check for mistakes.
const page = allMarkdownFiles.find((p) => {
const fileBasename = path.basename(p.filename, '.md');
const parentPath = parsedPathname.replace(/\/[^/]+$/, '');
return fileBasename === lastSegment && p.filename.includes(parentPath);
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The p.filename.includes(parentPath) check is too loose and could match files in subdirectories. For example, when looking for /material-ui/migration/upgrade-to-v7 (which should match a file at docs/data/material/migration/upgrade-to-v7.md), this would incorrectly also match docs/data/material/migration/v7/upgrade-to-v7.md because that filename also contains /material/migration. Consider using p.pathname === parentPath instead, which would provide an exact directory match and avoid false positives from files in subdirectories.

Suggested change
return fileBasename === lastSegment && p.filename.includes(parentPath);
return fileBasename === lastSegment && path.dirname(p.filename) === parentPath;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants