Only use one class name generator to avoid side effects

- Remove duplicate CSSBaseline from test app wrapper

Signed-off-by: Philipp Hugenroth <philipph@spotify.com>
This commit is contained in:
Philipp Hugenroth
2023-04-28 16:05:36 +02:00
parent 7cfe41766f
commit 9b714a9bfd
4 changed files with 37 additions and 34 deletions
@@ -0,0 +1,24 @@
/*
* Copyright 2022 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { unstable_ClassNameGenerator as ClassNameGenerator } from '@mui/material/className';
/**
* This API is introduced in @mui/material (v5.0.5) as a replacement of deprecated createGenerateClassName & only affects v5 MUI components from `@mui/*`
*/
ClassNameGenerator.configure(componentName => {
return `v5-${componentName}`;
});
@@ -15,31 +15,16 @@
*/
import React, { ReactNode } from 'react';
import {
Theme as Mui4Theme,
StylesProvider,
ThemeProvider,
} from '@material-ui/core/styles';
import './MuiClassNameSetup';
import { ThemeProvider } from '@material-ui/core/styles';
import {
StyledEngineProvider,
Theme as Mui5Theme,
ThemeProvider as Mui5Provider,
} from '@mui/material/styles';
import {
StylesProvider as Mui5StylesProvider,
createGenerateClassName,
} from '@mui/styles';
import Mui5CssBaseline from '@mui/material/CssBaseline';
import { UnifiedTheme } from './types';
import { CssBaseline } from '@material-ui/core';
const generateV4ClassName = createGenerateClassName({
seed: 'm4',
});
const generateV5ClassName = createGenerateClassName({
seed: 'm5',
});
/**
* Props for {@link UnifiedThemeProvider}.
*
@@ -85,25 +70,14 @@ export function UnifiedThemeProvider(
);
if (v4Theme) {
/* const styles = maybeLoadMui4Styles();
if (!styles) {
throw new Error('Failed to load MUI 4 styles package');
}
const { StylesProvider, ThemeProvider } = styles; */
result = (
<StylesProvider generateClassName={generateV4ClassName} injectFirst>
<ThemeProvider theme={v4Theme as Mui4Theme}>{result}</ThemeProvider>
</StylesProvider>
);
result = <ThemeProvider theme={v4Theme}>{result}</ThemeProvider>;
}
if (v5Theme) {
result = (
<Mui5StylesProvider generateClassName={generateV5ClassName}>
<StyledEngineProvider injectFirst>
<Mui5Provider theme={v5Theme as Mui5Theme}>{result}</Mui5Provider>
</StyledEngineProvider>
</Mui5StylesProvider>
<StyledEngineProvider injectFirst>
<Mui5Provider theme={v5Theme}>{result}</Mui5Provider>
</StyledEngineProvider>
);
}