Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Next release #301

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ Looking for more guidance? Full documentation for Faststore lives [on this GitHu

This project has strict performance budgets. Right out of the box, this project performs around 95 on Google's Page Speed Insights website, which usually is way more strict than your laptop's chrome lighthouse. Every time you commit to the repository, our QA bots will run and evaluate your code quality. We recommend you NEVER put in production a code that breaks any of the bots. If a bot breaks and still you need to put the code into production, change the bot config (`lighthouserc.js`, `cypress.json`) to make it pass and merge. This way you ensure your website will keep performing well during the years to come.

### Lazy loading components

[According to Gatsby](https://www.gatsbyjs.com/docs/how-to/performance/improving-site-performance/#step-5-on-critical-paths-lazy-load-below-the-fold-components):

> `loadable-components` is the recommended lazy-loading solution for all server-side-rendered React applications, including Gatsby websites.

So First, try to use the native `lazy`/`Suspense` alternative. But if there is some Server Side Rendered dependency, switch to using the `loadable-components`.

Finally, for that pages that can use both `lazy` and `loadable`, keep the preference to use only `loadable` for the sake of avoiding loading two different things for the same purpose.

## Adding third party scripts

Adding third-party scripts to a webpage usually makes it slow. To maintain great performance while third-party scripts are added, this project uses [Partytown](https://github.com/BuilderIO/partytown/), a lazy-load library that helps relocate intensive scripts into a web worker and off of the main thread.
Expand Down
38 changes: 20 additions & 18 deletions cypress/integration/plp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,30 @@ describe('Search page Filters and Sorting options', () => {
.should('exist')
.first()
.click()
.getById('filter-modal-button-apply')
.click()

// Check applied filters
cy.getById('open-filter-button')
.click()
.getById('filter-accordion-panel-checkbox')
.first()
.click({ force: true })
.then(($checkbox) => {
const value = $checkbox.attr('data-value')
const quantity = $checkbox.attr('data-quantity')

// Check if the filter applied actually ended up in the URL
cy.location('href').should((loc) => {
expect(loc).to.include(value)
})

// Check if the filter applied actually brought the number of products it said it would
cy.getById('total-product-count').then(($countDiv) => {
expect(Number($countDiv.attr('data-count'))).to.eq(Number(quantity))
})
cy.getById('filter-modal-button-apply')
.click()
.then(() => {
// Check if the filter applied actually ended up in the URL
cy.location('href').should((loc) => {
expect(loc).to.include(value)
})

// Check if the filter applied actually brought the number of products it said it would

cy.waitUntil(() => {
return cy.get('.product-grid').should('exist')
}).then(() => {
cy.getById('total-product-count').then(($countDiv) => {
expect(Number($countDiv.attr('data-count'))).to.eq(
Number(quantity)
)
})
})
})
})
})

Expand Down
2 changes: 1 addition & 1 deletion gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
start_url: '/',
icon: 'src/images/icon.png',
background_color: '#E31C58',
theme_color: '#E31C58',
theme_color: '#ffffff',
display: 'standalone',
cache_busting_mode: 'none',
},
Expand Down
24 changes: 9 additions & 15 deletions src/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { lazy, Suspense, useState } from 'react'
import Loadable from '@loadable/component'
import React, { useState } from 'react'
import loadable from '@loadable/component'
import Navbar from 'src/components/common/Navbar'
import { BellRinging as BellRingingIcon } from 'phosphor-react'
import { useCartNotificationEffect } from 'src/sdk/cart/useCartNotificationEffect'
Expand All @@ -9,9 +9,11 @@ import type { PropsWithChildren } from 'react'
import Alert from './components/ui/Alert'
import './styles/fonts.css'

const CartSidebar = lazy(() => import('src/components/cart/CartSidebar'))
const Toast = lazy(() => import('src/components/ui/Toast'))
const Footer = Loadable(() => import('src/components/common/Footer'))
const CartSidebar = loadable(() => import('src/components/cart/CartSidebar'))

const Toast = loadable(() => import('src/components/ui/Toast'))

const Footer = loadable(() => import('src/components/common/Footer'))

function Layout({ children }: PropsWithChildren<unknown>) {
const { displayMinicart, toasts } = useUI()
Expand Down Expand Up @@ -51,17 +53,9 @@ function Layout({ children }: PropsWithChildren<unknown>) {
<main>{children}</main>

<Footer />
{displayMinicart && (
<Suspense fallback={null}>
<CartSidebar />
</Suspense>
)}
{displayMinicart && <CartSidebar />}

{toasts.length > 0 && (
<Suspense fallback={null}>
<Toast />
</Suspense>
)}
{toasts.length > 0 && <Toast />}
</div>
)
}
Expand Down
10 changes: 6 additions & 4 deletions src/components/cart/CartSidebar/CartSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import { useCart } from 'src/sdk/cart/useCart'
import { useCheckoutButton } from 'src/sdk/cart/useCheckoutButton'
import Button from 'src/components/ui/Button'
import IconButton from 'src/components/ui/IconButton'
import {
ArrowRight as ArrowRightIcon,
X as XIcon,
Expand Down Expand Up @@ -51,12 +52,13 @@ function CartSidebar() {
{totalItems}
</Badge>
</div>
<Button
<IconButton
data-testid="cart-sidebar-button-close"
classes="cart-sidebar__button"
aria-label="Close Cart"
icon={<XIcon size={32} />}
onClick={() => onDismissTransition()}
>
<XIcon size={32} />
</Button>
/>
</header>
<Alert icon={<TruckIcon size={24} />}>
Free shiping starts at $300
Expand Down
10 changes: 3 additions & 7 deletions src/components/cart/CartSidebar/cart-sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@
display: flex;
align-items: center;
justify-content: space-between;
padding: var(--space-5) var(--page-padding-phone) var(--space-4);
padding: var(--space-2) var(--page-padding-phone) var(--space-2);
background-color: var(--bg-neutral-lightest);

button {
position: absolute;
right: calc(-1 * var(--page-padding-phone));
margin-right: var(--space-0);
color: var(--color-text);
background-color: transparent;
.cart-sidebar__button {
margin-right: calc(-1 * var(--space-1));
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/components/cart/CartToggle/CartToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import Button from 'src/components/ui/Button'
import IconButton from 'src/components/ui/IconButton'
import { useCartToggleButton } from 'src/sdk/cart/useCartToggleButton'
import { ShoppingCart as ShoppingCartIcon } from 'phosphor-react'

Expand All @@ -9,13 +9,12 @@ function CartToggle() {
const btnProps = useCartToggleButton()

return (
<Button
<IconButton
{...btnProps}
className="cart-toggle"
aria-label={`Cart with ${btnProps['data-items']} items`}
>
<ShoppingCartIcon size={32} />
</Button>
icon={<ShoppingCartIcon size={32} />}
/>
)
}

Expand Down
18 changes: 1 addition & 17 deletions src/components/cart/CartToggle/cart-toggle.scss
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
@import "../../../styles/utilities.scss";

.cart-toggle[data-store-button] {
.cart-toggle[data-store-icon-button] {
position: relative;
display: flex;
align-items: center;
justify-content: center;
min-width: var(--tap-min-size);
min-height: var(--tap-min-size);
background-color: transparent;
border-width: 0;
border-radius: var(--border-radius-button);
cursor: pointer;
transition: background-color .5s ease;

svg { color: var(--color-text); }

&::after {
--cart-toggle-size: var(--space-3);
Expand All @@ -34,8 +22,4 @@
border-radius: var(--border-radius-pill);
content: attr(data-items);
}

&:hover {
background-color: var(--bg-secondary-light);
}
}
4 changes: 2 additions & 2 deletions src/components/common/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { memo } from 'react'
import {
List as UIList,
Icon as UIIcon,
Expand Down Expand Up @@ -137,4 +137,4 @@ function Footer() {
)
}

export default Footer
export default memo(Footer)
25 changes: 12 additions & 13 deletions src/components/common/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState } from 'react'
import React, { memo, useState } from 'react'
import { Link as LinkGatsby } from 'gatsby'
import { List as UIList } from '@faststore/ui'
import CartToggle from 'src/components/cart/CartToggle'
import Logo from 'src/components/ui/Logo'
import Link from 'src/components/ui/Link'
import Button from 'src/components/ui/Button'
import IconButton from 'src/components/ui/IconButton'
import { List as ListIcon, X as XIcon } from 'phosphor-react'
import SignInLink from 'src/components/ui/SignInLink'
import SlideOver from 'src/components/ui/SlideOver'
Expand Down Expand Up @@ -50,13 +50,12 @@ function Navbar() {
<header className="navbar / grid-content-full">
<div className="navbar__header / grid-content">
<section className="navbar__row">
<Button
className="navbar__menu"
<IconButton
classes="navbar__menu"
aria-label="Open Menu"
icon={<ListIcon size={32} />}
onClick={() => setShowMenu(true)}
>
<ListIcon size={32} />
</Button>
/>
<LinkGatsby
to="/"
aria-label="Go to Faststore home"
Expand Down Expand Up @@ -95,15 +94,15 @@ function Navbar() {
>
<Logo />
</LinkGatsby>
<Button
className="navbar__button"

<IconButton
classes="navbar__button"
aria-label="Close Menu"
icon={<XIcon size={32} />}
onClick={() => {
onDismissTransition?.()
}}
>
<XIcon size={32} />
</Button>
/>
</header>
<div className="navlinks">
<NavLinks />
Expand All @@ -118,4 +117,4 @@ function Navbar() {
)
}

export default Navbar
export default memo(Navbar)
15 changes: 2 additions & 13 deletions src/components/common/Navbar/navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
}

.navbar__menu[data-store-button] {
color: var(--color-text);
background-color: transparent;
border: 0;

@include media(">=notebook") { display: none; }
}

Expand Down Expand Up @@ -87,17 +83,10 @@
display: flex;
align-items: center;
justify-content: space-between;
padding: var(--space-3) 0;
padding-bottom: var(--space-2);

.navbar__button {
position: absolute;
right: calc(-1 * var(--page-padding-phone));
display: flex;
margin-right: var(--space-1);
padding: var(--space-1);
color: var(--color-text-display);
background-color: transparent;
border: 0;
margin-right: calc(-1 * var(--space-1));
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/components/common/SearchInput/search-input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
border-radius: var(--border-radius-default);
transition: box-shadow .2s ease, border .2s ease;

&:focus { @include input-focus-ring; }
&:hover {
border-color: var(--color-border-input-selected);
box-shadow: 0 0 0 var(--border-width-0) var(--color-border-input-selected);
}

@include input-focus-ring;
}

[data-store-icon] { display: block; }
Expand Down
Loading