Skip to content

fix: Resolve Algolia DocSearch duplicate results and search bar layout - #22789

Merged
Jen-Uno merged 24 commits into
masterfrom
fix/algolia-docsearch-duplicates-and-layout
Aug 6, 2026
Merged

Jen-Uno merged 24 commits into
masterfrom
fix/algolia-docsearch-duplicates-and-layout

Conversation

@Jen-Uno

@Jen-Uno Jen-Uno commented Mar 6, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

Fixes the Algolia DocSearch problems reported in #22788 — duplicate / low-quality results, a search bar that spans the full viewport width, and search not showing up in local builds — and re-scopes the fixes to the correct layer per the analysis in unoplatform/uno-private#2038.

Approach (layered)

DocSearch renders whatever records live in the hosted Algolia index, so duplicates, navigation noise and ranking are fundamentally an index/crawler-side concern — not something client JS can fully fix. This PR splits the work accordingly:

  • Index / crawler side (the real fix): exclusion, per-page dedup, URL canonicalization and ranking, expressed as a crawler configuration to apply to the hosted platform index.
  • Display side (interim polish + UX): a small, unit-tested transformItems module, the search-bar layout fix, and a "See all results" entry point to a full results page.

Note: data-docsearch-exclude HTML attributes are not honored by the DocSearch crawler (verified against Algolia's docs) — exclusion must be server-side. The template markers remain as intent documentation, but the authoritative exclusion is the crawler config below.

Changes

Index/crawler configuration — the authoritative fix (new)

  • doc/algolia/docsearch-crawler-config.js — recordExtractor with .remove() for navbar/footer/sidebar/breadcrumb, attributeForDistinct: 'url_without_anchor' + distinct for one-record-per-page, URL canonicalization (/index.html, trailing slash), a section facet for same-title disambiguation, and customRanking.
  • doc/algolia/README.md — how to apply it to the hosted index, staging-index validation, and acceptance checks. (The crawler write key is a placeholder — never committed.)

Client-side result transforms — refactored & unit-tested

  • doc/templates/uno/service/docsearch-transform.js — extracts the former inline transformItems logic (breadcrumb filtering, page-level dedup, same-title disambiguation) into a pure, testable module. Fixes a prototype-pollution crash (a page titled constructor/__proto__ previously threw and killed transformItems) and the short-first-URL disambiguation edge case.
  • doc/templates/uno/service/docsearch-transform.test.js — node --test coverage (13 tests) incl. the prototype-key and short-URL cases.
  • scripts.tmpl.partial delegates to the module with an identity fallback so search never hard-breaks.

"See all results" + full results page

  • Replaced the previous custom ~250-line MutationObserver overlay (and its algoliasearch-lite dependency) with DocSearch's built-in resultsFooterComponent.
  • doc/search.html — a self-contained InstantSearch.js results page (query in URL, pagination, highlighting) the footer links to. Uses only the public search-only key. Wired into docfx.json resources.

Search-bar layout fix (kept)

  • service/search.scss — override for docfx's global header { position: fixed } leaking onto .DocSearch-SearchBar, keeping it inside the modal (+ small footer-link styling).

Build / local compatibility

  • gulpfile.js — exclude *.test.js from the JS bundle (test files are Node-only and would otherwise break docfx.js).
  • import_external_docs_test.ps1 — pin docfx 2.73.2 to match CI; sidebar.js/docfx.js keep the toc.json → toc.html compatibility guard.

Testing

  • cd doc/templates/uno/service && node --test → 13/13 passing.
  • The changed files were adversarially reviewed (crawler API, resultsFooterComponent v3 signature, InstantSearch usage, docfx/gulp wiring); findings fixed.

Smoke-test before merge (needs the live widget)

  • The v3 resultsFooterComponent returns a Preact vnode from a separately-loaded Preact; it fails safe (no footer) if the runtime rejects it — confirm it renders on the real modal.
  • The footer count depends on state.context.nbHits; the label falls back to "See all results" if absent.
  • The crawler config must be applied to the hosted index (on a staging index first) — that's where the duplicate/ranking fixes actually take effect.

Not in this PR

Fixes #22788 · Refs unoplatform/uno-private#2038

Copilot AI lite review requested due to automatic review settings March 6, 2026 01:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes two issues in the Uno Platform documentation site: (1) duplicate search results in the Algolia DocSearch integration by adding a transformItems callback that filters and deduplicates per-page results, and (2) a misaligned search bar layout by adding a CSS fix for .DocSearch-SearchBar. It also adds data-docsearch-exclude attributes to several layout partials (navbar, breadcrumb, footer, affix) to prevent those sections from being indexed as searchable content, and pins the docfx version used in the local test script.

Changes:

  • Added transformItems callback to the DocSearch initialization that removes breadcrumb-anchored entries, deduplicates results per base page URL, and disambiguates same-titled pages with path-derived suffixes.
  • Added data-docsearch-exclude to navbar, breadcrumb, footer, and affix template partials to prevent indexing of chrome elements.
  • Pinned docfx to version 2.73.2 in the local documentation test script.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
doc/templates/uno/partials/scripts.tmpl.partial Adds transformItems function to filter/deduplicate DocSearch results
doc/templates/uno/styles/main.css Adds .DocSearch-SearchBar positional fix for search bar layout
doc/templates/uno/toc.html.primary.tmpl New file; places #docsearch container in the sidebar
doc/templates/uno/partials/footer.tmpl.partial New file; adds footer partial with data-docsearch-exclude
doc/templates/uno/partials/breadcrumb.tmpl.partial New file; adds breadcrumb partial with data-docsearch-exclude
doc/templates/uno/partials/affix.tmpl.partial New file; adds right-sidebar partial with data-docsearch-exclude
doc/templates/uno/partials/_navbar.tmpl.partial Adds data-docsearch-exclude to the nav element
doc/import_external_docs_test.ps1 Pins docfx tool to version 2.73.2

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread doc/import_external_docs_test.ps1 Resolved
This was referenced Mar 6, 2026
Jen-Uno and others added 10 commits August 6, 2026 16:17
Replace the idealized template with the actual deployed crawler config plus
the two uno-private#2038 fixes (chrome exclusion via $(...).remove() and
attributeForDistinct url -> url_without_anchor). Document the operational
gotchas (initialIndexSettings only apply to a new index; safetyChecks
maxLostRecordsPercentage). API key is a placeholder, never committed.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…arams)

