#community-help

Solving Instant Search Reinstantiation Issues

TLDR Digamber inquired about destroying a instant search instance. Jason suggested several methods. Eventually, Digamber resolved it by using the dispose method.

Powered by Struct AI
+11
12
13mo
Solved
Join the chat
Aug 02, 2022 (13 months ago)
Digamber
Photo of md5-a0246423746b3b51425d05cfd9c494ae
Digamber
01:30 PM
Hey Guys,
I have instant search question i’ve been googling but didn’t get any results - is it possible to destroy an instant search instance ?
Use case is i have a menu of collections and I want to destroy and re-init the instant search instance
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:35 PM
Could you try the standard JS delete keyword?
Digamber
Photo of md5-a0246423746b3b51425d05cfd9c494ae
Digamber
01:37 PM
Do you mean to delete the widgets and hits manually ?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:38 PM
Yeah, but I'm wondering if just deleting the main instantsearch object would suffice
Digamber
Photo of md5-a0246423746b3b51425d05cfd9c494ae
Digamber
01:41 PM
Tried deleting main instantSeach object - that hasnt worked, and i am a bit wary of deleting manually as something might be skipped or overlooked
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:42 PM
What if you just assign a new instantsearch instance to the existing variable? May be the automated GC will take care of deleting the necessary stuff then
Digamber
Photo of md5-a0246423746b3b51425d05cfd9c494ae
Digamber
01:43 PM
Tried doing that - hasnt worked, the widgets from previous instance still remain
Digamber
Photo of md5-a0246423746b3b51425d05cfd9c494ae
Digamber
01:56 PM
Thanks will check it out and will update here if i find a better solution too
01:56
Digamber
01:56 PM
Cheers
+11
Aug 03, 2022 (13 months ago)
Digamber
Photo of md5-a0246423746b3b51425d05cfd9c494ae
Digamber
05:52 AM
Hi, again so if anyone comes across this thread,
using the dispose method will work to remove all widgets from the search instance https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/#widget-param-dispose
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:06 PM
Good to know! Thanks Digamber!