You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ember从3.16升级到5.12后store.pushPayload报错:标识符不属于当前store实例

Ember 3.16升级至5.12(Ember Data 5.3.0)的Store实例问题

近期将Ember项目从3.16版本升级至5.12版本(同步升级ember-data至5.3.0)。以下代码在Ember 3.16中无需显式注入store服务即可正常运行:

// =========route.ts============
export default class TopologyViewRoute {
      // == Dependencies ==========================================================
      @service notifier: any
      @service store: any           // 这段代码在Ember 3.16中无需添加即可正常运行
      
      constructor () {
        super(...arguments)
        this.rFetch = new RFetch(genericTopologyAdapter, genericTopologySerializer, genericTopologyParser)
      }
      
      @task({restartable: true})
      * _fetchT (): TaskGenerator<object> {
        const topologies = yield this.rFetch.fetch({
            adapterOptions: {
              context: this.contextPayload
            },
            serializerOptions: {
              store: this.store
            }
          })
          return topologies
      }
    }
// ===========addon/rfetch.ts===============
    
async fetch (
    {adapterOptions = {}, serializerOptions = {}} :
    RFetchOptions = {adapterOptions: {}, serializerOptions: {}}
  ): Promise<RFetchResult> {
    const {url, fetchOptions} = this.adapter(adapterOptions)
    const response = await fetch(url, fetchOptions || {})
    const payload = await response.json()
    return {payload, normalized: this.serializer(payload, serializerOptions)}
  }
// ============addon/generic-topo.js  =================
export function genericTopologySerializer (payload: Document, {store}: {store: Store}) {
  const includedHash = _.keyBy(payload.included, 'id')

  const formattedIncluded = payload.included?.reduce((currentIncluded, element) => {
    _.set(element, 'attributes.externalSource', element.meta?.externalSource)

    const updatedElement = _getUpdatedAggregateElement({element, includedHash})

    return [...currentIncluded, updatedElement]
  }, [])

  const includedForStore = formattedIncluded?.filter((object: ResourceIdentifier) => object.type !== 'topologies') || []
  if (includedForStore) store.pushPayload({data: includedForStore})  // 若不在TopologyViewRoute中注入store,此处store为null

  return {...payload, included: formattedIncluded}
}

升级后,先遇到了**"无法在undefined上调用pushPayload"**的错误,通过注入store服务解决了该问题,但随后出现了新错误:

The supplied identifier {"type":"management-session","id":"19dc2cfe-e028-4bfd-a162-a12b5e352d6b","lid":"@lid:management-session-19dc2cfe-e028-4bfd-a162-a12b5e352d6b"} does not belong to this store instance

不清楚为何会出现该store相关报错,明明传递并使用的是同一个store。是否存在遗漏的其他废弃特性?


内容的提问来源于stack exchange,提问作者Saurabh Batra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 20:05:58