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

RFC:完善 Umi 的 Link Prefetch 功能 #12842

Closed
sorrycc opened this issue Dec 11, 2024 · 0 comments · Fixed by #12844
Closed

RFC:完善 Umi 的 Link Prefetch 功能 #12842

sorrycc opened this issue Dec 11, 2024 · 0 comments · Fixed by #12844

Comments

@sorrycc
Copy link
Member

sorrycc commented Dec 11, 2024

问题

目前我们提供了 routePrefetch 的配置,开启后,会对 Link 做基于 preload=intent 的处理,即基于意图当用户鼠标进来时做对应路由的 preload。

存在的问题:

1、功能太单一,参考 #12825 缺少 render、viewport 策略的支持
2、intent 没有做 timeout,所以一滑而过的也会做 preload

方案

1、修改 routePreload 配置类型为 'intent' | 'render' | 'viewport' | true | false,为兼容老功能,true 即为 'intent',此为全局配置
2、允许用户通过 <Link preload="none|intent|render|viewport" /> 覆盖默认行为
3、intent 策略增加 timeout 操作,默认为 50,并允许通过 routePreloadTimeout 配置进行修改
4、render 策略在 useLayoutEffect 下做
5、viewport 策略用 IntersectionObserver 监听 Link 元素是否进入 viewport 来做,会有一定的兼容性问题,不过低版本浏览器就不做支持了(文档上说明)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant