Skip to content

Conversation

@bernardobelchior
Copy link
Member

@bernardobelchior bernardobelchior commented Sep 29, 2025

Fixes mui/mui-x#19749.

Fix JSON files not being imported in TS demos.

I'm not very experienced with docs-infra, so feel free to suggest improvements.

It seemed that once a file is processed it won't be processed again. Since JS processing happens before TS processing, modules that independent from the variant won't show up in the TS demo because they will have been processed by the JS demo already.

Before:

Screen.Recording.2025-09-29.at.10.51.34.mov

After:

Screen.Recording.2025-09-29.at.10.51.14.mov

@bernardobelchior bernardobelchior requested a review from a team September 29, 2025 08:51
@bernardobelchior bernardobelchior added type: bug It doesn't behave as expected. scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305). labels Sep 29, 2025
@mui-bot
Copy link

mui-bot commented Sep 29, 2025

Netlify deploy preview

https://deploy-preview-47000--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 c23cba0

Comment on lines 158 to 173
// If the moduleID does not end with an extension, or ends with an unsupported extension (e.g. ".styling") we need to resolve it
// Fastest way to get a file extension, see: https://stackoverflow.com/a/12900504/
const importType = importModuleID.slice(
(Math.max(0, importModuleID.lastIndexOf('.')) || Infinity) + 1,
);
const importType = getExtension(importModuleID);
Copy link
Member

Choose a reason for hiding this comment

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

You copy paste the comments. Maybe keeping is only at one place is enough

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, yes, forgot to remove it 👍

);

// the file has already been processed
if (addedModulesRelativeToModulePath.has(relativeModuleFilePath)) {
Copy link
Member

Choose a reason for hiding this comment

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

Not 100% sure, but wouldn't it be solved if we just make addedModulesRelativeToModulePath work per-variant?

           demos[demoName].relativeModules = {};
         }
 
-        const addedModulesRelativeToModulePath = new Set();
         await Promise.all(
           Array.from(relativeModules.get(demoName)).map(async ([relativeModuleID, variants]) => {
             for (const variant of variants) {
+              const addedModulesRelativeToModulePath = new Set();
               let raw = '';
               const relativeModuleFilePath = path.join(
                 path.dirname(moduleFilepath),

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems to fix the issue 👍 thanks!

Copy link
Member

@Janpot Janpot Sep 29, 2025

Choose a reason for hiding this comment

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

Actually, on a second look, that doesn't seem to be equivalent. Maybe we need to

const addedModulesRelativeToModulePath = { TS: new Set(), JS: new Set() };

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, on a second look, that doesn't seem to be equivalent. Maybe we need to

const addedModulesRelativeToModulePath = { TS: new Set(), JS: new Set() };

?

How would that solve the issue? If the TS key is only read when the variant is TS, isn't it equivalent?

Copy link
Member

@Janpot Janpot Sep 29, 2025

Choose a reason for hiding this comment

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

Because with the first solution I propose, it would stop deduplicating altogether, addedModulesRelativeToModulePath would never get more than one item added. But if I understand correctly, we want deduplication per variant. So we need two sets instead of one, and add to the set of the current variant we're working on.

I guess, I don't know this code too well neither. Just learning along reviewing 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, you're right. We're iterating over the modules and inside that iteration we iterate over the variants. It would only work it if was the other way around.

@bernardobelchior bernardobelchior force-pushed the fix-json-not-imported-ts-demo branch from 08d4459 to 78effb6 Compare September 29, 2025 09:34
Copy link
Member

@Janpot Janpot left a comment

Choose a reason for hiding this comment

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

Justa small suggestion, but at your own discretion

@bernardobelchior bernardobelchior merged commit 0e2c14e into mui:master Sep 29, 2025
18 checks passed
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). type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[charts][docs] Data tab doesn't show in typescript demos

4 participants