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

feat: onbeforehydrate #7001

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HomyeeKing
Copy link
Contributor

背景

线上hydrate由于报错栈没有参考价值,不能快速修复,在 appConfig 添加 onBeforeHydrate hook 来让开发者获取 hydrate 前后的 DOM 然后上报,用于快速定位问题

使用

// src/app.ts
import { defineAppConfig } from 'ice';

// App config, see https://ice3.alibaba-inc.com/v3/docs/guide/basic/app
export default defineAppConfig(() => {
  let beforeHydrateHtml = '';
  return {
    // Set your configs here.
    app: {
      onRecoverableError(error: any, errorInfo) {

+        // 上报 监控平台
+        if(reportLog){ 
+ 				const currentHtml = document.documentElement.innerHTML
+         reportLog({
+            code: `hydrate 错误 DOM Diff`,
+            message: {
+              beforeHydrateHtml,
+              currentHtml
+            },
+            level: 'Debug',
+          });
+        }
+      },
+      onBeforeHydrate() {
+        beforeHydrateHtml = document.documentElement.innerHTML;
+        console.log('beforeHydrate', document.documentElement.innerHTML);
+      },
+    },
  };
});

效果

获取前后的 DOM 然后 diff 查看差异点
image

@ClarkXia ClarkXia changed the base branch from master to release/next October 10, 2024 03:46
@ClarkXia ClarkXia changed the base branch from release/next to master October 10, 2024 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant