Bug with initialUiState.
See original GitHub issueBug 🐞
What is the current behavior?
<ais-instant-search-ssr
:initial-ui-state="initialUiState"
>
ais-instant-search-ssr does not support :initial-ui-state feature. I need this on server side since I want to preconfigure my search based on something from my headless cms. And I can’t do this in my setup.
I’m using Nuxt Algolia implemented like in your docs:
data() {
const mixin = createServerRootMixin({
searchClient: getSearchClient(this.$config ?? process.env),
indexName: this.$config?.ALGOLIA_INDEX_NAME ?? process.env.ALGOLIA_INDEX_NAME!,
routing: {
router: nuxtRouter(this.$router),
},
initialUiState: {
[this.$config?.ALGOLIA_INDEX_NAME]: {
refinementList: {
business: ["koed"] <--- THIS IS HERE I WANT TO USE MY CMS DATA PROPERTY
}
},
}
});
return {
...mixin.data(),
};
},
provide() {
return {
// Provide the InstantSearch instance for SSR
$_ais_ssrInstantSearchInstance: this.instantsearch,
};
},
serverPrefetch() {
return this.instantsearch?.findResultsState(this).then((algoliaState: any) => {
this.$ssrContext.nuxt.algoliaState = algoliaState;
});
},
beforeMount() {
const results =
(this.$nuxt.context && this.$nuxt.context.nuxtState.algoliaState) ||
(window as unknown as IAlgoliaWindow).__NUXT__.algoliaState;
(this as any).instantsearch.hydrate(results);
// Remove the SSR state so it can't be applied again by mistake
delete this.$nuxt.context.nuxtState.algoliaState;
delete (window as unknown as IAlgoliaWindow).__NUXT__.algoliaState;
},
I can’t use my properties in data() from headless cms so I need some way to set this initialUiState when my cms data is available-
What is the expected behavior?
The expected behavior is I can set my initialUiState programatically. something like this:
data() {
const cmsProp = this.data.property;
const mixin = createServerRootMixin({
searchClient: getSearchClient(this.$config ?? process.env),
indexName: this.$config?.ALGOLIA_INDEX_NAME ?? process.env.ALGOLIA_INDEX_NAME!,
routing: {
router: nuxtRouter(this.$router),
},
initialUiState: {
[this.$config?.ALGOLIA_INDEX_NAME]: {
refinementList: {
business: [cmsProp ] <--- USED HERE.
}
},
}
});
return {
...mixin.data(),
};
},
What is the version you are using?
“algoliasearch”: “^4.9.3”, “vue-instantsearch”: “^3.7.0”,
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
Can I set defaultRefinement on hierarchicalMenu in the .js ...
With Instantsearch.js you can define an initialUiState when initializing the search client.
Read more >Developers - Nuxt initialUiState is not working - - Bountysource
Bug . What is the current behavior? The initialUIState is not rendered when i set the page attribute with: const indexName...
Read more >Change Log - kepler.gl
47a184c6 [Bug] Fix Range brush maximum update exceeds crashes (#1955). f9485018 [Enhancement] improve tooltip ... [Feat] pass initialUiState to prop (#1187).
Read more >instantsearch.js - UNPKG
46, ### Bug Fixes. 47. 48, * **getUiState:** support `initialUiState` ([#4948](https://github.com/algolia/instantsearch.js/issues/4948)) ...
Read more >Unable to print custom text twice from my UI - Google Groups
initialUiState () def initialUiState(self): self.pushBtn_makeRobot.toggle() self.pushBtn_makeStairs.toggle() self.pushBtn_randomlyDistribute.toggle()
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
something approximately like this: https://codesandbox.io/s/awesome-architecture-shex2?file=/src/App.vue
If you use routing, you can’t also use initial UI state, they both act on the same information and routing takes precedence. What you should do is:
Hope that makes sense!