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

v2 only works once after page reload #171

Closed
shanke-pvex opened this issue Nov 22, 2023 · 26 comments
Closed

v2 only works once after page reload #171

shanke-pvex opened this issue Nov 22, 2023 · 26 comments

Comments

@shanke-pvex
Copy link

I use Laravel 10 with inertia and vue3.
Every javascript trigger only works after a page reload.
When navigating to another page and go back in my SPA none of the javascript is working.

With version 1.9.0 everything is fine (except the new added plugins :)).

Is version 2.0 compatible with inertia?

@shanke-pvex shanke-pvex changed the title v2 only works once after pages reload v2 only works once after page reload Nov 22, 2023
@ashikck
Copy link

ashikck commented Nov 23, 2023

Same for me with react and vite.

@sebastianbilling
Copy link

Same for me with React and NextJS

@hiteshjoshi
Copy link
Contributor

hiteshjoshi commented Nov 24, 2023

Same for me with Astro 3.5.x

@lenart
Copy link

lenart commented Nov 26, 2023

Seems like it's the same story with Rails and Turbo. It works on initial page load but not after page is navigated.

@jahaganiev
Copy link
Member

Hey everyone,

Our team just recently updated Framework Guides page with live playground demos for all v2 JS components. Please try out with the latest version and let us know if you still have any issues.

Cheers!

@ashikck
Copy link

ashikck commented Nov 28, 2023

Worked for me. Thanks alot

@ndrshnsn
Copy link

Seems like it's the same story with Rails and Turbo. It works on initial page load but not after page is navigated.

hey @lenart have you find any way to solve this? its working only with turbo: false...

@ndrshnsn
Copy link

ndrshnsn commented Nov 28, 2023

Seems like it's the same story with Rails and Turbo. It works on initial page load but not after page is navigated.

hey @lenart have you find any way to solve this? its working only with turbo: false...

Just found myself and used other solutions as reference. Call Preline loaders into turbo:load event.

document.addEventListener("turbo:load", function(event) {
    HSAccordion.autoInit();
    HSDropdown.autoInit();
    HSOverlay.autoInit();
    HSSelect.autoInit();
});

and call it from your main application.js

@shanke-pvex
Copy link
Author

Hey everyone,

Our team just recently updated Framework Guides page with live playground demos for all v2 JS components. Please try out with the latest version and let us know if you still have any issues.

Cheers!

It works

@lenart
Copy link

lenart commented Nov 29, 2023

Seems like it's the same story with Rails and Turbo. It works on initial page load but not after page is navigated.

hey @lenart have you find any way to solve this? its working only with turbo: false...

Just found myself and used other solutions as reference. Call Preline loaders into turbo:load event.

document.addEventListener("turbo:load", function(event) {
    HSAccordion.autoInit();
    HSDropdown.autoInit();
    HSOverlay.autoInit();
    HSSelect.autoInit();
});

and call it from your main application.js

@ndrshnsn haven't had a chance to try it out myself but it seems like you should call HSStaticMethods.autoInit(); and don't have to deal with individual components. I'd probably put that code to turbo:visit dom event.

UPDATE: I did what I said above and it works.

@jahaganiev
Copy link
Member

Huge thanks everyone for the updates and sharing the workaround with others - your contributions are truly appreciated!

@sebastianbilling @hiteshjoshi if you are still having an issue, please open a new issue with more details.

Cheers!

@sajjadgol
Copy link

sajjadgol commented Nov 30, 2023

I copied DOM when dropdown menu not work , below code generated :

<div class="hs-dropdown-menu min-w-[18rem] transition-[opacity,margin] duration-[0.1ms] sm:duration-[150ms] hs-dropdown-open:opacity-100 opacity-0 sm:w-48 z-10 bg-white sm:shadow-md rounded-lg p-2 dark:bg-gray-800 sm:dark:border dark:border-gray-700 dark:divide-gray-700 before:absolute top-full sm:border before:-top-5 before:start-0 before:w-full before:h-5 block" data-popper-escaped="" data-popper-placement="bottom-start" style="position: fixed; inset: 0px auto auto 0px; transform: translate(1290px, 70px);">

and copied Dom when dropdown and other element work correctly , below code

<div class="hs-dropdown-menu min-w-[18rem] transition-[opacity,margin] duration-[0.1ms] sm:duration-[150ms] hs-dropdown-open:opacity-100 opacity-0 sm:w-48 z-10 bg-white sm:shadow-md rounded-lg p-2 dark:bg-gray-800 sm:dark:border dark:border-gray-700 dark:divide-gray-700 before:absolute top-full sm:border before:-top-5 before:start-0 before:w-full before:h-5 hidden" style="">

many different , you can use Meld software for tracking differents

@ndrshnsn
Copy link

Seems like it's the same story with Rails and Turbo. It works on initial page load but not after page is navigated.

hey @lenart have you find any way to solve this? its working only with turbo: false...

Just found myself and used other solutions as reference. Call Preline loaders into turbo:load event.

document.addEventListener("turbo:load", function(event) {
    HSAccordion.autoInit();
    HSDropdown.autoInit();
    HSOverlay.autoInit();
    HSSelect.autoInit();
});

and call it from your main application.js

@ndrshnsn haven't had a chance to try it out myself but it seems like you should call HSStaticMethods.autoInit(); and don't have to deal with individual components. I'd probably put that code to turbo:visit dom event.

UPDATE: I did what I said above and it works.

Thanks, worked like a charm. Noted that if you need to use one of these components + Stimulus (dependent dropdowns, for ex) you should call them again in controller - like HSSelect.autoInit() in controller connect

Just sharing my findings ;)

@VishalLudhrani
Copy link

VishalLudhrani commented Nov 30, 2023

Huge thanks everyone for the updates and sharing the workaround with others - your contributions are truly appreciated!

@sebastianbilling @hiteshjoshi if you are still having an issue, please open a new issue with more details.

Cheers!

I still am facing issues.

I referred to the updated documentation, and made changes accordingly.
It works as intended during the development.

However, the build fails with ReferenceError: Self is not defined.

Please find the details here

@hiteshjoshi
Copy link
Contributor

Hey everyone,

Our team just recently updated Framework Guides page with live playground demos for all v2 JS components. Please try out with the latest version and let us know if you still have any issues.

Cheers!

Still the same. If I add a new item on the fly after preline load, it won't work.

@hiteshjoshi
Copy link
Contributor

Yup, it behaves very strange. Had to go back to v1.9.0

So at whatever point my dom adds a new dropdown it works in 1.9.0
but with 2.0.2 it doesnt work (sometimes it works after a few clicks but not always)

@zerobig
Copy link

zerobig commented Nov 30, 2023

I solved it.

./node_modules/preline/preline.d.ts
add lines:

declare global {
	interface Window {
		HSStaticMethods: {
			afterTransition(el: HTMLElement, cb: Function): void;
			getClassPropertyAlt(el: HTMLElement, prop?: string, val?: string): string;
			getClassProperty(el: HTMLElement, prop?: string, val?: string): string;
			autoInit(collection: string | string[] = 'all'): void;
		};
	}
}

./components/PrelineScript.tsx
change two lines:

  useEffect(() => {
    setTimeout(() => {
-     HSStaticMethods.autoInit();
+     window.HSStaticMethods.autoInit();
-   }, 100);
+   }, 300);
  }, [path]);

@koossaayy
Copy link

I can confirm this; using Livewire, and preline v2.0.2, but rolling back to v1.9.0 it works perfectly.

@umaraziz0
Copy link

Can confirm, JS features like tabs don't work properly in v2, it stops working on HMR or page navigation, hopefully a fix will come soon

@Sicria
Copy link

Sicria commented Dec 19, 2023

@umaraziz0 Check out #205 it has an approach that may work for you.

@billymosis
Copy link

Seems like it's the same story with Rails and Turbo. It works on initial page load but not after page is navigated.

hey @lenart have you find any way to solve this? its working only with turbo: false...

Just found myself and used other solutions as reference. Call Preline loaders into turbo:load event.

document.addEventListener("turbo:load", function(event) {
    HSAccordion.autoInit();
    HSDropdown.autoInit();
    HSOverlay.autoInit();
    HSSelect.autoInit();
});

and call it from your main application.js

Hi for anybody here and using HTMX and sent partial HTML from server we can use htmx load event like this

    document.addEventListener('htmx:load', function() {
    ....
    }

@mpspm
Copy link

mpspm commented Jan 17, 2024

Has anyone gotten HMR to work with Inertia + React? I looked at the Preline framework guide for React and it's slightly different due to how Inertia initializes a React app, which is like this:

// app.jsx
import { createInertiaApp } from '@inertiajs/react'
import { createRoot } from 'react-dom/client'

createInertiaApp({
  resolve: name => {
    const pages = import.meta.glob('./Pages/**/*.jsx', { eager: true })
    return pages[`./Pages/${name}.jsx`]
  },
  setup({ el, App, props }) {
    createRoot(el).render(<App {...props} />)
  },
})

Trying to use useEffect and useLocation as recommended by the framework guide somewhere here won't work as this isn't a component function, and the App component sent to the render function doesn't appear to be an actual component file in my js directory, otherwise I'd try adding the hooks there. Any help is so greatly appreciated.

@hiteshjoshi
Copy link
Contributor

#197 (comment)

@jaseemuddinn
Copy link

Seems like it's the same story with Rails and Turbo. It works on initial page load but not after page is navigated.

hey @lenart have you find any way to solve this? its working only with turbo: false...

Just found myself and used other solutions as reference. Call Preline loaders into turbo:load event.

document.addEventListener("turbo:load", function(event) {
    HSAccordion.autoInit();
    HSDropdown.autoInit();
    HSOverlay.autoInit();
    HSSelect.autoInit();
});

and call it from your main application.js

@ndrshnsn haven't had a chance to try it out myself but it seems like you should call HSStaticMethods.autoInit(); and don't have to deal with individual components. I'd probably put that code to turbo:visit dom event.

UPDATE: I did what I said above and it works.

Could you please share your file of app.jsx??

@ode96-dev
Copy link

I had the same issue. I resolved it by maintaining the guidelines...Preline maintains that: "projects_root_directory/app/components/PrelineScript.tsx", meaning the PrelineScript.tsx component must be housed within a components folder in the app directory.

@jaseemuddinn
Copy link

@ode96-dev thanks

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