应用程序在刷新后崩溃

时间:2017-10-09 09:58:13

标签: reactjs meteor render

我的应用程序出了问题。一切都很好,直到我按下刷新按钮。我认为它正在发生,因为有些东西尚未准备好呈现。

org.apache.spark.SparkException: Task not serializable
  at org.apache.spark.util.ClosureCleaner$.ensureSerializable(ClosureCleaner.scala:298)
  at org.apache.spark.util.ClosureCleaner$.org$apache$spark$util$ClosureCleaner$$clean(ClosureCleaner.scala:288)
  at org.apache.spark.util.ClosureCleaner$.clean(ClosureCleaner.scala:108)
  at org.apache.spark.SparkContext.clean(SparkContext.scala:2039)
  at org.apache.spark.rdd.RDD$$anonfun$mapPartitionsWithIndex$1.apply(RDD.scala:817)
  ...
  at org.apache.spark.sql.Dataset.head(Dataset.scala:1934)
  at org.apache.spark.sql.Dataset.take(Dataset.scala:2149)
  at org.apache.spark.sql.Dataset.showString(Dataset.scala:239)
  at org.apache.spark.sql.Dataset.show(Dataset.scala:526)
  at org.apache.spark.sql.Dataset.show(Dataset.scala:506)
  ... 46 elided
Caused by: java.io.NotSerializableException: scala.util.matching.Regex$MatchIterator
Serialization stack:
  - object not serializable (class: scala.util.matching.Regex$MatchIterator, value: empty iterator)
  - field (class: $iw, name: mi, type: class scala.util.matching.Regex$MatchIterator)
  - object (class $iw, $iw@79303206)
  - field (class: $iw, name: $iw, type: class $iw)
  ...

知道我应该从render方法中移动那些变量吗?那么它在页面刷新后应该如何工作?非常感谢您的参与。

1 个答案:

答案 0 :(得分:0)

假设订阅管理在此组件上方进行,您可以防止未准备好的数据:

render () {
  const currentFanpage = Fanpages.findOne({fanpageName: this.fanpage});
  if (!currentFanpage) {
    return (
      <div />
    );
  } else {
    const currentGreeting = currentFanpage.fanpageInfo.config.greeting[0].text
    return (
      // your html
    )
  }
}

更好的是,让父组件呈现微调器,直到订阅为.ready()

<强>更新 您询问了如何将createContainerwithRouter一起使用。我通常不会使用withRouter而且我还没有对此进行过测试,但它应该是这样的:

const container = () => {
  const sub = Meteor.subscribe('mysub');
  const loading = sub.ready();
  const user = Meteor.user();
  return { loading, user };
}

export default withRouter(container, Greetings))

重要的是容器的loading密钥与订阅状态相关联。

Container tutorial