question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug with initialUiState.

See original GitHub issue

Bug 🐞

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:closed
  • Created 2 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Haroenvcommented, Sep 28, 2021
1reaction
Haroenvcommented, Sep 28, 2021

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:

  1. add a new property “initial state” or something to the router you created
  2. pass the cms state to the router
  3. merge with the router from the url

Hope that makes sense!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found