minimal-mistakes icon indicating copy to clipboard operation
minimal-mistakes copied to clipboard

When open some page with home or splash layout, there's js error [Uncaught TypeError: Cannot read properties of null (reading 'querySelectorAll')] in browser console.

Open qddegtya opened this issue 1 year ago • 3 comments
trafficstars

What happened?

  • Minimal Mistakes version: 4.26.2
  • Ruby gem or remote theme version: 4.26.2
  • Jekyll version: 3.9.5
  • Git repository URL:
  • Hosted on GitHub Pages (if yes provide URL to site): [Hosted on Vercel]
  • Operating system: Hosted on Vercel

Expected behavior

// https://github.com/mmistakes/minimal-mistakes/blob/master/assets/js/_main.js#L127
// Suggestion: Optimize code logic with IIFE to check if page__content element is exists.
(function () {
  var pageContentElement = document.querySelector(".page__content");
  if (!pageContentElement) return;

  pageContentElement.querySelectorAll("h1, h2, h3, h4, h5, h6")
    .forEach(function (element) {
      var id = element.getAttribute("id");
      if (id) {
        var anchor = document.createElement("a");
        anchor.className = "header-link";
        anchor.href = "#" + id;
        anchor.innerHTML =
          '<span class="sr-only">Permalink</span><i class="fas fa-link"></i>';
        anchor.title = "Permalink";
        element.appendChild(anchor);
      }
    });
})();

Steps to reproduce the behavior

  1. Started up a Jekyll server locally.
  2. Open some page with home or splash layout then Open Developer Tool in browser.
截屏2024-08-05 02 47 34

Other

No response

qddegtya avatar Aug 04 '24 18:08 qddegtya

Please elaborate on what is wrong. As is currently written, this is not a bug report.

iBug avatar Aug 04 '24 18:08 iBug

Please elaborate on what is wrong. As is currently written, this is not a bug report.

看 UserId,以为是 Bot,I'M SORRY. 😄 如果需要的话,我可以直接提 PR,我看你也是「国内开发者」,因此直接中文沟通了,这是一段 _main.js 里的报错,没有做防御逻辑,在 Home 或者 Splash Layout 里并不会渲染 page__content,所以会直接导致相关页面执行到这里的时候,浏览器控制台有错误输出,虽然这个 feature 的代码并不会直接影响页面渲染,但这是事实上的代码逻辑错误,应该优化一下。

qddegtya avatar Aug 04 '24 18:08 qddegtya

可以,你开 PR 吧。

我的回复是要求报 bug 时把所有信息讲清楚,特别是「有 error」→「有什么 error」,并且最好能把报错内容附在 issue 正文里。你这样只贴一段代码还说「自己去看」,没有人能看出来你要报的是什么 bug。

(此条针对你 edit 前的 issue,但以后也请注意)

剩下的自己去看《提问的智慧》吧。

iBug avatar Aug 04 '24 18:08 iBug