Skip to content
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

fix(theme): fix issue that mui was loaded multiple times #2130

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
"typescript": "5.6.3"
},
"resolutions": {
"@types/react": "18.3.18",
"@types/react-dom": "18.3.5",
"@backstage/[email protected]": "patch:@backstage/backend-dynamic-feature-service@npm%3A0.4.4#./.yarn/patches/@backstage-backend-dynamic-feature-service-npm-0.4.4.patch",
"@backstage/[email protected]": "patch:@backstage/plugin-auth-backend-module-oidc-provider@npm%3A0.3.1#./.yarn/patches/@backstage-plugin-auth-backend-module-oidc-provider-npm-0.3.1.patch",
"@backstage/plugin-auth-backend-module-oidc-provider@^0.3.1": "patch:@backstage/plugin-auth-backend-module-oidc-provider@npm%3A0.3.1#./.yarn/patches/@backstage-plugin-auth-backend-module-oidc-provider-npm-0.3.1.patch",
Expand All @@ -68,7 +66,16 @@
"@backstage/plugin-scaffolder-node@^0.2.9": "patch:@backstage/plugin-scaffolder-node@npm%3A0.6.1#./.yarn/patches/@backstage-plugin-scaffolder-node-npm-0.6.1-a2cc13065e.patch",
"@backstage/plugin-scaffolder-node@^0.4.8": "patch:@backstage/plugin-scaffolder-node@npm%3A0.6.1#./.yarn/patches/@backstage-plugin-scaffolder-node-npm-0.6.1-a2cc13065e.patch",
"@backstage/plugin-scaffolder-node@^0.6.0": "patch:@backstage/plugin-scaffolder-node@npm%3A0.6.1#./.yarn/patches/@backstage-plugin-scaffolder-node-npm-0.6.1-a2cc13065e.patch",
"@backstage/plugin-scaffolder-node@^0.5.1": "patch:@backstage/plugin-scaffolder-node@npm%3A0.6.1#./.yarn/patches/@backstage-plugin-scaffolder-node-npm-0.6.1-a2cc13065e.patch"
"@backstage/plugin-scaffolder-node@^0.5.1": "patch:@backstage/plugin-scaffolder-node@npm%3A0.6.1#./.yarn/patches/@backstage-plugin-scaffolder-node-npm-0.6.1-a2cc13065e.patch",
"@mui/icons-material": "^5",
"@mui/material": "^5",
"@mui/private-theming": "^5",
"@mui/styled-engine": "^5",
"@mui/styles": "^5",
"@mui/system": "^5",
"@mui/utils": "^5",
"@types/react-dom": "18.3.5",
"@types/react": "18.3.18"
},
"jest": {
"testTimeout": 20000
Expand Down
4 changes: 3 additions & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
"@emotion/styled": "11.14.0",
"@internal/plugin-dynamic-plugins-info": "*",
"@janus-idp/backstage-plugin-rbac-common": "1.12.0",
"@material-ui/core": "4.12.4",
"@material-ui/lab": "^4.0.0-alpha.61",
"@mui/icons-material": "5.16.12",
"@mui/material": "5.16.12",
"@mui/styled-engine": "5.16.12",
"@redhat-developer/red-hat-developer-hub-theme": "0.4.0",
"@red-hat-developer-hub/backstage-plugin-theme": "0.4.9",
"@scalprum/core": "0.8.1",
"@scalprum/react-core": "0.9.3",
"lodash": "4.17.21",
Expand Down
113 changes: 113 additions & 0 deletions packages/app/src/components/AppBase/AppBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ import { ScaffolderFieldExtensions } from '@backstage/plugin-scaffolder-react';
import { SearchPage as BackstageSearchPage } from '@backstage/plugin-search';
import { UserSettingsPage } from '@backstage/plugin-user-settings';

import ButtonV4 from '@material-ui/core/Button';
import GridV4 from '@material-ui/core/Grid';
import TextFieldV4 from '@material-ui/core/TextField';
import AutocompleteV4 from '@material-ui/lab/Autocomplete';
import AutocompleteV5 from '@mui/material/Autocomplete';
import ButtonV5 from '@mui/material/Button';
import GridV5 from '@mui/material/Grid';
import TextFieldV5 from '@mui/material/TextField';

import { entityPage } from '../catalog/EntityPage';
import DynamicRootContext from '../DynamicRoot/DynamicRootContext';
import { LearningPaths } from '../learningPaths/LearningPathsPage';
Expand All @@ -28,6 +37,109 @@ import ConfigUpdater from '../Root/ConfigUpdater';
import { SearchPage } from '../search/SearchPage';
import { settingsPage } from '../UserSettings/SettingsPages';

const ButtonTest = () => {
const movies = [
{ title: 'The Shawshank Redemption', year: 1994 },
{ title: 'The Godfather', year: 1972 },
{ title: 'The Godfather: Part II', year: 1974 },
{ title: 'The Dark Knight', year: 2008 },
{ title: '12 Angry Men', year: 1957 },
{ title: "Schindler's List", year: 1993 },
{ title: 'Pulp Fiction', year: 1994 },
{ title: 'The Lord of the Rings: The Return of the King', year: 2003 },
{ title: 'The Good, the Bad and the Ugly', year: 1966 },
{ title: 'Fight Club', year: 1999 },
];

return (
<div>
<h1>Material UI v4 buttons</h1>
<div>
<ButtonV4 variant="contained">Default</ButtonV4>
<ButtonV4 variant="contained" color="primary">
Primary
</ButtonV4>
<ButtonV4 variant="contained" color="secondary">
Secondary
</ButtonV4>
<ButtonV4 variant="contained" disabled>
Disabled
</ButtonV4>
<ButtonV4 variant="contained" color="primary" href="#contained-buttons">
Link
</ButtonV4>
</div>

<h1>MUI v5 buttons</h1>
<div>
<ButtonV5 variant="contained">Default</ButtonV5>
<ButtonV5 variant="contained" color="primary">
Primary
</ButtonV5>
<ButtonV5 variant="contained" color="secondary">
Secondary
</ButtonV5>
<ButtonV5 variant="contained" disabled>
Disabled
</ButtonV5>
<ButtonV5 variant="contained" color="primary" href="#contained-buttons">
Link
</ButtonV5>
</div>

<h1>Material UI v4 Autocomplete</h1>
<div>
<AutocompleteV4
options={movies}
renderInput={params => <TextFieldV4 {...params} label="Movie" />}
getOptionLabel={option => option.title}
/>
</div>

<h1>MUI v5 Autocomplete</h1>
<div>
<AutocompleteV5
options={movies}
renderInput={params => <TextFieldV5 {...params} label="Movie" />}
getOptionLabel={option => option.title}
/>
</div>

<h1>MUI v4 Grid</h1>
<GridV4 container>
<GridV4 item>
<div style={{ backgroundColor: 'gray' }}>1</div>
</GridV4>
<GridV4 item>
<div style={{ backgroundColor: 'gray' }}>2</div>
</GridV4>
<GridV4 item>
<div style={{ backgroundColor: 'gray' }}>3</div>
</GridV4>
<GridV4 item>
<div style={{ backgroundColor: 'gray' }}>4</div>
</GridV4>
</GridV4>

<h1>MUI v5 Grid</h1>
<GridV5 container>
<GridV5 item>
<div style={{ backgroundColor: 'gray' }}>1</div>
</GridV5>
<GridV5 item>
<div style={{ backgroundColor: 'gray' }}>2</div>
</GridV5>
<GridV5 item>
<div style={{ backgroundColor: 'gray' }}>3</div>
</GridV5>
<GridV5 item>
<div style={{ backgroundColor: 'gray' }}>4</div>
</GridV5>
</GridV5>
</div>
);
};

const AppBase = () => {
const {
AppProvider,
Expand Down Expand Up @@ -120,6 +232,7 @@ const AppBase = () => {
<Route path="/settings" element={<UserSettingsPage />}>
{settingsPage}
</Route>
<Route path="/button-test" element={<ButtonTest />} />
<Route path="/catalog-graph" element={<CatalogGraphPage />} />
<Route path="/learning-paths" element={<LearningPaths />} />
{dynamicRoutes.map(
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/DynamicRoot/DynamicRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createApp } from '@backstage/app-defaults';
import { BackstageApp } from '@backstage/core-app-api';
import { AnyApiFactory, BackstagePlugin } from '@backstage/core-plugin-api';

import { useThemes } from '@redhat-developer/red-hat-developer-hub-theme';
import { useThemes } from '@red-hat-developer-hub/backstage-plugin-theme';
import { AppsConfig } from '@scalprum/core';
import { useScalprum } from '@scalprum/react-core';

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/DynamicRoot/Loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Box from '@mui/material/Box';
import CircularProgress from '@mui/material/CircularProgress';
import CssBaseline from '@mui/material/CssBaseline';
import { ThemeProvider } from '@mui/material/styles';
import { useLoaderTheme } from '@redhat-developer/red-hat-developer-hub-theme';
import { useLoaderTheme } from '@red-hat-developer-hub/backstage-plugin-theme';

const Loader = () => {
// Access theme context before Backstage App is instantiated
Expand Down
Loading
Loading