Skip to content

Commit 5ed58d7

Browse files
authored
fix for global vars caused by certain ids causing issues with init (#386)
1 parent 499f1db commit 5ed58d7

2 files changed

Lines changed: 24 additions & 21 deletions

File tree

src/components/Template/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React from "react"
2-
import PropTypes from "prop-types"
31
import Head from "next/head"
2+
import PropTypes from "prop-types"
3+
import React from "react"
4+
import pkg from "../../../package.json"
45
import Hero from "./Hero"
56
import Tocbot from "./Tocbot"
67
import Tracking from "./Tracking"
7-
import pkg from "../../../package.json"
88

99
function Template(props) {
1010
return (

src/js/index-dist.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
/* globals define */
22

33
import * as tocbot from "./index-esm.js"
4-
;(function (root, factory) {
4+
;((root, factory) => {
55
if (typeof define === "function" && define.amd) {
66
define([], factory(root))
7-
} else if (typeof exports === "object") {
7+
} else if (typeof exports === "object" && !(exports instanceof HTMLElement)) {
88
module.exports = factory(root)
99
} else {
1010
root.tocbot = factory(root)
1111
}
12-
})(typeof global !== "undefined" ? global : window || global, function (root) {
13-
"use strict"
12+
})(
13+
typeof global !== "undefined" && !(global instanceof HTMLElement)
14+
? global
15+
: window || global,
16+
(root) => {
17+
// Just return if its not a browser.
18+
const supports =
19+
!!root &&
20+
!!root.document &&
21+
!!root.document.querySelector &&
22+
!!root.addEventListener // Feature test
23+
if (typeof window === "undefined" && !supports) {
24+
return
25+
}
1426

15-
// Just return if its not a browser.
16-
const supports =
17-
!!root &&
18-
!!root.document &&
19-
!!root.document.querySelector &&
20-
!!root.addEventListener // Feature test
21-
if (typeof window === "undefined" && !supports) {
22-
return
23-
}
24-
25-
// Make tocbot available globally.
26-
root.tocbot = tocbot
27+
// Make tocbot available globally.
28+
root.tocbot = tocbot
2729

28-
return tocbot
29-
})
30+
return tocbot
31+
},
32+
)

0 commit comments

Comments
 (0)