Skip to content

Commit

Permalink
revert back to dynamically importing panelsnap
Browse files Browse the repository at this point in the history
  • Loading branch information
poojagunturu96 committed Dec 15, 2023
1 parent 6bed62d commit 3524b34
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/js/panel-snap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { $, $$ } from './utils/dom';
import { PREFERS_REDUCED_MOTION } from './utils/prefers-reduced-motion';
import { VALID_ASPECT_RATIO } from './utils/check-aspect-ratio';
import PanelSnap from 'panelsnap';

// Check if section height is less than the viewport height. If it is less than the viewport height,
// then set the directionThreshold as the difference to prevent scroll issues.
Expand All @@ -18,14 +17,20 @@ let defaultOptions = {
}
};

function lazyLoadPanelSnap() {
async function lazyLoadPanelSnap() {
if (VALID_ASPECT_RATIO && !PREFERS_REDUCED_MOTION) {
const { default: PanelSnap } = await import(
/* webpackChunkName: "panelsnap" */ 'panelsnap'
);

journey.forEach(() => new PanelSnap(defaultOptions));
}
}

const journey = $$('.journey');

if (journey.length !== 0) {
lazyLoadPanelSnap();
lazyLoadPanelSnap().catch(
(error) => 'An error occurred while loading panelsnap'
);
}
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const config = {
module: {
rules: [
{
// here doing the swiper loader and declaring no sideEffects
// declaring no sideEffects for files with .mjs extension which is mainly swiper
test: /\.mjs$/,
sideEffects: false
},
Expand Down

0 comments on commit 3524b34

Please sign in to comment.