# DiscoTOC 问题：TypeError：\_offsetCalculator.headerOffset 不是一个函数

**URL:** https://meta.discourse.org/t/problem-with-discotoc-typeerror-offsetcalculator-headeroffset-is-not-a-function/219710
**Category:** Bug
**Created:** [2022年三月1日 15:08 UTC](https://meta.discourse.org/t/problem-with-discotoc-typeerror-offsetcalculator-headeroffset-is-not-a-function/219710 "2022-03-01T15:08:26Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![amotl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/amotl/32/109873_2.png) [@amotl](https://meta.discourse.org/u/amotl)
#### Post date: [2022年三月1日 15:08 UTC](https://meta.discourse.org/t/problem-with-discotoc-typeerror-offsetcalculator-headeroffset-is-not-a-function/219710/1 "2022-03-01T15:08:26Z")

</div>

尊敬的 Discourse 团队，尊敬的 @Johani：

非常感谢您提供的出色的 Discourse 插件 [https://meta.discourse.org/t/discotoc-automatic-table-of-contents/111143。](https://meta.discourse.org/t/discotoc-automatic-table-of-contents/111143%E3%80%82)

昨天，有用户报告称 TOC 导航在 [community.hiveeyes.org](http://community.hiveeyes.org) 上停止工作，您可以在 \[1\] 找到一个示例。该实例运行的是 Discourse 2.8.0.beta10 和最新的 DiscoTOC，是从主题组件管理器升级的。

在另外两个 Discourse 实例上，一切似乎都正常：

- 2.8.0.beta10（自托管），DiscoTOC _落后 17 个提交，在 [5b051e18](https://github.com/discourse/DiscoTOC/commit/5b051e18)_ \[2\]
- 2.9.0.beta2（商业计划），DiscoTOC _落后 1 个提交，在 [9933031](https://github.com/discourse/DiscoTOC/commit/9933031)_ \[3\]

您认为这可能是由于我们在系统中安装的其他插件 \[4\] 造成的吗？到目前为止，我们从未遇到过与 DiscoTOC 类似的任何问题。

提前感谢您花时间调查此事。我们倾向于认为这是我们这边的一个小问题，因为我们还没有发现其他人的类似报告。从另一个角度来看，这里的结果也可能有助于其他人观察到类似的情况。

此致，  
Andreas。

* * *

Firefox 浏览器控制台中的错误是 `Uncaught TypeError: _offsetCalculator.headerOffset is not a function`，发生在 `updateTOCSidebar` 函数中。

 ![image](https://global.discourse-cdn.com/meta/original/3X/5/f/5f024505d424be9926f13621ac452e0e506d62db.jpeg)  
 ![image](https://global.discourse-cdn.com/meta/original/3X/6/f/6fc0eb40e87832ae7432cc8c3e3cc1d9cedbb8f8.jpeg)

* * *

1. [Installation von Saraswati auf SBC-Systemen (Debian), mit Upload per rsync oder FTP - BOB-Anleitungen - Hiveeyes](https://community.hiveeyes.org/t/installation-von-saraswati-auf-sbc-systemen-debian-mit-upload-per-rsync-oder-ftp/4084) 

2. [Panodata Map Panel for Grafana - The workbench - Panodata Community](https://community.panodata.org/t/panodata-map-panel-for-grafana/121) 

3. [Interpolating missing time-series values - Tutorials - CrateDB Community](https://community.crate.io/t/interpolation-of-missing-time-series-values/1010) 

4. 安装的插件。

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2022年三月1日 17:34 UTC](https://meta.discourse.org/t/problem-with-discotoc-typeerror-offsetcalculator-headeroffset-is-not-a-function/219710/2 "2022-03-01T17:34:12Z")

</div>

插件 footnote 在移动设备上有点难读。我也会在这里列出一个列表，以便更清楚地显示。👍 （目前没有明显冲突，但其他人可能会发现问题）

> **已安装插件：**
>
> > [@amotl](#):
> >
> > 已安装插件。  
> > - [GitHub - discourse/docker\_manager: Plugin for use with discourse docker image](https://github.com/discourse/docker_manager.git)  
> > - [GitHub - discourse/discourse-translator](https://github.com/discourse/discourse-translator.git)  
> > - [GitHub - discourse/discourse-checklist: A simple checklist rendering plugin for discourse](https://github.com/discourse/discourse-checklist.git)  
> > - [GitHub - discourse/discourse-assign: Plugin for assigning users to a topic](https://github.com/discourse/discourse-assign.git)  
> > - [GitHub - discourse/discourse-solved: Allow accepted answers on topics](https://github.com/discourse/discourse-solved.git)  
> > - [GitHub - discourse/discourse-chat-integration](https://github.com/discourse/discourse-chat-integration.git)  
> > - [GitHub - discourse/discourse-math: Official MathJax support for Discourse](https://github.com/discourse/discourse-math.git)  
> > - [GitHub - discourse/discourse-calendar: Adds the ability to create a dynamic calendar in the first post of a topic.](https://github.com/discourse/discourse-calendar.git)  
> > - [GitHub - discourse/discourse-footnote: footnotes for posts in Discourse](https://github.com/discourse/discourse-footnote.git)  
> > - [GitHub - discourse/discourse-graphviz: Adds the Viz.js library to discourse](https://github.com/discourse/discourse-graphviz.git)  
> > - [GitHub - discourse/discourse-sitemap: Generate XML sitemap for your Discourse forum.](https://github.com/discourse/discourse-sitemap.git)  
> > - [GitHub - discourse/discourse-docs](https://github.com/discourse/discourse-docs.git)  
> > - [GitHub - discourse/discourse-data-explorer: SQL Queries for admins in Discourse](https://github.com/discourse/discourse-data-explorer.git)  
> > - [GitHub - paviliondev/discourse-tickets: Ticketing system for Discourse](https://github.com/angusmcleod/discourse-tickets.git)  
> > - [GitHub - angusmcleod/discourse-events: Allows you to manage events in Discourse](https://github.com/angusmcleod/discourse-events.git)  
> > - [GitHub - merefield/discourse-locations: Tools for handling locations in Discourse](https://github.com/angusmcleod/discourse-locations.git)  
> > - [GitHub - paviliondev/discourse-custom-wizard: A Discourse Plugin that allows you to create custom user wizards.](https://github.com/angusmcleod/discourse-custom-wizard.git)  
> > - [GitHub - communiteq/discourse-suppress-category-from-latest](https://github.com/discoursehosting/discourse-suppress-category-from-latest.git)  
> > - [GitHub - discourse/discourse-yearly-review: Publishes an automated Year in Review topic](https://github.com/discourse/discourse-yearly-review.git)

---

<div class="post-metadata">

### Author: ![amotl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/amotl/32/109873_2.png) [@amotl](https://meta.discourse.org/u/amotl)
#### Post date: [2022年三月1日 18:38 UTC](https://meta.discourse.org/t/problem-with-discotoc-typeerror-offsetcalculator-headeroffset-is-not-a-function/219710/3 "2022-03-01T18:38:26Z")

</div>

你好，

在按照 `updateTOCSidebar:210` 的引用时，Firefox 显示了这段代码

```javascript
210: var distance = Math.abs(_domUtils.default.offset(heading).top - (0, _offsetCalculator.headerOffset)() - window.scrollY);

```

并指示可能存在语法错误

![image](https://cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/optimized/3X/7/3/733f1342c4dcbd4ab55d050e5fc45737d745f7f0_2_517x43.png)

而原始代码是

> <https://github.com/discourse/DiscoTOC/blob/7bf7b95/javascripts/discourse/initializers/disco-toc-main.js#L108-L110>

你认为这可能是 [REFACTOR: General component overhaul by pmusaraj · Pull Request #19 · discourse/DiscoTOC · GitHub](https://github.com/discourse/DiscoTOC/pull/19) 的初期问题吗，@pmusaraj？

可以在我们的公共 Discourse 实例上检查这一点，例如在页面 [Installation von Saraswati auf SBC-Systemen (Debian), mit Upload per rsync oder FTP - BOB-Anleitungen - Hiveeyes](https://community.hiveeyes.org/t/installation-von-saraswati-auf-sbc-systemen-debian-mit-upload-per-rsync-oder-ftp/4084) 上。

此致，  
Andreas。

/cc @eviltrout, @cvx, @j.jaffeux

---

<div class="post-metadata">

### Author: ![Benjamin\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/benjamin_d/32/277831_2.png) [@Benjamin\_D](https://meta.discourse.org/u/Benjamin_D)
#### Post date: [2022年三月1日 21:21 UTC](https://meta.discourse.org/t/problem-with-discotoc-typeerror-offsetcalculator-headeroffset-is-not-a-function/219710/4 "2022-03-01T21:21:32Z")

</div>

我发现 DiscoTOC 自 1 月 18 日重构以来使用的 `headerOffset` 出现在 `app/assets/javascripts/discourse/app/lib/offset-calculator.js` 中 [在此提交](https://github.com/discourse/discourse/commit/1ed2520589d988cc3299f8a85c8a20ade502f45d#diff-ee360fb09f76b3326cb85fe1cf363e30b3cc98e7d783dc97910f85dff0641990) 中，时间是 1 月 7 日，介于 2.8.0.beta10（12 月 21 日）和 2.8.0.beta11（1 月 13 日）之间。

---

<div class="post-metadata">

### Author: ![amotl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/amotl/32/109873_2.png) [@amotl](https://meta.discourse.org/u/amotl)
#### Post date: [2022年三月1日 21:55 UTC](https://meta.discourse.org/t/problem-with-discotoc-typeerror-offsetcalculator-headeroffset-is-not-a-function/219710/5 "2022-03-01T21:55:05Z")

</div>

那么我们应该升级 Discourse，或者将 DiscoTOC 降级到重构之前的版本，对吗？谢谢！

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2022年三月1日 22:48 UTC](https://meta.discourse.org/t/problem-with-discotoc-typeerror-offsetcalculator-headeroffset-is-not-a-function/219710/6 "2022-03-01T22:48:27Z")

</div>

> [@amotl](#):
>
> 升级 Discourse

是的。

在报告 bug 之前，您应该始终做的一件事是尝试查看它是否仍然存在于最新的 `{tests-passed|stable}` 上。

---

<div class="post-metadata">

### Author: ![amotl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/amotl/32/109873_2.png) [@amotl](https://meta.discourse.org/u/amotl)
#### Post date: [2022年三月2日 12:46 UTC](https://meta.discourse.org/t/problem-with-discotoc-typeerror-offsetcalculator-headeroffset-is-not-a-function/219710/7 "2022-03-02T12:46:13Z")

</div>

> [@RGJ](#):
>
> 在报告 bug 之前，你应该始终尝试查看它是否仍然存在于最新的 `{tests-passed|stable}` 版本中。

没问题，非常感谢！

~~但是~~ 我还有另一种关于报告的观点想在此分享：为搜索引擎提供信息，以便为遇到相同错误的其他用户提供如何处理和缓解该问题的指南。

例如：“嘿，这里发生了什么？浏览器控制台中出现“Uncaught TypeError”？我马上把它粘贴到搜索框里。啊，对了，找到了——我看到，只需升级 Discourse 或降级 DiscoTOC 即可。谢谢，再见。”

 ![image](https://global.discourse-cdn.com/meta/original/3X/b/3/b311fd6ea21ec40ca0c247d30203a40b858f8738.png)  
 ![image](https://global.discourse-cdn.com/meta/original/3X/4/7/470679834abdc8045439588c37607d2d00680d2c.png)

非常感谢 Richard 提供的快速支持！非常感激。

---

<div class="post-metadata">

### Author: ![amotl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/amotl/32/109873_2.png) [@amotl](https://meta.discourse.org/u/amotl)
#### Post date: [2022年三月4日 11:52 UTC](https://meta.discourse.org/t/problem-with-discotoc-typeerror-offsetcalculator-headeroffset-is-not-a-function/219710/8 "2022-03-04T11:52:16Z")

</div>

你好，

我们想汇报一下，在升级到 Discourse 2.9.0.beta2 后，一切又恢复正常了。

非常感谢，此致，  
Andreas。

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2022年三月8日 00:49 UTC](https://meta.discourse.org/t/problem-with-discotoc-typeerror-offsetcalculator-headeroffset-is-not-a-function/219710/9 "2022-03-08T00:49:23Z")

</div>


