ant-design / ant-design/pro-components

👑 [需求] 优化ProLayout 渲染时 child 组件的位置跳动问题

Open
#8,194 3 comments 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4.8k
Forks
1.4k
Avg merge
10h 44m
Merged PRs (30d)
3

Description

### 🔩 所属模块或组件
ProLayout

### 🥰 需求描述

目前第一次访问页面都会出现子组件跳动,用户反馈影响体验。 希望用户首次加载进入页面就能够看到最终的ProLayout Style。

### ⛰ 功能需求适用场景

用户首次进入页面

### 🧐 解决方案

root cause 是因为 PageContainerBase 中的 useEffect 使用 setHasPageContainer 更新state, 导致 WrapperContent 组件更新 contentClassName 中的 `${prefixCls}-content-has-page-container` class 导致css改变。

PageContainer 中 PageContainerBase 组件 useEffect 改用为 useLayoutEffect.

### 🚑 其他信息
子组件第一次渲染
**首次渲染**
![image](https://github.com/ant-design/pro-components/assets/44203829/1a3157c3-6a09-4656-8a84-e45243b3adfc)

useEffect 执行setHasPageContainer 再次渲染,添加 `${prefixCls}-content-has-page-container` 后
![image](https://github.com/ant-design/pro-components/assets/44203829/03ac2b37-0119-4366-a0f8-38f616a0d7d3)

Contributor guide

Open the contributing guide

Research direction

Start in the PageContainer implementation and locate the PageContainerBase component, its useEffect call, and the setHasPageContainer update. Check how this update changes WrapperContent's contentClassName during the first render; done means the initial ProLayout display no longer visibly jumps when the page first loads.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.