question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Second `source.populate` library call in taxonomy handler overrides previous content

See original GitHub issue

Bug report

Describe the expected behavior

The second call to source.populate should add the new data without removing the previous one.

Describe the observed behavior

When the taxonomy handler is used, two calls are made. The first one tries to get the category id from the slug: https://github.com/frontity/frontity/blob/514b9fa393154c797dd70c7db1a373b61b06ba88/packages/wp-source/src/libraries/handlers/taxonomy.ts#L23-L24 Here is how it looks state.source.category[8] after those lines:

{
  id: 8,
  count: 10791,
  description: 'Category description',
  link: '/category-link/',
  name: 'Category name',
  slug: 'category-slug',
  taxonomy: 'category',
  parent: 0,
  meta: [],
  _links: {
    self: [ [Object] ],
    collection: [ [Object] ],
    about: [ [Object] ],
    'wp:post_type': [ [Object] ],
    curies: [ [Object] ]
  }
}

Later another call is made to request the posts of that category: https://github.com/frontity/frontity/blob/514b9fa393154c797dd70c7db1a373b61b06ba88/packages/wp-source/src/libraries/handlers/taxonomy.ts#L33-L46

After those lines state.source.category[8] looks like this:

{
  id: 8,
  link: '/noticias-motor/',
  name: 'Noticias motor',
  slug: 'noticias-motor',
  taxonomy: 'category',
  _links: {
    self: [ [Object] ],
    collection: [ [Object] ],
    about: [ [Object] ],
    'wp:post_type': [ [Object] ],
    curies: [ [Object] ]
  }
}

As you can see some fields have been removed, like description or parent. Therefore I’m forced to call categories/?include=8 again in order to access the description property.

Describe the steps involved to reproduce the problem

  1. Insert console logs after each source.populate call in the taxonomy handler to see the output difference.
  2. Visit an archive url for the taxonomy handler to be used.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
luisherranzcommented, Feb 14, 2020

Maybe we can use the blocked label here:

  • If you move an issue to the blocked column, you also add the blocked label.
  • Once someone has “fixed” the block, he/she can remove the blocked label.
  • The assignee can move back the issue to in progress once he/she is ready to continue the work.

That way we can look at the blocked column and see the issues that still need something.

1reaction
luisherranzcommented, Jan 8, 2020

If we want to avoid re-renders it cannot be a simple merge, it has to be a deep-merge. That means we would need to traverse the object and it will have a performance hit. For that reason, I prefer to do it on-demand with the force: true option.

In terms of UX, users don’t usually want to refresh the content when they navigate to other parts of the site. When users want to see new content, they do so by clicking on a refresh button or swiping down. Those actions are the ones that can have the force: true and the overwrite.

To avoid bugs in the future, I wouldn’t do a deep-merge, I would just overwrite the whole object. We don’t know how people are going to structure their REST API responses. Maybe someone adds or removes fields when certain things happen on their site. If we merge the content, the entity data won’t have the guarantee of being a faithful representation of the latest REST API response.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Context | Android Developers
New tests should be written using the Android Testing Support Library. ... Move an existing database file from the given source storage context...
Read more >
aws-cdk/aws-s3-deployment module - AWS Documentation
This library allows populating an S3 bucket with the contents of .zip files from ... Source.asset('/path/to/local/directory'); Another bucket: s3deploy.
Read more >
Gravity Forms Populate Anything - Enable Dynamic Population
Dynamically filter and populate field choices and values with posts, users, taxonomies, terms, Gravity Forms entries, and databases.
Read more >
do_action() | Function - WordPress Developer Resources
Contents. Description; Parameters; Source; Related. Uses; Used By ... It is possible to create new action hooks by simply calling this function, ...
Read more >
Event Management configuration preferences
Skip to Content. Docs. Product documentation. English. EnglishDeutsch日本語한국어FrançaisPortuguês (BR). More Sites.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found