前提
MUIを活用してReactでWebサイトを作成中。
実現したいこと
MUIの標準ボタンを使いたい。
発生している問題・エラーメッセージ
サーバーにデプロイし、ページを開く or リロードするとstyleが一瞬適用され、すぐにstyleが解除されてしまう。
Chromeでのみ発生。safariやfirefoxでは発生していない。
該当のソースコード
create-react-appの不要なものを削除したものに、MUIのボタンを入れ込んでいます。
デプロイするサーバーの関係上、package.jsonに『 "homepage": ".",』を追加しています。
jsx
1//index.js 2 3import React from "react"; 4import ReactDOM from "react-dom/client"; 5import App from "./App"; 6 7const root = ReactDOM.createRoot(document.getElementById("root")); 8root.render( 9 <React.StrictMode> 10 <App /> 11 </React.StrictMode> 12);
jsx
1//App.js 2 3import Button from "@mui/material/Button"; 4 5function App() { 6 return ( 7 <div className="App"> 8 <Button variant="text">Text</Button> 9 <Button variant="contained">Contained</Button> 10 <Button variant="outlined">Outlined</Button> 11 </div> 12 ); 13} 14 15export default App;
package.json
1{ 2 "name": "test-app", 3 "version": "0.1.0", 4 "homepage": ".", 5 "private": true, 6 "dependencies": { 7 "@emotion/react": "^11.10.4", 8 "@emotion/styled": "^11.10.4", 9 "@mui/material": "^5.10.4", 10 "@mui/system": "^5.10.4", 11 "@testing-library/jest-dom": "^5.16.5", 12 "@testing-library/react": "^13.4.0", 13 "@testing-library/user-event": "^13.5.0", 14 "react": "^18.2.0", 15 "react-dom": "^18.2.0", 16 "react-scripts": "5.0.1", 17 "web-vitals": "^2.1.4" 18 }, 19 "scripts": { 20 "start": "react-scripts start", 21 "build": "react-scripts build", 22 "test": "react-scripts test", 23 "eject": "react-scripts eject" 24 }, 25 "eslintConfig": { 26 "extends": [ 27 "react-app", 28 "react-app/jest" 29 ] 30 }, 31 "browserslist": { 32 "production": [ 33 ">0.2%", 34 "not dead", 35 "not op_mini all" 36 ], 37 "development": [ 38 "last 1 chrome version", 39 "last 1 firefox version", 40 "last 1 safari version" 41 ] 42 } 43} 44
試したこと
原因を切り分けるべく最低限のシステムにしてみた。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。