Skip to content
This repository has been archived by the owner on Nov 17, 2017. It is now read-only.

Related entities not correctly populated in latest version #38

Closed
larsbs opened this issue Feb 11, 2017 · 5 comments
Closed

Related entities not correctly populated in latest version #38

larsbs opened this issue Feb 11, 2017 · 5 comments
Labels

Comments

@larsbs
Copy link

larsbs commented Feb 11, 2017

The newest update (v0.5.1) has introduced a bug which causes related entities not being populated at all. For instance, if we have [Group] 1 --> * [User], the users property is not populated in the final group object.

Seems to be related to the new browsers property added to package.json since removing this line restores the correct behaviour.

@gpbl
Copy link
Owner

gpbl commented Feb 11, 2017

🤔 I don't see how the package.json could affect the behavior of the library . How are you importing it?

@larsbs
Copy link
Author

larsbs commented Feb 11, 2017

It's not very difficult to reproduce. The following sample code shows what's happening:

import { schema } from 'normalizr';
import { denormalize } from 'denormalizr';

const user = new schema.Entity('user', {
  group: group
});
const group = new schema.Entity('group', {
  users: [user],
});

const entity = { id: 1, name: 'Lars', group: 1 };
const entities = { 
  user: { 
    1: { id: 1, name: 'Lars', group: 1 },
  },
  group: {
    1: { id: 1, name: 'Test', users: [1] },
  },
};

const result = denormalize(entity, entities, group);

// If we use denormalizr@0.5.0 (no browser field in package.json)
console.log(result)  // { id: 1, name: 'Test', users: [{ id: 1, name: 'Lars', group: [circular]}] };

// if we use denormalizr@0.5.1 (browser field in package.json)
console.log(result)  // { id: 1, name: 'Test', users: [{}] };

// If we manually remove browser field from denormalizr@0.5.1 package.json
 console.log(result)  // { id: 1, name: 'Test', users: [{ id: 1, name: 'Lars', group: [circular]}] };

I'm using webpack to bundle the library, so probably it's related to webpack using the browser field instead of the main field.

@gpbl
Copy link
Owner

gpbl commented Feb 11, 2017

I'm using webpack to bundle the library, so probably it's related to webpack using the browser field instead of the main field.

Interesting, thanks, this should be the reason. Are you using webpack 1?

@larsbs
Copy link
Author

larsbs commented Feb 11, 2017

Yes, webpack@1.13.1 to be more precise.

@gpbl gpbl added the bug label Feb 12, 2017
@gpbl
Copy link
Owner

gpbl commented Feb 12, 2017

@larsbs this should be fixed in v0.5.2! Thanks for the report, really appreciated 👍
Please reopen if not working as expected.

@gpbl gpbl closed this as completed Feb 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants