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

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. #4938

Open
qddegtya opened this issue Aug 4, 2024 · 3 comments · May be fixed by #4939

Comments

@qddegtya
Copy link

qddegtya commented Aug 4, 2024

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

@iBug
Copy link
Collaborator

iBug commented Aug 4, 2024

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

@qddegtya qddegtya changed the title [bug] js error under home or splash layout [bug] when open some page with home or splash layout, there's js error on browser console. Aug 4, 2024
@qddegtya qddegtya changed the title [bug] when open some page with home or splash layout, there's js error on browser console. [bug] when open some page with home or splash layout, there's js error in browser console. Aug 4, 2024
@qddegtya qddegtya changed the title [bug] when open some page with home or splash layout, there's js error in browser console. When open some page with home or splash layout, there's js error in browser console. Aug 4, 2024
@qddegtya
Copy link
Author

qddegtya commented Aug 4, 2024

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 的代码并不会直接影响页面渲染,但这是事实上的代码逻辑错误,应该优化一下。

@iBug
Copy link
Collaborator

iBug commented Aug 4, 2024

可以,你开 PR 吧。

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

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

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

qddegtya added a commit to qddegtya/minimal-mistakes that referenced this issue Aug 4, 2024
@qddegtya qddegtya linked a pull request Aug 4, 2024 that will close this issue
@qddegtya qddegtya changed the title When open some page with home or splash layout, there's js error in browser console. 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. Aug 4, 2024
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 a pull request may close this issue.

2 participants