【发布时间】:2019-05-26 16:41:06
【问题描述】:
我正在尝试使用 clojurescript 和 re-agent(围绕 react 的包装器)构建浏览器扩展。代码很简单(complete source and repro steps here),大部分是从一个re-agent的例子中复制过来的:
(ns clext2.core
(:require [reagent.core :as r]))
(defn timer-component []
(let [seconds-elapsed (r/atom 0)]
(fn []
(js/setTimeout #(do (println "timeout") (swap! seconds-elapsed inc)) 1000)
[:div "Seconds Elapsed: " @seconds-elapsed])))
(let [app (js/document.createElement "div")
_ (js/document.body.appendChild app)]
(r/render [timer-component] app))
我用:simple优化标志编译了这个,将生成的js复制到Mozilla发布的示例代码中:https://github.com/cljsjs/packages/wiki/Creating-Packages,并在chrome和firefox上加载了扩展。
观察
当我在本地使用 figwheel 进行测试时,计数器会在 chromium 和 firefox 中呈现。
当我导航到一个真实页面时(不使用无花果):
- 使用 Firefox,计数器加载但不增加(
timeout打印一次) - 使用 chrome,计数器会加载并递增(
timeout每秒打印一次)
预期行为
我希望计数器在使用 firefox 时会明显增加,但事实并非如此。
浏览器版本
- Chromium(71.0.3578.98(官方构建)Manjaro Linux(64 位))
- Firefox(manjaro 为 64.0)。
我的问题
我不确定如何进一步调试,接下来我可以尝试什么?
【问题讨论】:
-
我可以在 mac os 上使用最新的 firefox 和 chrome 重现该问题(chrome 有效,firefox 无效)。
标签: reactjs google-chrome firefox chromium clojurescript