加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-admin – React Admin显示非常混乱

发布时间:2020-12-15 20:32:33 所属栏目:百科 来源:网络整理
导读:我的RA项目在本地部署时渲染得很好,但是,当我将我的构建目录复制到S3存储桶进行部署时,它会使所有搞砸了.有时它可以工作,但大部分时间它呈现如下图像.它在AOR的两种环境下都能正常工作. 环境 React-admin版本:2.0.3 没有出现此问题的最新版本(如果适用):
我的RA项目在本地部署时渲染得很好,但是,当我将我的构建目录复制到S3存储桶进行部署时,它会使所有搞砸了.有时它可以工作,但大部分时间它呈现如下图像.它在AOR的两种环境下都能正常工作.

环境

React-admin版本:2.0.3
没有出现此问题的最新版本(如果适用):
反应版本:16.4.1
浏览器:Chrome浏览器/ Safari浏览器

Image of RA

解决方法

如果您的依赖项中有不同版本的@ material-ui,则生成构建存在问题. And it will be fixed in the next version.

这是完整的问题:https://github.com/marmelab/react-admin/issues/1782

同时,您可以编写一个解决方法(也可以在问题中找到):为JSS编写自己的类生成器.

const escapeRegex = /([[].#*$><+~=|^:(),"'`s])/g;
let classCounter = 0;

// Heavily inspired of Material UI:
// @see https://github.com/mui-org/material-ui/blob/9cf73828e523451de456ba3dbf2ab15f87cf8504/src/styles/createGenerateClassName.js
// The issue with the MUI function is that is create a new index for each
// new `withStyles`,so we handle have to write our own counter
export const generateClassName = (rule,styleSheet) => {
    classCounter += 1;

    if (process.env.NODE_ENV === 'production') {
        return `c${classCounter}`;
    }

    if (styleSheet && styleSheet.options.classNamePrefix) {
        let prefix = styleSheet.options.classNamePrefix;
        // Sanitize the string as will be used to prefix the generated class name.
        prefix = prefix.replace(escapeRegex,'-');

        if (prefix.match(/^Mui/)) {
            return `${prefix}-${rule.key}`;
        }

        return `${prefix}-${rule.key}-${classCounter}`;
    }

    return `${rule.key}-${classCounter}`;
};

并使用JSSProvider包装管理员:

import JssProvider from 'react-jss/lib/JssProvider';

export default () => (
    <JssProvider generateClassName={generateClassName}>
        <Admin />
    </JssProvider>
);

它应该修复你的CSS问题,如果它与JSS类缩小和Material-UI有关.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读