0

I have recently updated my ember project code from ember 3.16 to ember 5.12 (and ember-data to 5.3.0)

The following piece of code worked fine in ember 3.16 (without even injecting the store service explicitly).

// =========route.ts============
export default class TopologyViewRoute {
      // == Dependencies ==========================================================
      @service notifier: any
      @service store: any           // The code worked find w/o this line in 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})  // store is null if not injected in TopologyViewRoute
    
      return {...payload, included: formattedIncluded}
    }

But after updating ember, I started getting error "can't call pushPayload on undefined", which I resolved by injecting the store service. But since then, I am getting below error

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

I am not sure why is it complaining about the store and I am passing and using the same store. Is there any other deprecation that I might be missing?

2
  • I notice that your Route does not extend from @ember/routing/route, or for that matter, @ember/object. I don't think without that your service injections would work in either Ember 3.16 or Ember 5.12 Commented Jun 24 at 16:50
  • Also please check your model and ensure it is created with the same store instance as the one used here. This may not be the case if you have not injected the store where you are creating your model. Commented Jun 24 at 16:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.