Skip to main content
AndrewK
Helper ⭐️
August 31, 2026
Solved

How does the sdk observeElement work

  • August 31, 2026
  • 4 replies
  • 64 views

In the docs it says it uses a mutation observer under the hood and disconnects when the element loads. API Reference | CC Developer Portal 

I notice some elements re-render repeatedly shaking loose event handlers and updates previously made. Does observeElement take this into account? Also is there any way to do this for multiple elements like a querySelectorAll version of this?

 

Thanks!

Best answer by revathimenon

Hello ​@AndrewK 

Thanks for raising this! I took it to our devs, here's what came back. 

observeElement is one-shot. It disconnects the moment the element first shows up, so it won't fire again when that element re-renders. onEvent behaves the same way since it's built on observeElement. And there's no querySelectorAll version today, so it's one selector per call.
On the re-rendering itself, the honest answer from our devs is that it depends on the element. Some of our markup is static and stays put, other parts are rendered and managed by our JS framework, and there you're working against its render cycle, so handlers and changes can get dropped on the next tick. Internal class names can shift between releases too.


Which elements are you seeing this on, and are you working from a custom widget or from third-party scripts / header-footer?

4 replies

revathimenon
Gainsight Community Lead
September 2, 2026

Hi ​@AndrewK 

I’m checking on this internally and will loop back to you with an answer soon!

Where focus goes, energy flows.
revathimenon
Gainsight Community Lead
September 2, 2026

Hello ​@AndrewK 

Thanks for raising this! I took it to our devs, here's what came back. 

observeElement is one-shot. It disconnects the moment the element first shows up, so it won't fire again when that element re-renders. onEvent behaves the same way since it's built on observeElement. And there's no querySelectorAll version today, so it's one selector per call.
On the re-rendering itself, the honest answer from our devs is that it depends on the element. Some of our markup is static and stays put, other parts are rendered and managed by our JS framework, and there you're working against its render cycle, so handlers and changes can get dropped on the next tick. Internal class names can shift between releases too.


Which elements are you seeing this on, and are you working from a custom widget or from third-party scripts / header-footer?

Where focus goes, energy flows.
AndrewK
AndrewKAuthor
Helper ⭐️
September 4, 2026

Thanks ​@revathimenon for checking on this!

 

Most recently I was seeing this while working on changing the way the date is displayed on posts as suggested in this thread. Is it possible to display the actual date a post was created vs. "xx days ago" | Gainsight Community

 

I’m doing this with a third-party script. You can see in their example, ​@akhilv uses setInterval to deal with this re-rendering.

 

I have gotten quite familiar with MutationObserver - Web APIs | MDN since moving to Gainsight but was hoping there might be a simpler way to deal with this. Maybe worth posting an idea.

 

Thanks

Andrew
samanthahamlet
Gainsight Community Manager
September 8, 2026

Hey ​@AndrewK 

Just following up on this, I’d definitely suggest submitting an Idea for this for the team to review! 😊