Skip to content

PLANET-8110: Dynamic rendering in the Search page#2897

Open
mardelnet wants to merge 33 commits intomainfrom
PLANET-8110_investigate-dynamic-rendering-in-search-page
Open

PLANET-8110: Dynamic rendering in the Search page#2897
mardelnet wants to merge 33 commits intomainfrom
PLANET-8110_investigate-dynamic-rendering-in-search-page

Conversation

@mardelnet
Copy link
Contributor

@mardelnet mardelnet commented Feb 17, 2026

Summary

This PR is an investigation into the feasibility of making the front-end responsible for the dynamic rendering in the Search page. The results determine that the implementation, while not simple, is possible with our current infrastructure.

To do so, default JavaScript (mainly the assets/src/js/search.js file) was replaced with React, and PHP/Twig with JSX. The Api/Search.php file was modified to stop returning HTML and only return plain data, and a new API endpoint was added to get a list of filters associated with the user search (categories, post types, etc.). Many elements of the templates/search.twig file and also the complete templates/tease-search.twig file were removed, since now React is in charge of rendering them using specific components. The core of this implementation is the assets/src/js/search_results.js file. This file dynamically renders all the Search page components (the form, the results, the load more button, the filters, etc.) and controls the data in a reactive way.


Ref: https://greenpeace-planet4.atlassian.net/browse/PLANET-8110

Testing

  1. Visit the Search Results page on your local instance or the test instance.
  2. For local testing, remember to activate ElasticPress (npm run elastic:activate), build the theme (npm i --legacy-peer-deps && npm run build && npm start), and clear the Timber cache (npx wp-env run cli wp timber clear_cache)
  3. Have fun!

- Improve the load more button and the search title
- Add the post types filter component
- Add component for the sorting select
- Replace "tease-search" template with component
- Fetch results when filters are applied
- Update the active filters when filters are modified
@mardelnet mardelnet self-assigned this Feb 17, 2026
@mardelnet mardelnet added PoC Pull requests that are defined as a proof of concept DO NOT MERGE labels Feb 17, 2026
@mardelnet mardelnet marked this pull request as ready for review February 17, 2026 13:01
planet-4 added a commit to greenpeace/planet4-test-sinope that referenced this pull request Feb 17, 2026
/unhold bfe1b3c5-8344-4b8b-86ae-0720dba20fa1
@planet-4
Copy link
Contributor

planet-4 commented Feb 17, 2026

Test instance is ready 🚀

🌑 sinope | admin | blocks report | CircleCI | composer-local.json

⌚ 2026.02.24 14:12:22

@mardelnet mardelnet marked this pull request as draft February 17, 2026 14:22
@mardelnet mardelnet marked this pull request as ready for review February 18, 2026 08:57
planet-4 added a commit to greenpeace/planet4-test-sinope that referenced this pull request Feb 18, 2026
/unhold e90675be-266e-442b-a46d-383026233730
planet-4 added a commit to greenpeace/planet4-test-sinope that referenced this pull request Feb 18, 2026
/unhold cc791aca-f289-4481-8af8-c52383744070
planet-4 added a commit to greenpeace/planet4-test-sinope that referenced this pull request Feb 24, 2026
/unhold 83872a6f-c71e-4d10-aba1-7becd5e74edf
planet-4 added a commit to greenpeace/planet4-test-sinope that referenced this pull request Feb 24, 2026
/unhold 31559a3f-ddd9-41ac-9ba4-2ff4c953eaaa
planet-4 added a commit to greenpeace/planet4-test-sinope that referenced this pull request Feb 24, 2026
/unhold e7c9711a-8d5a-4bc6-b786-d28f6fc16bc5
}

// Load More button component:
function LoadMoreButton({foundPosts, currentPage, postsPerLoad, onLoadMore}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer using const for declaring components, over function, i.e.

const LoadMoreButton = ({...}) => {...}```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, in order to reduce this file's size, I would declare all these components in separate files

const valueToShow = remainingPosts < postsPerLoad ? remainingPosts : postsPerLoad;
const showMore = currentPage * postsPerLoad < foundPosts;

if (!showMore) {return null;}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason here to return null instead of nothing like line 168?

if (!showMore) {return null;}

return (
<button
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this button should have more attributes, for GA in particular

return (
<ul className="list-unstyled">
{posts.map(post => {
return (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to remove this return and directly use

posts.map(post => (...))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DO NOT MERGE PoC Pull requests that are defined as a proof of concept [Test Env] sinope

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants