Fix #4701: Odd behavior on older versions of Chrome.
Regression caused by the upgrade to Webpacker 6.0 in 90cd3293e. This
caused various Javascript errors in old versions of Chrome, which
somehow resulted in the keyboard shortcut for visiting the next page
being triggered when you pressed any key.
Specifically, the mobx library (used by the TagCounter component) called
`Object.entries`, which isn't available in Chrome 49, and for some
unknown reason this triggered the buggy shortcut behavior.
`Object.entries` is supposed to be automatically polyfilled by Babel to
support old browsers, but something changed in Webpacker 6 that broke
this and I couldn't get it working again. The probable cause is that
Webpacker 6 no longer transpiles code inside ./node_modules by default,
which means that any libraries we use that use new Javascript features
won't get transpiled down to support old browsers, but even after fixing
that it still didn't work. The workaround is to just drop mobx and
preact entirely to avoid the issue.
This commit is contained in:
@@ -1,39 +1,29 @@
|
||||
import { h, Component, render } from "preact";
|
||||
import { makeObservable, observable, computed, action } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
|
||||
import Utility from "./utility";
|
||||
|
||||
export default @observer class TagCounter extends Component {
|
||||
export default class TagCounter {
|
||||
static lowCount = 10;
|
||||
static highCount = 20;
|
||||
|
||||
@observable tagCount = 0;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
makeObservable(this);
|
||||
constructor($element) {
|
||||
this.$element = $element;
|
||||
this.$target.on("input", (event) => this.update(event));
|
||||
this.update();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
$(this.props.tags).on("input", this.updateCount);
|
||||
this.updateCount();
|
||||
update() {
|
||||
this.$element.find(".tag-count").text(`${this.tagCount} / ${TagCounter.highCount} tags`);
|
||||
this.$element.find("img").attr("src", `/images/${this.iconName}.png`);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<span class="tag-counter">
|
||||
<span class="tag-count">{this.tagCount}</span> / {TagCounter.highCount} tags
|
||||
<img src={`/images/${this.iconName}.png`}/>
|
||||
</span>
|
||||
);
|
||||
get $target() {
|
||||
return $(this.$element.attr("data-for"));
|
||||
}
|
||||
|
||||
@action.bound updateCount() {
|
||||
this.tagCount = Utility.regexp_split($(this.props.tags).val()).length;
|
||||
get tagCount() {
|
||||
return Utility.regexp_split(this.$target.val()).length;
|
||||
}
|
||||
|
||||
@computed get iconName() {
|
||||
get iconName() {
|
||||
if (this.tagCount < TagCounter.lowCount) {
|
||||
return "blobglare";
|
||||
} else if (this.tagCount >= TagCounter.lowCount && this.tagCount < TagCounter.highCount) {
|
||||
@@ -45,8 +35,7 @@ export default @observer class TagCounter extends Component {
|
||||
|
||||
static initialize() {
|
||||
$("[data-tag-counter]").toArray().forEach(element => {
|
||||
let target = $($(element).attr("data-for")).get(0);
|
||||
render(h(TagCounter, { tags: target }), element);
|
||||
new TagCounter($(element));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user