fix: metadata 缺失时 Object.entries 导致页面整页崩溃,增加判空#294
Open
chirschou wants to merge 1 commit into
Open
Conversation
开源版 polaris-server 不返回 namespace/instance 的 metadata 字段, checkGlobalRegistry 与 getSourcePolairisIp 对 undefined 调用 Object.entries 会使 namespace/服务/实例等页面整页白屏。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
搭配开源版 polaris-server(任意版本,含 main 构建)使用时,命名空间、服务列表、服务别名、熔断规则、实例列表等页面整页白屏崩溃:
根因
开源版 polaris-server 的 namespace / instance 响应中不包含
metadata字段(store/mysql/namespace.go等存储层不读取该列,空 map 在序列化时也会被省略),而前端两处代码对其无条件调用Object.entries:web/src/polaris/service/utils.tsx—checkGlobalRegistry(),被命名空间/服务/别名/熔断等列表页的每行渲染调用;web/src/polaris/service/detail/instance/getColumns.tsx—getSourcePolairisIp(),实例列表"来源北极星IP"列调用。Object.entries(undefined)抛出 TypeError,导致 React 渲染整体崩溃。修复
两处均改为
Object.entries(x.metadata ?? {}),metadata 缺失时按"无标记"处理,行为与存在空 metadata 时一致。验证
已在本地环境(polaris-server v1.18.1 / v1.17.8.1 + MySQL 存储)构建验证:修复后命名空间等页面正常渲染,
internal-sync-from-local-registry标记逻辑在 metadata 存在时行为不变。