-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Toolbar Date Filter, remove react-hot-loader, fix dashboard date filter URL #3586
Conversation
This reverts commit e59bcfa
Cypress fails and it's going to be complicated to work around that: cypress-io/cypress#8948 |
Reverted back to webpack 4 because cypress. Tests are now green. Ready for a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a big diff for such a small UX-wise change…
Ready for another look! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Let's get it in! |
Changes
This PR started innocently enough, with the desire to just add a datefilter into the toolbar, so we could now do this:
I had to refactor the DateFilter a bit to separate it from the
dateFilterLogic
(which is tied to the/insights
url), and was happy when all was done. However even though all other pages were fine, the/insights
and/dashboard/:id
pages would not load anymore:The error was thrown when calling
useState
... inside the date filter? This took countless hours of debugging to track down 🤦, but in the end it's a conflict between the react hot module reloading system and multiple configurations insidewebpack.json
(we export an array of configs -- we can't merge them into one config with multiple entrypoints as the toolbar has a different set of webpack plugins that it needs for CSS).Turns out we can't
import
the same"lib/components/*"
inside both the toolbar and the main app... and have both running at the same time. Because the toolbar is loaded via posthog-js and comes with its own version of React inside the.js
bundle, we'll have two copies of React loaded in memory... but both of them will try to load the samevendor~lib~datepicker-blabla.js
file that's delivered by HMR, which is then linked to just one of the two React instances.The only change to make this work was to remove the component from the toolbar:
... but then there would be no date picker in the toolbar.
The solution (after trying oh so many things for, again, hours 😢), was to remove react hot module reloading altogether. It's deprecated anyway and we should switch to react fast refresh. Without react-hot-loader, when you make a change, then instead of a react component being swapped in place, the full page will reload instead. In my experience this HMR was in my experience often broken anyway and I frequently reloaded the entire page. Plus it didn't work if you modified a
logic
.In addition to all of that, this PR also:
Upgrades to Webpack v5 (from v4)Checklist