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

Lazy loading crashes Flatpickr #210

Open
Kovbo opened this issue Mar 9, 2023 · 1 comment
Open

Lazy loading crashes Flatpickr #210

Kovbo opened this issue Mar 9, 2023 · 1 comment

Comments

@Kovbo
Copy link

Kovbo commented Mar 9, 2023

I have found a bug that crashes the application if you move from a page with Flatpickr to any lazy-loaded page.

Uncaught TypeError: Cannot read properties of null (reading 'destroy')
    at DateTimePicker2.destroyFlatpickrInstance (index.js:112:23)
    at DateTimePicker2.componentWillUnmount (index.js:168:12)
    at callComponentWillUnmountWithTimer (react-dom.development.js:22683:16)
    
    this.flatpickr.destroy(); // <- This line cause the issue
    this.flatpickr = null;

It just cannot destroy a Flatpickr instance.

An example of a regular SPA using React Router Dom:

const PageTwo = lazy(() => import('../modules/wizards/WizardsPage'))
...

<Routes>
    <Route
          path='app/one'
          element={<PageOne />} // Renders Flatpickr
        />
      <Route
          path='app/two'
          element={<PageTwo />} //Lazy loading
        />
</Routes>
//PageOne
<div>
        <Flatpickr placeholder='Click to select' />
        <Link to='/app/two'>Move to Page Two</Link> // <- Crashes application
<div>     

Regular import or just a prior visit to a lazy-loaded page solves the issue, but it's not ideal.

@ZachSaucier
Copy link

I think this is the same issue as #83

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

2 participants