Skip to content

Commit

Permalink
Remove fallback modules (#3326)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Mar 25, 2024
1 parent 1ea5a67 commit 57b8ed6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 23 deletions.
3 changes: 1 addition & 2 deletions docs/data/toolpad/studio/concepts/custom-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ Toolpad Studio exposes a [`createComponent`](https://mui.com/toolpad/studio/refe

```jsx
import * as React from 'react';
import { Typography } from '@mui/material';
import { createComponent } from '@toolpad/studio/browser';

export interface HelloWorldProps {
msg: string;
}

function HelloWorld({ msg }: HelloWorldProps) {
return <Typography>{msg}</Typography>;
return <div>{msg}</div>;
}

export default createComponent(HelloWorld, {
Expand Down
3 changes: 1 addition & 2 deletions packages/toolpad-studio/src/server/localMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ async function createDefaultCodeComponent(name: string, filePath: string): Promi
const result = await format(
`
import * as React from 'react';
import { Typography } from '@mui/material';
import { createComponent } from '@toolpad/studio/browser';
export interface ${propTypeId} {
Expand All @@ -242,7 +241,7 @@ async function createDefaultCodeComponent(name: string, filePath: string): Promi
function ${componentId}({ msg }: ${propTypeId}) {
return (
<Typography>{msg}</Typography>
<div>{msg}</div>
);
}
Expand Down
20 changes: 1 addition & 19 deletions packages/toolpad-studio/src/server/toolpadAppBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ const TOOLPAD_BUILD = process.env.GIT_SHA1?.slice(0, 7) || 'dev';

const MAIN_ENTRY = '/main.tsx';
const EDITOR_ENTRY = '/editor.tsx';
const FALLBACK_MODULES = [
'@mui/material',
'@mui/icons-material',
'@mui/x-data-grid',
'@mui/x-charts',
];

function getHtmlContent(entry: string) {
return `
Expand Down Expand Up @@ -62,20 +56,10 @@ function toolpadStudioVitePlugin(): Plugin {
return {
name: 'toolpad-studio',

async resolveId(id, parent) {
async resolveId(id) {
if (id.endsWith('.html')) {
return id;
}
const hasFallback = FALLBACK_MODULES.some(
(moduleName) => moduleName === id || id.startsWith(`${moduleName}/`),
);
if (hasFallback) {
const [userMod, fallbackMod] = await Promise.all([
this.resolve(id, parent),
this.resolve(id, currentDirectory),
]);
return userMod || fallbackMod;
}
return null;
},

Expand Down Expand Up @@ -314,7 +298,6 @@ if (import.meta.hot) {
},
envFile: false,
resolve: {
dedupe: FALLBACK_MODULES,
alias: [
{
// FIXME(https://github.com/mui/material-ui/issues/35233)
Expand Down Expand Up @@ -364,7 +347,6 @@ if (import.meta.hot) {
optimizeDeps: {
force: !process.env.EXPERIMENTAL_INLINE_CANVAS && toolpadDevMode ? true : undefined,
include: [
...FALLBACK_MODULES.map((moduleName) => `@toolpad/studio > ${moduleName}`),
...(process.env.EXPERIMENTAL_INLINE_CANVAS && dev
? [
'perf-cascade',
Expand Down

0 comments on commit 57b8ed6

Please sign in to comment.