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

iframe 会刷新页面 #31

Open
erlei22 opened this issue Jan 27, 2021 · 16 comments
Open

iframe 会刷新页面 #31

erlei22 opened this issue Jan 27, 2021 · 16 comments
Labels
wontfix This will not be worked on

Comments

@erlei22
Copy link

erlei22 commented Jan 27, 2021

https://codesandbox.io/s/umi-keep-alive-tabs-demo-forked-teqs5?file=/src/pages/setting.js

@CJY0208
Copy link
Member

CJY0208 commented Jan 28, 2021

iframe 的问题已经记录过了,不过没找到解决方式,原因是对 iframe 标签进行的 dom 移位操作一律会引起刷新,但 keep-alive 的工作方式是必须进行 dom 移位...

@chj-damon
Copy link
Contributor

没看懂,刷新页面是指什么?

@CJY0208
Copy link
Member

CJY0208 commented Jan 28, 2021

@chj-damon 就是 iframe 内部会执行 location.reload() 之类的操作
只要 iframe 的 dom 节点位置挪了一下都会触发,reload 后内部的状态就丢掉了

@Aaron52077
Copy link

Aaron52077 commented Jul 26, 2022

@CJY0208 https://wuli-admin.gitee.io/react-mat-pro/#/dashboard 利用react-activation + ReactDom.createPortal 实现的缓存

@CJY0208
Copy link
Member

CJY0208 commented Jul 26, 2022

@CJY0208 https://github.com/CJY0208)https://wuli-admin.gitee.io/react-antd-template/#/dashboard 利用react-activation + ReactDom.createPortal 实现的缓存

没看明白,似乎没有发生 dom 移位,感觉不一定是 activation 在生效

@Aaron52077
Copy link

Aaron52077 commented Jul 26, 2022

@CJY0208 https://wuli-admin.gitee.io/react-antd-template/#/dashboard 利用react-activation + ReactDom.createPortal 实现的缓存

没看明白,似乎没有发生 dom 移位,感觉不一定是 activation 在生效

keepAlive嵌入outlet缓存的name,只是把iframe组件通过createPortal转移到keepAlive外层

@CJY0208
Copy link
Member

CJY0208 commented Jul 26, 2022

@Aaron52077 也就是需要对 keep alive 内的 iframe 做手动处理

@Aaron52077
Copy link

@Aaron52077 也就是需要对 keep alive 内的 iframe 做手动处理

无需处理

@CJY0208
Copy link
Member

CJY0208 commented Jul 26, 2022

代码能看一下嘛?我看看有没有可能搬到 activation 内部

@Aaron52077
Copy link

Aaron52077 commented Jul 26, 2022

代码能看一下嘛?我看看有没有可能搬到 activation 内部

import React, { CSSProperties, useMemo } from "react";
import { useLocation, useOutlet, useParams } from "react-router-dom";
import { Layout } from "antd";
import KeepAlive from "react-activation";
import { MAT_KEEP_ALIVE } from "@/components/keep-alive/constant";
import { useSelector } from "react-redux";
import { getAppStoreState } from "@/store/getters";

interface PageContentProps {
  style?: CSSProperties;
}

const MatPageContent: React.FC<PageContentProps> = ({ style }) => {
  const { currentRoute } = useSelector(getAppStoreState);
  const { pathname } = useLocation();
  const params = useParams();
  const outlet = useOutlet();
  const dispalyIframe = useMemo(() => (params.frameId ? "block" : "none"), [params.frameId]);

  return (
    <Layout.Content className="mat-layout-content" style={{ ...style }}>
      <KeepAlive name={currentRoute.id} id={pathname} when={[currentRoute.keepAlive, true]}>
        {outlet}
      </KeepAlive>

      <div id={MAT_KEEP_ALIVE} style={{ display: dispalyIframe }} />
    </Layout.Content>
  );
};

export default MatPageContent;

@AndyJinSS
Copy link

@CJY0208 https://wuli-admin.gitee.io/react-mat-pro/#/dashboard 利用react-activation + ReactDom.createPortal 实现的缓存

请问React Mat Pro有开源吗?

@Aaron52077
Copy link

@CJY0208 https://wuli-admin.gitee.io/react-mat-pro/#/dashboard 利用react-activation + ReactDom.createPortal 实现的缓存

请问React Mat Pro有开源吗?

暂时没有,还在完善一些功能

@Aaron52077
Copy link

@CJY0208 https://wuli-admin.gitee.io/react-mat-pro/#/dashboard 利用react-activation + ReactDom.createPortal 实现的缓存

请问React Mat Pro有开源吗?

https://gitee.com/wuli-admin/angular-mat-pro/tree/react18/

@ALongLi
Copy link

ALongLi commented Jun 14, 2023

createPortal的实现能看下吗

@zhangpanjun
Copy link

这个问题有后续吗?有解决demo吗 @CJY0208

@sodagreen574
Copy link

@CJY0208 https://wuli-admin.gitee.io/react-mat-pro/#/dashboard 利用react-activation + ReactDom.createPortal 实现的缓存

请问React Mat Pro有开源吗?

https://gitee.com/wuli-admin/angular-mat-pro/tree/react18/

https://wuli-admin.gitee.io/react-mat-pro/ 老哥,,这个项目方便开源吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

8 participants