Repository navigation
fix: Resolve Algolia DocSearch duplicate results and search bar layout - #22789
Conversation
There was a problem hiding this comment.
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
transformItemscallback 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-excludeto navbar, breadcrumb, footer, and affix template partials to prevent indexing of chrome elements. - Pinned
docfxto version2.73.2in 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.
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]>
5aa7be9 to
a6e65a0
Compare
|
|
There was a problem hiding this comment.
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 addintegrity+crossoriginattributes (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/crossoriginto 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/crossoriginto 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();
}
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-22789/docs/index.html |
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]>
…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]>
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-22789/docs/index.html |
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:
platformindex.transformItemsmodule, the search-bar layout fix, and a "See all results" entry point to a full results page.Changes
Index/crawler configuration — the authoritative fix (new)
doc/algolia/docsearch-crawler-config.js—recordExtractorwith.remove()for navbar/footer/sidebar/breadcrumb,attributeForDistinct: 'url_without_anchor'+distinctfor one-record-per-page, URL canonicalization (/index.html, trailing slash), asectionfacet for same-title disambiguation, andcustomRanking.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 inlinetransformItemslogic (breadcrumb filtering, page-level dedup, same-title disambiguation) into a pure, testable module. Fixes a prototype-pollution crash (a page titledconstructor/__proto__previously threw and killedtransformItems) and the short-first-URL disambiguation edge case.doc/templates/uno/service/docsearch-transform.test.js—node --testcoverage (13 tests) incl. the prototype-key and short-URL cases.scripts.tmpl.partialdelegates to the module with an identity fallback so search never hard-breaks."See all results" + full results page
MutationObserveroverlay (and itsalgoliasearch-litedependency) with DocSearch's built-inresultsFooterComponent.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 intodocfx.jsonresources.Search-bar layout fix (kept)
service/search.scss— override for docfx's globalheader { position: fixed }leaking onto.DocSearch-SearchBar, keeping it inside the modal (+ small footer-link styling).Build / local compatibility
gulpfile.js— exclude*.test.jsfrom the JS bundle (test files are Node-only and would otherwise breakdocfx.js).import_external_docs_test.ps1— pin docfx2.73.2to match CI;sidebar.js/docfx.jskeep thetoc.json → toc.htmlcompatibility guard.Testing
cd doc/templates/uno/service && node --test→ 13/13 passing.resultsFooterComponentv3 signature, InstantSearch usage, docfx/gulp wiring); findings fixed.Smoke-test before merge (needs the live widget)
resultsFooterComponentreturns 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.state.context.nbHits; the label falls back to "See all results" if absent.Not in this PR
Fixes #22607), as it's unrelated to search.Fixes #22788 · Refs
unoplatform/uno-private#2038