Refactor duplicated Typesense search UI rendering logic

Created on 20 August 2025, 22 days ago

Problem/Motivation

Currently, the Typesense search UI rendering logic is duplicated in two different places:

  1. In the search_api_typesense_search_block plugin (TypesenseSearchBlock::build()).
  2. In the controller (TypesenseIndexController::search()).

This duplication increases the maintenance burden, since changes to the UI have to be updated in both places, and it makes the code harder to extend or customize consistently.

Steps to reproduce

  1. Enable the Typesense search block and navigate to a page where it is displayed.
  2. Visit a route handled by TypesenseIndexController::search().
  3. Observe that both render the search UI using separate but nearly identical implementations.

Proposed resolution

  • Refactor the search UI rendering logic into a shared reusable service, trait, or dedicated rendering class.
  • Both TypesenseSearchBlock::build() and TypesenseIndexController::search() should call this shared method to generate the search UI.
  • Ensure that the shared code supports contextual differences (e.g., block vs. page rendering) without duplication.

Remaining tasks

  • [ ] Extract common search UI rendering logic into a shared method/service.
  • [ ] Update TypesenseSearchBlock::build() to use the shared method.
  • [ ] Update TypesenseIndexController::search() to use the shared method.
  • [ ] Add/adjust tests to confirm both block and controller render consistently.
  • [ ] Document the new approach for future maintainers.

User interface changes

No changes are expected in the rendered search UI. The change is internal and focused on reducing duplicated code.

API changes

No API changes expected. Internal refactoring only.

Data model changes

No data model changes expected.

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇮🇹Italy robertoperuzzo 🇮🇹 Tezze sul Brenta, VI

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024