Skip to content
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

Dropdown not working after SSR navigation #589

Open
Denny09310 opened this issue Mar 7, 2025 · 0 comments
Open

Dropdown not working after SSR navigation #589

Denny09310 opened this issue Mar 7, 2025 · 0 comments

Comments

@Denny09310
Copy link

Denny09310 commented Mar 7, 2025

Description

While experimenting with the Preline UI library using Blazor, I noticed that dropdowns stop working after navigation when using SSR mode.

To ensure reinitialization of Preline UI components after an enhanced navigation event, I used the following script as recommended in the Blazor documentation:

<script>Blazor.addEventListener('enhancedload', () => HSStaticMethods.autoInit())</script>

However, in some cases, dropdowns still do not work.

Debugging Findings

After investigating the issue, I found that inside the open function in Preline UI, the dropdown fails to open due to the animationInProcess variable remaining true.

Code Snippet (Preline UI open function)

open(e) {
	if (this.el.classList.contains("open") || this.animationInProcess)
		return !1;
	this.animationInProcess = !0;
	const t = e || this.el
	  , i = window.getComputedStyle(this.el)
	  , n = (i.getPropertyValue("--scope") || "").trim()
	  , o = (i.getPropertyValue("--strategy") || "fixed").trim();
	"window" === n && document.body.appendChild(this.menu),
	"static" !== o && (this.el._floatingUI = this.setupFloatingUI(t)),
	this.menu.style.margin = null,
	this.menu.classList.remove("hidden"),
	this.menu.classList.add("block"),
	setTimeout(( () => {
		var e;
		(null === (e = null == this ? void 0 : this.toggle) || void 0 === e ? void 0 : e.ariaExpanded) && (this.toggle.ariaExpanded = "true"),
		this.el.classList.add("open"),
		"window" === n && this.menu.classList.add("open"),
		this.animationInProcess = !1,
		this.hasAutofocus && this.focusElement(),
		this.fireEvent("open", this.el),
		(0,
		s.dispatch)("open.hs.dropdown", this.el, this.el)
	}
	))
}

The issue arises because animationInProcess is true, causing the function to exit before opening the dropdown.


🔍 Steps to Reproduce

  1. Enable SSR mode in Blazor.
  2. Add a Preline UI dropdown component.
  3. Trigger the dropdown to open.
  4. Without explicitly closing the dropdown, navigate to a different page.
  5. Attempt to open the dropdown after the navigation.

✅ Expected Behavior

The dropdown should work normally after navigation, as the autoInit function is called correctly.

❌ Actual Behavior

The dropdown does not open after navigation.


🛠 Environment

  • OS: Windows 11 (23H2 build SO 22631.4890)
  • Browser: Microsoft Edge 133.0.3065.92 (64 bit)
  • Blazor Version: 9.0.2
  • .NET Version: 9.0
  • Preline UI Version: 3.0.0

📄 Additional Context

If a minimal repro is needed I can share the project I've used to debug the issue. I don't know if this issue is caused on other frameworks as well. I'll try other components as well to check if this is an isolated issue or is this present on the other components as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant