Skip to content

[docs-infra] Fix stackblitz for js projects #46220

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

Merged
merged 3 commits into from
Jun 2, 2025
Merged
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
6 changes: 3 additions & 3 deletions docs/src/modules/sandbox/StackBlitz.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('StackBlitz', () => {
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.js"></script>
<script type="module" src="/src/index.jsx"></script>
</body>
</html>`,
'package.json': `{
Expand All @@ -76,7 +76,7 @@ describe('StackBlitz', () => {
"vite": "latest"
}
}`,
'src/Demo.js': `import * as React from 'react';
'src/Demo.jsx': `import * as React from 'react';
import Stack from '@mui/material/Stack';
import Button from '@mui/material/Button';
Expand All @@ -90,7 +90,7 @@ export default function BasicButtons() {
);
}
`,
'src/index.js': `import * as React from 'react';
'src/index.jsx': `import * as React from 'react';
import * as ReactDOM from 'react-dom/client';
import { StyledEngineProvider } from '@mui/material/styles';
import Demo from './Demo';
Expand Down
11 changes: 10 additions & 1 deletion docs/src/modules/sandbox/StackBlitz.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import addHiddenInput from 'docs/src/modules/utils/addHiddenInput';
import SandboxDependencies from 'docs/src/modules/sandbox/Dependencies';
import getFileExtension from 'docs/src/modules/sandbox/FileExtension';
import flattenRelativeImports from 'docs/src/modules/sandbox/FlattenRelativeImports';
import { CodeVariant, DemoData } from 'docs/src/modules/sandbox/types';
import * as CRA from 'docs/src/modules/sandbox/CreateReactApp';

function getFileExtension(codeVariant: 'TS' | 'JS') {
if (codeVariant === 'TS') {
return 'tsx';
}
if (codeVariant === 'JS') {
return 'jsx';
}
throw new Error(`Unsupported codeVariant: ${codeVariant}`);
}

function ensureExtension(file: string, extension: string): string {
return file.endsWith(`.${extension}`) ? file : `${file}.${extension}`;
}
Expand Down
Loading