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

Fix 2: Content Prioritization #2

Open
wants to merge 3 commits into
base: fix/01-lazy-entire-sections
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"react": "^16.10.2",
"react-burger-menu": "^2.6.11",
"react-dom": "^16.10.2",
"react-lazy-named": "^1.0.0",
"react-lazy-named": "^1.1.1",
"react-lorem-ipsum": "^1.4.3",
"react-scripts": "3.2.0"
},
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
Expand Down
49 changes: 49 additions & 0 deletions src/components/Animated/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { Suspense } from 'react';
import lazy from 'react-lazy-named';

// this is ugly
// const Div = lazy(() =>
// import(
// 'framer-motion' /* webpackChunkName: "framer", webpackPreload: true */
// ).then(mod => ({
// default: mod.motion.div,
// }))
// );

const MotionDiv = lazy(() => import('framer-motion'), 'motion.div');

export const AnimatedDiv = props => (
<Suspense fallback={<div className={props.className}>{props.children}</div>}>
<MotionDiv {...props} />
</Suspense>
);

const MotionA = lazy(() => import('framer-motion'), 'motion.a');

export const AnimatedA = props => (
<Suspense
fallback={
<a className={props.className} href={props.href}>
{props.children}
</a>
}
>
<MotionA {...props} />
</Suspense>
);

const MotionLi = lazy(() => import('framer-motion'), 'motion.li');

export const AnimatedLi = props => (
<Suspense fallback={<li className={props.className}>{props.children}</li>}>
<MotionLi {...props} />
</Suspense>
);

const MotionUl = lazy(() => import('framer-motion'), 'motion.ul');

export const AnimatedUl = props => (
<Suspense fallback={<ul className={props.className}>{props.children}</ul>}>
<MotionUl {...props} />
</Suspense>
);
16 changes: 13 additions & 3 deletions src/components/BoringContent/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
// @ts-nocheck
import React from 'react';
import { LoremIpsum } from 'react-lorem-ipsum';
import React, { Suspense } from 'react';
import lazy from 'react-lazy-named';

const LoremIpsum = lazy(
() =>
new Promise(resolve =>
setTimeout(() => resolve(import('react-lorem-ipsum')), 5000)
),
'LoremIpsum'
);

const BoringContent = () => (
<section>
<h2>Terms and Conditions</h2>
<LoremIpsum avgWordsPerSentence={12} p={10} />
<Suspense fallback={null}>
<LoremIpsum avgWordsPerSentence={12} p={10} />
</Suspense>
</section>
);

Expand Down
Binary file modified src/components/Hero/motorcycle-sm.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions src/components/Products/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-nocheck
import React, { useState, useEffect } from 'react';
import { motion } from 'framer-motion';
import { shuffle } from 'lodash-es';
import { AnimatedA, AnimatedDiv } from '../Animated';
import {
delay,
spring,
Expand Down Expand Up @@ -33,22 +33,22 @@ function Products() {
<h2>Pick your next Hog ride</h2>
<div className={s.animated}>
{colors.map(([background, fill], idx) => (
<motion.a
<AnimatedA
whileHover={{ scale: 1.2 }}
key={background}
layoutTransition={spring}
className={`${s.tile} ${s[`moto${idx + 1}`]}`}
style={{ backgroundColor: background, '--logo-color': fill }}
>
<motion.div
<AnimatedDiv
animate={logoAnimation}
className={s.shine}
transition={{
...logoTransition,
delay: Math.random() * 3 * delay,
}}
></motion.div>
</motion.a>
></AnimatedDiv>
</AnimatedA>
))}
</div>
</section>
Expand Down
22 changes: 11 additions & 11 deletions src/components/Sidebar/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-nocheck
import React, { useState } from 'react';
import { motion } from 'framer-motion';
import { push as Menu } from 'react-burger-menu';
import { AnimatedUl, AnimatedLi } from '../Animated';

import './styles.css';

Expand Down Expand Up @@ -33,28 +33,28 @@ const Hero = () => {
onStateChange={({ isOpen }) => setTimeout(() => setOpen(isOpen), 50)}
>
{open ? (
<motion.ul initial="hidden" animate="visible" variants={list}>
<motion.li variants={items}>
<AnimatedUl initial="hidden" animate="visible" variants={list}>
<AnimatedLi variants={items}>
<a className="menu-item" href="/">
Home
</a>
</motion.li>
<motion.li variants={items}>
</AnimatedLi>
<AnimatedLi variants={items}>
<a className="menu-item" href="/">
My Hog
</a>
</motion.li>
<motion.li variants={items}>
</AnimatedLi>
<AnimatedLi variants={items}>
<a className="menu-item" href="/">
Cart
</a>
</motion.li>
<motion.li variants={items}>
</AnimatedLi>
<AnimatedLi variants={items}>
<a className="menu-item" href="/">
Contact
</a>
</motion.li>
</motion.ul>
</AnimatedLi>
</AnimatedUl>
) : (
false
)}
Expand Down
15 changes: 11 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6044,6 +6044,11 @@ lodash._reinterpolate@^3.0.0:
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
integrity sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=

lodash.get@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=

lodash.memoize@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
Expand Down Expand Up @@ -8189,10 +8194,12 @@ react-is@^16.8.1, react-is@^16.8.4:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.10.2.tgz#984120fd4d16800e9a738208ab1fba422d23b5ab"
integrity sha512-INBT1QEgtcCCgvccr5/86CfD71fw9EPmDxgiJX4I2Ddr6ZsV6iFXsuby+qWJPtmNuMY0zByTsG4468P7nHuNWA==

react-lazy-named@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/react-lazy-named/-/react-lazy-named-1.0.0.tgz#18264c847e85cfd88d2d2f55862331c321897d3c"
integrity sha512-uQYGX8eDpoxmsIW5cm+yh2/6lP0MCmYyGiE8Ti0RU9NGyOl46pmixDVhQdJGUbpqMe1kqWGWbs0nog9U5ag9ng==
react-lazy-named@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/react-lazy-named/-/react-lazy-named-1.1.1.tgz#84d9813d7645754dbbdd7bff2e9dd2c6b7fc02d9"
integrity sha512-6qUKD8lmoH7gy5Ws0Cc9Jq6aE5SsZN+1npxo3jgmzJbK9Q64n5us7ZS9ZHrCBC6rnbrwae0FV1gnL+NlOTURkw==
dependencies:
lodash.get "^4.4.2"

react-lorem-ipsum@^1.4.3:
version "1.4.3"
Expand Down