Related entities not correctly populated in latest version
larsbs opened this issue · 5 comments
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.
🤔 I don't see how the package.json could affect the behavior of the library . How are you importing it?
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.
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?
Yes, webpack@1.13.1
to be more precise.