adopted-ember-addons / ember-data-model-fragments

Ember Data addon to support nested JSON documents
MIT License
370 stars 114 forks source link

Fragments with a function-style defaultValue error in v6 #470

Closed grayt0r closed 1 year ago

grayt0r commented 1 year ago

Versions:

When pushing a payload to the store for a model that contains a fragment with a function-style defaultValue I receive the following error:

Uncaught TypeError: Cannot read properties of undefined (reading 'length')
    at -private.js:2170:1
    at changeProperties (index.js:589:1)
    at ExampleModel._notifyProperties (-private.js:2168:1)
    at InternalModel.setupData (-private.js:5991:1)
    at Store._load (-private.js:9153:1)
    at Store._pushInternalModel (-private.js:9380:1)
    at -private.js:9331:1
    at Backburner._run (backburner.js:843:1)
    at Backburner._join (backburner.js:822:1)
    at Backburner.join (backburner.js:632:1)

The model is defined like this:

export default class ExampleModel extends Model {
  @attr name;

  @fragment('example-fragment', { defaultValue: () => ({}) }) exampleFragment;
}

The error goes away and everything works when I downgrade to ember-data-model-fragments v5.0.0 and ember-data v3.27.1.

I can also fix the error by swapping to a non-function defaultValue, i.e.:

export default class ExampleModel extends Model {
  @attr name;

  @fragment('example-fragment', { defaultValue: {} }) exampleFragment;
}

Is this a known limitation of v6? Or a bug?

A minimal reproduction can be found here: https://github.com/grayt0r/ember-data-model-fragments-bug (relevant commit).

Thanks!

VincentMolinie commented 1 year ago

Oh I actually got the exact same issue ! This PR might fix your issue (https://github.com/adopted-ember-addons/ember-data-model-fragments/pull/474)

grayt0r commented 1 year ago

@VincentMolinie looks like it does... thank you 🙌

knownasilya commented 1 year ago

Released as v6.0.2