ember-inspector icon indicating copy to clipboard operation
ember-inspector copied to clipboard

The inspector seems to influence Ember Data record creation

Open Windvis opened this issue 3 years ago • 1 comments

Describe the bug We have a route that creates certain records when they don't exist yet. We assign them default values on creation by passing data into the createRecord method. For example;

store.createRecord('model-name', {
    someAttribute: 'Hello',
});

I noticed that sometimes the initial values aren't set correctly and I couldn't figure out why. Eventually I realized it's caused by having the inspector open when the page loads. If I close the dev tools, reload, open the data tab and look at the values, everything works. If I do the same without first closing the dev tools, the values aren't set. What's even more strange is that it only seems to happen for the first record that's created this way. The second one does have the values we pass into it.

It's also not just a visual bug, the value hasn't actually been stored in the record so record.someAttribute will return undefined.

Another thing I noticed is that first creating the record before setting the value doesn't have the same issue:

let record = store.createRecord('model-name');
record.someAttribute = 'hello';

That will always work, no matter if the dev tools are open when reloading. If you then create a second record with the initial value object, that still works as expected which makes me think it might be a timing issue?

I'll try to create a reproduction to see if it's related to our setup or not.

To Reproduce Steps to reproduce the behavior:

  1. Create new records with initial values
  2. Reload the page with the dev tools activated
  3. Go to the data tab and verify that not all default values have been set.

Expected behavior The dev tools do not affect application code.

Screenshots Reloading the page with the dev tools closed: image

Reloading the page with the dev tools open ("Primary" is missing) image

Environment Ember version, browser, etc. Ember 3.26, Firefox 96

Additional context Add any other context about the problem here.

Windvis avatar Feb 01 '22 13:02 Windvis

May be related to: https://github.com/emberjs/ember-inspector/issues/1875

lifeart avatar Mar 09 '22 06:03 lifeart

the fixes for #1875 should also fix this

patricklx avatar Oct 02 '22 08:10 patricklx

Just had the issue with:

  • Ember Inspector 4.9.1
  • "ember-data": "~3.27.1"

This bug should be re-opened 🤷‍♂️

schorke avatar Sep 25 '23 11:09 schorke

I think you need at least ember data 3.28, which includes the fix

patricklx avatar Sep 25 '23 12:09 patricklx