-
Notifications
You must be signed in to change notification settings - Fork 39
Add standalone engine definition to SSR-Next search #6613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Created standalone-static-state-factory.ts that skips search execution - Added comprehensive tests for standalone factory - Updated search-engine.ssr.ts to return both searchEngineDefinition and standaloneEngineDefinition - Updated hydrated-state-factory.ts to conditionally wait for search completion - Updated search-engine.ssr.test.ts with tests for both definitions and backward compatibility Co-authored-by: y-lakhdar <[email protected]>
packages/headless/src/ssr-next/search/factories/standalone-static-state-factory.ts
Outdated
Show resolved
Hide resolved
packages/headless/src/ssr-next/search/factories/hydrated-state-factory.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: y-lakhdar <[email protected]>
There was a problem hiding this comment.
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 successfully adds standalone engine definition support to SSR-Next search, enabling standalone search boxes and other components without server-side search execution. The implementation closely follows the established pattern from commerce SSR-Next, maintaining consistency across the codebase.
Key accomplishments:
- Introduces
standaloneEngineDefinitionalongsidesearchEngineDefinitionfor different use cases - Implements performance optimization by skipping unnecessary API calls on non-search pages
- Maintains full backward compatibility through object destructuring
- Comprehensive test coverage with 181 passing tests
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
packages/headless/src/ssr-next/search/factories/standalone-static-state-factory.ts |
New factory that skips server-side search execution and returns empty searchActions array for standalone components |
packages/headless/src/ssr-next/search/factories/standalone-static-state-factory.test.ts |
Comprehensive test suite (7 tests) verifying standalone factory behavior including no search execution and empty searchActions |
packages/headless/src/ssr-next/search/factories/hydrated-state-factory.ts |
Added conditional check to only wait for search completion when searchActions array is non-empty, preventing infinite wait for standalone |
packages/headless/src/ssr-next/search/engine/search-engine.ssr.ts |
Updated to return both searchEngineDefinition and standaloneEngineDefinition, with improved documentation and usage examples |
packages/headless/src/ssr-next/search/engine/search-engine.ssr.test.ts |
Expanded test coverage (16 tests) with dedicated test suites for both definitions and backward compatibility verification |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
SSR Standalone Search Engine Support - Complete ✅
This PR adds standalone engine definition support to
ssr-next/search, following the exact pattern used in commerce SSR-Next. This enables standalone search boxes and other components that don't require server-side search execution.✅ Implementation Complete
standalone-static-state-factory.tsthat skips search executionstandalone-static-state-factory.test.ts(7 tests)search-engine.ssr.tsto return bothsearchEngineDefinitionandstandaloneEngineDefinitionsearch-engine.ssr.test.tsto test standalone behavior (16 tests)hydrated-state-factory.tsto handle empty searchActions arraysrc/ssr-nextdirectory📊 Test Results
🎯 Key Changes
1. New Standalone Static State Factory
File:
packages/headless/src/ssr-next/search/factories/standalone-static-state-factory.tssearchActionsarray2. Updated Search Engine Definition
File:
packages/headless/src/ssr-next/search/engine/search-engine.ssr.tsBefore (breaking for new feature):
After:
3. Fixed Hydration Logic
File:
packages/headless/src/ssr-next/search/factories/hydrated-state-factory.tssearchActions.length > 0📝 Usage Example
🔄 Backward Compatibility
The implementation maintains full backward compatibility through destructuring:
🏗️ Architecture
Follows commerce SSR-Next pattern exactly:
packages/headless/src/ssr-next/commerce/engine/commerce-engine.ssr.ts(reference)packages/headless/src/ssr-next/commerce/factories/static-state-factory.ts(reference)🎯 Benefits
🔍 Type Safety
Type inference works correctly with both definitions:
Original prompt
This section details on the original issue you should resolve
<issue_title>[DXUI Feature]: Support SSR standalone components</issue_title>
<issue_description>### Feature Description
Feature Request
Add standalone search engine definition support to SSR-Next search implementation (
packages/headless/src/ssr-next/search/).Currently,
fetchStaticState()always executes a server-side search, even for standalone search boxes that only need query suggestions and redirection functionality. This creates unnecessary:Note: This is a new feature for
ssr-next/only (not a breaking change). The olderssr/implementation will remain unchanged.Current Behavior
Desired Behavior
Add a new
standaloneEngineDefinitionoption (similar to commerce SSR-Next) that:standaloneEngineDefinitiondefineSearchEngine()usage continues to workReference Implementation
Commerce SSR-Next already implements this pattern in
packages/headless/src/ssr-next/commerce/engine/commerce-engine.ssr.ts:In commerce's
ssr-next/commerce/factories/static-state-factory.ts:Proposed Implementation
1. Update
defineSearchEngineto Return Multiple Engine DefinitionsIMPORTANT: This changes the return type, making it a new feature rather than modifying existing behavior.
2. Create Standalone Static State Factory
Create a new factory that skips search execution:
3. Update Engine Definition to Export Both
Files to Create/Modify
New Files
packages/headless/src/ssr-next/search/factories/standalone-static-state-factory.ts- Factory that skips search executionpackages/headless/src/ssr-next/search/factories/standalone-static-state-factory.test.ts- Tests for standalone factoryModified Files
packages/headless/src/ssr-next/search/engine/search-engine.ssr.ts- Update return type and add standalone definition✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.