preline icon indicating copy to clipboard operation
preline copied to clipboard

Preline Dropdown only works after hard refresh

Open insivika opened this issue 11 months ago • 1 comments

Just implemented the premium dashboard component in my next.js project and came to find that i have to refresh the page to get the drop down to show up.

Clicking the profile button doesnt do anything: Screenshot 2024-03-11 at 3 41 19 PM

After refreshing the page clicking the button opens the modal: Screenshot 2024-03-11 at 3 42 52 PM

Here's my PrelineScript


'use client';

import { usePathname } from 'next/navigation';
import { useEffect } from 'react';

import { IStaticMethods } from 'preline/preline';
declare global {
  interface Window {
    HSStaticMethods: IStaticMethods;
  }
}

export default function PrelineScript() {
  const path = usePathname();

  useEffect(() => {
    const loadPreline = async () => {
      await import('preline/preline');
      window.HSStaticMethods.autoInit();
    };
    loadPreline();
  }, [path]);

  return null;
}


insivika avatar Mar 11 '24 20:03 insivika

Same issue I am experiencing, the advanced select works only after a hard refresh on the first render it looks something like this.

image

amrajat avatar Mar 12 '24 04:03 amrajat

I see that the click event listener is not added to the button when navigating to the page, only when hard refreshing

insivika avatar Mar 12 '24 16:03 insivika

I have this issue as well. I have to hard refreshing my page to get the popover. Did you guys find a solution to solve this?

algebra2boy avatar Mar 15 '24 14:03 algebra2boy

I had to change the PrelineScript back to how its suggested in the docs and increase the setTimeout delay from 100 to 1000

'use client';

/* eslint-disable @typescript-eslint/no-explicit-any */
import { usePathname } from 'next/navigation';
import { useEffect } from 'react';

declare global {
  interface Window {
    HSStaticMethods: any;
  }
}

export default function PrelineScript() {
  const path = usePathname();
  useEffect(() => {
    import('preline/preline');
  }, []);

  useEffect(() => {
    setTimeout(() => {
      window.HSStaticMethods.autoInit();
    }, 1000);
  }, [path]);

  return null;
}

insivika avatar Mar 15 '24 14:03 insivika

Hey, thanks for the quick reply. The suggested 1000 setTime delay works on my end! Thanks again.

algebra2boy avatar Mar 15 '24 15:03 algebra2boy

after changing the delay to 1000, it works for rendering only but its functionality still not working.

    const planEl = HSSelect.getInstance("#plan");
    planEl.on("change", (val) => setPlan(Number(val)));

    const planTypeEl = HSSelect.getInstance("#planType");
    planTypeEl.on("change", (val) => setPlanType(val));

    const quantityEl = HSInputNumber.getInstance("#quantity");
    quantityEl.on("change", ({ inputValue }) =>
      setQuantity(Number(inputValue))
    );
  });

When we try to select options it doesn't work.

amrajat avatar Mar 16 '24 17:03 amrajat

This issue is the same as mentioned on #278, and is yet to be resolved.

Increasing the timeout does decrease the frequency of this issue, but it does still occasionally occur, it could be increased more to further improve it but the JS features are unresponsive for the duration of the timeout, which doesn't seem like a great solution to this.

Something has been introduced in v2 that is causing this issue as I've rolled back to 1.9.0 and this problem does not exist in that version.

Paradiced avatar Mar 24 '24 17:03 Paradiced

hi is the dropdown issue fixed?

kishsak avatar May 10 '24 13:05 kishsak

I've encountered this issue as well, even in 2.2.0 version (using Vue 3), not only with dropdowns but also with modals. As a temporary solution, reverting to version 1.9.0 fixed it.

Natsume-197 avatar May 10 '24 15:05 Natsume-197

I've encountered this issue as well, even in 2.2.0 version (using Vue 3), not only with dropdowns but also with modals. As a temporary solution, reverting to version 1.9.0 fixed it.

thx bro, i'am stress about that, downgrade the version 2.1.0 to 1.9.0 is worked in ReactJS 👍

muhismail015 avatar May 11 '24 23:05 muhismail015

I've encountered this issue as well, even in 2.2.0 version (using Vue 3), not only with dropdowns but also with modals. As a temporary solution, reverting to version 1.9.0 fixed it.

Thx for the solution

kgnfth avatar May 13 '24 22:05 kgnfth

Hey folks, since every framework has its ins and outs it's hard to know what exactly causing the issue. We suggest to open a new issue with Stackblitz demo and step by step details to reproduce the issue.

Here's a great example how JS components should be integrated to specific frameworks.

Cheers!

jahaganiev avatar Jun 01 '24 19:06 jahaganiev