ignoreQueryParams:[tabs] infinite-loops against docfx tabbed pages'
client-side ?tabs redirect and drops them. Strip the query at the record
level instead so tabbed pages index under one clean URL.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Regenerates the gulp bundle so styles/docfx.js reflects the highlight-
preservation change in service/docsearch-transform.js. Test file remains
excluded from the bundle.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Pre-uno-private#2038 baseline (attributeForDistinct: url, no chrome
removal / query strip / ignoreQueryParams). API key placeholdered.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…guation

Breadcrumb filtering and page-level dedup are now handled server-side
(crawler .remove() + attributeForDistinct), so drop them from
docsearch-transform.js; only same-title disambiguation remains. Update
tests (10 passing), add a gulp `scripts` task export, and rebuild the
docfx.js bundle.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…alization snippets

Document the two optional (not-deployed) crawler enhancements in the
README with paste-ready code, and add pointers from the config file. The
deployed config stays the active source of truth.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Decision (uno-private#2038): same-title disambiguation cannot move to the
index layer for uno — recordExtractor is per-page and can't compare
same-titled pages to find their distinguishing segment (which sits at a
variable path depth, e.g. workshop MVUX-XAML vs MVVM-XAML). Documents this
in the README, reclassifies the item as applied/client-side, and reframes
the section-facet snippet as future contextual-filtering only.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sourcemap remaps because the docsearch-transform.js comment shifted source
line positions; the minified docfx.js is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…HANGE 4)

Make the recordExtractor collapse /index.html and trailing-slash URL
variants (regular .html pages and #anchors untouched). Moves this out of
'optional snippet' into the active config; low impact (~3 index.html pages
in the docs sitemap) but closes the #2038 canonical-URL item.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address PR #22789 review: hitTitle()/hitSnippet() fall back to raw
hit.hierarchy/hit.content when no highlight/snippet result exists; those
raw values were concatenated into innerHTML unescaped. Escape the raw
fallbacks (the connector-escaped highlight/snippet values, which carry
<mark>, are left as-is).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Jen-Uno
Jen-Uno force-pushed the fix/algolia-docsearch-duplicates-and-layout branch from 5aa7be9 to a6e65a0 Compare August 6, 2026 20:18
@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 226240 has failed on Uno.UI - docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 21 changed files in this pull request and generated 1 comment.

Files not reviewed (2)
  • doc/templates/uno/styles/docfx.js: Generated file
  • doc/templates/uno/styles/main.css: Generated file
Suppressed comments (4)

doc/templates/uno/partials/scripts.tmpl.partial:27

  • These CDN dependencies are not pinned to an exact version and do not use Subresource Integrity (SRI). For supply-chain hardening and build reproducibility, pin to exact versions (e.g., @docsearch/[email protected], [email protected]) and add integrity + crossorigin attributes (or vendor/host them under your control if possible).
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@docsearch/css@3" />
<script src="https://cdn.jsdelivr.net/npm/@docsearch/js@3"></script>
<!-- Preact, used to build the DocSearch v3 resultsFooterComponent vnode
     (v3 renders the footer as a Preact component; it has no v4 `html` helper). -->
<script src="https://cdn.jsdelivr.net/npm/preact@10/dist/preact.umd.js"></script>

doc/search.html:19

  • Similar to the DocSearch includes, these assets are pulled from CDN without exact version pinning or SRI. Consider pinning exact versions and adding integrity/crossorigin to reduce the risk of unexpected upstream changes or compromised CDN content.
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.css@8/themes/satellite-min.css" />

doc/search.html:53

  • Similar to the DocSearch includes, these assets are pulled from CDN without exact version pinning or SRI. Consider pinning exact versions and adding integrity/crossorigin to reduce the risk of unexpected upstream changes or compromised CDN content.
  <script src="https://cdn.jsdelivr.net/npm/algoliasearch@4/dist/algoliasearch-lite.umd.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4"></script>

doc/templates/uno/service/docsearch-transform.js:54

  • decodeURIComponent() throws on malformed percent-encoding (e.g. a raw % in the segment). Since this code runs during search rendering, a single bad URL segment could break the whole transform. Wrap decoding in a try/catch (fall back to the original string when decoding fails) to keep the transform fail-safe.
    function humanizeSegment(segment) {
        return decodeURIComponent(String(segment))
            .replace(/\.html?$/i, '')
            .replace(/[-_]/g, ' ')
            .replace(/\b\w/g, function (c) { return c.toUpperCase(); })
            .trim();
    }

Comment thread doc/search.html Resolved
Copilot AI review requested due to automatic review settings August 6, 2026 20:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@unodevops

Copy link
Copy Markdown
Contributor

Address PR #22789 review: esc() guards HTML injection but not unsafe href
schemes. Add safeUrl() allowlisting http(s)/relative/anchor URLs (control
chars stripped, javascript:/data:/etc. -> '#') and route hit.url through it.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings August 6, 2026 20:52
…p link

The floating 'Edit this page / Send feedback' box (.feedback-box, fixed at
bottom-right) covered the footer's 'back to top' link when scrolled to the
bottom. checkFeedbackBoxOverlap() hid the box against the affix and article
but not the footer; add the <footer> to that check. Bundle regenerated.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@unodevops

Copy link
Copy Markdown
Contributor

@Jen-Uno
Jen-Uno merged commit d7a1c6f into master Aug 6, 2026
12 checks passed
@Jen-Uno
Jen-Uno deleted the fix/algolia-docsearch-duplicates-and-layout branch August 6, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

♥️ Algolia DocSearch results are duplicated and search bar spans full viewport width

5 participants