FixIt icon indicating copy to clipboard operation
FixIt copied to clipboard

[BUG] 当cookie consent加载失败时目录 & 回到顶部 不显示

Open du33169 opened this issue 2 years ago • 0 comments

Describe the bug 描述你遇到的错误

在开启cookieconsent的同时,如果使用I don't care about cookie之类的浏览器插件访问网站,或者因为其他原因(例如单独配置的CDN失效)导致cookieconsent.min.js无法加载时,会导致页面的目录和回到顶部按钮不显示。

根据报错可以定位到是由于theme.js中,当cookieconsent加载失败时,抛出异常导致后续步骤无法执行。

init() {
    try {
      if (this.config.encryption) {
        this.initFixItDecryptor();
      } else if (!this.config.encryption?.all) {
        this.initTwemoji();
        this.initDetails();
        this.initLightGallery();
        this.initHighlight();
        this.initTable();
        this.initHeaderLink();
        this.initMath();
        this.initMermaid();
        this.initEcharts();
        this.initTypeit();
        this.initMapbox();
        this.initPangu();
      }
      this.initThemeColor();
      this.initSVGIcon();
      this.initMenu();
      this.initSwitchTheme();
      this.initSearch();
      this.initCookieconsent();//here
      this.initSiteTime();
      this.initServiceWorker();
      this.initWatermark();
      this.initMDevtools();
      this.initAutoMark();
      this.initReward();

      window.setTimeout(() => {
        this.initComment();
        if (!this.config.encryption?.all) {
          this.initToc();
          this.initTocListener();
        }
        this.onScroll();
        this.onResize();
        this.onClickMask();
        this.beforeprint();
      }, 100);
    } catch (err) {
      console.error(err);
    }
  }

Expected behavior 期待的行为

对于cookieConsent这类提供额外功能且独立于其他部分的第三方资源的初始化过程,是否可以改为异步执行以避免某个模块的资源加载失败导致影响页面功能?

这应该也有助于提供页面加载速度。

Screenshots 屏幕截图

image

image

Build Environment 构建环境

No response

Preview Environment 预览环境

No response

Additional Information 补充信息

No response

du33169 avatar Apr 01 '23 07:04 du33169