简体   繁体   English

当部署到 Heroku 时,Mui Autocomplete 与 popper 组件相结合会导致重大泄漏?

[英]Mui Autocomplete combined with a popper component is causing a major leak when deployed to Heroku?

I have the following code for a v4 mui autocomplete component, the issue with it, is that the custom popper component is casing a R14, H10 errors when deploying to heroku, indicating a major memory leak, if I remove this component which servers the purpose of styling, then things works like charm, but the issue is why would this popper component cause such a hidden leak?, took me 17h to find the cause, I tried styling the drop down using the paper component, that is located on the autocomplete as well, but it didn't give me the styling that I want.我有以下 v4 mui 自动完成组件的代码,它的问题是自定义 popper 组件在部署到 heroku 时出现 R14、H10 错误,这表明 memory 主要泄漏,如果我删除此服务于目的的组件样式,然后事情就像魅力一样,但问题是为什么这个 popper 组件会导致这样一个隐藏的泄漏?,我花了 17 小时才找到原因,我尝试使用位于自动完成上的纸质组件对下拉菜单进行样式设置也一样,但它没有给我想要的样式。

 <Autocomplete id='advancedselect' ref={refAutocomplete} options={optionsObj} groupBy={(option: any) => option.name} getOptionLabel={(option) => option.name} renderOption={(option) => ( <React.Fragment> <div style={{ width: '12vw', maxWidth: 75, marginRight: 10 }}> <Icons img={option.equipment} /> </div> {option.name} </React.Fragment> )} disableListWrap // Popper disabeled every thing works fine PopperComponent={(props: any) => <Popper {...props} className={classes.propper} placement='bottom'></Popper>} inputValue={selected.exercise} onInputChange={handleAutoComplete} className={classes.root} renderInput={(params) => ( <TextField error={err.exercise? true: false} onChange={handleTextField} {...params} InputLabelProps={{ shrink: false }} label={selected.option} /> )} />
After long search apparently the rendered item is not getting garbage collated properly I found some solutions but I need help implementing them since I think that is the right way to stop the memory leak from happening 经过长时间的搜索,显然呈现的项目没有得到正确的垃圾整理我找到了一些解决方案,但我需要帮助实施它们,因为我认为这是阻止 memory 泄漏发生的正确方法

below is the logic for garbage collation yet not working以下是垃圾整理的逻辑但无法正常工作

 const [anchorEl, setAnchorEl] = React.useState(null); const handleClick = (event: any) => { setAnchorEl(anchorEl? null: event.currentTarget); }; const popperRefObject = React.useRef(null); React.useEffect(() => { popperRefObject && console.log(popperRefObject.current); }, [anchorEl]); console.log(anchorEl); // Adding ref to to the popper <Popper open={Boolean(anchorEl)} anchorEl={anchorEl} popperRef={popperRef} ref={popperRefObject} // keepMounted {...props} className={classes.propper} placement='top' ></Popper>

You need to reference the the popper when you open and close the menu and set the anchor element to be stable !!您需要在打开和关闭菜单时引用弹出器并将锚元素设置为稳定! so it can be effectively targeted by garbage collection所以它可以被垃圾收集有效地瞄准

 // Create State const [open, setOpen] = useState<any>({ open: false, anchorEl: null }); // Add to the autocomplete component.:. PaperComponent={({ children }) => <Paper className={classes.backDrop}>{children}</Paper>} PopperComponent={(props. any) => <Popper open={open.open} anchorEl={open.anchorEl} {.:,props} className= {classes.propper} placement='bottom'></Popper>} // When close run funciton onClose={() => setOpen({ /*anchorEl. null.*/,::open; open: false })} // When open run function onOpen={(event, any) => { const { currentTarget } = event: setOpen({ anchorEl, currentTarget; open: true, }); }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM