Skip to content

Commit

Permalink
@0.2.3: font loading cleanup (#4)
Browse files Browse the repository at this point in the history
Font cleanup: 
  remove index from next so font loading is not trigger eroneously
  cleaned up /next dir

move BannerBlock out of this package (it's specific to sites/market)
  • Loading branch information
artemis-prime authored Jan 27, 2024
1 parent dc194d7 commit 9b2533f
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 181 deletions.
12 changes: 5 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# dependencies
node_modules
**/node_modules
.pnp
.pnp.js

Expand All @@ -10,8 +11,6 @@ coverage

# next.js
.next/
out/
build

# misc
.DS_Store
Expand All @@ -24,17 +23,16 @@ yarn-error.log*
.pnpm-debug.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
**/.env
**/.env.*

# turbo
.turbo

.contentlayer
tsconfig.tsbuildinfo
**/tsconfig.tsbuildinfo

# build
**/dist

**/.npmrc
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

103 changes: 0 additions & 103 deletions pkgs/luxdefi-ui/blocks/components/banner-block.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions pkgs/luxdefi-ui/blocks/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import AccordianBlock from './accordian-block'
import BannerBlock from './banner-block'
import BlockFactory from './block-factory'
import CardBlock from './card-block'
import CTABlock from './cta-block'
Expand All @@ -11,7 +10,6 @@ import SpaceBlock from './space-block'

export {
AccordianBlock as AccordianBlockComponent,
BannerBlock as BannerBlockComponent,
BlockFactory,
CardBlock as CardBlockComponent,
CTABlock as CTABlockComponent,
Expand Down
18 changes: 0 additions & 18 deletions pkgs/luxdefi-ui/blocks/def/banner-block.ts

This file was deleted.

2 changes: 0 additions & 2 deletions pkgs/luxdefi-ui/blocks/def/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type AccordianBlock from './accordian-block'
import type BannerBlock from './banner-block'
import type Block from './block'
import type CardBlock from './card-block'
import type CTABlock from './cta-block'
Expand All @@ -13,7 +12,6 @@ import type SpecialBlock from './special-block'

export {
type AccordianBlock,
type BannerBlock,
type Block,
type CardBlock,
type CTABlock,
Expand Down
1 change: 0 additions & 1 deletion pkgs/luxdefi-ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ export {
} from './types'

export * from './primitives'
export * from './next'
11 changes: 11 additions & 0 deletions pkgs/luxdefi-ui/next/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Next related Lux helpers

### no `index.ts` file, and `load-and-return-lux-next-fonts-on-import.ts`

Next font loading requires the fonts to be assigned to const's in module scope (ie, loaded when the module is evaluated, exactly once).

If there was an `index.ts` "barrel file", and the client code imported anything from this package, it would have resulted in evaluting all the packages imported including the that loaded the fonts. Without the index, the client code knows what modules import it and thus when it happens.

tl;dr: See [this article from Vercel](https://vercel.com/blog/how-we-optimized-package-imports-in-next-js) about this issue.

(Previously, not having this safegaurd caused a serious bug becuase the fonts were loaded far too early.)
5 changes: 4 additions & 1 deletion pkgs/luxdefi-ui/next/determine-device-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { NextRequest, NextResponse, userAgent } from 'next/server'
import { getSelectorsByUserAgent } from 'react-device-detect'

export const determineDeviceMiddleware = async (request: NextRequest) => {
// writed this way so they can be chained :)
const determineDeviceMiddleware = async (request: NextRequest) => {

const ua = userAgent(request)
const { isMobileOnly, isTablet, isDesktop } = getSelectorsByUserAgent(ua.ua)
Expand All @@ -11,3 +12,5 @@ export const determineDeviceMiddleware = async (request: NextRequest) => {
url.searchParams.set('agent', agent)
return NextResponse.rewrite(url)
}

export default determineDeviceMiddleware
18 changes: 6 additions & 12 deletions pkgs/luxdefi-ui/next/get-app-router-font-classes.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import fontDescs from './lux-next-fonts'
import nextFonts from './load-and-return-lux-next-fonts-on-import'
import type NextFontDesc from './next-font-desc'

// These will be injected for <body> in app router app that uses our RootLayout

// First is assumed to be mapped to the default font and is injected into <body>
// as a normal tw font family class.
export default () => {
let nextFonts: NextFontDesc[] = []
fontDescs.forEach((desc: NextFontDesc) => {
if (desc.nextFont) {
nextFonts.push(desc)
}
})
return nextFonts.map(
(desc: NextFontDesc) => (desc.nextFont!.variable)
).join(' ') + ` font-${nextFonts[0].twName}`
}
export default () => (
nextFonts.map(
(desc: NextFontDesc) => (desc.nextFont!.variable)
).join(' ') + ` font-${nextFonts[0].twName}`
)
20 changes: 0 additions & 20 deletions pkgs/luxdefi-ui/next/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import type TwFontDesc from '../tailwind/tw-font-desc'

import twFonts from '../tailwind/lux-tw-fonts'

/*
Creating NextFontDesc's and TwFontDesc's has to be seperated because they are needed
at different times during the next compile / build. Otherwise a nasty
race condition happens!
Also, requires that "Font loaders must be called and assigned to a const in the module scope"
*/

const drukTextWide = localFont({
src: [
{
Expand All @@ -32,14 +41,7 @@ const inter = Inter({
subsets: ["latin"],
variable: "--font-inter",
})


/*
NextFontDesc and TwFontDesc have to be seperate because they are needed
at different times during the next compile / build. Otherwise a nasty
race condition happens! That's why they are in different files.
*/


export default [
{
font: inter,
Expand All @@ -62,3 +64,5 @@ export default [
})
}
) as NextFontDesc[]


2 changes: 1 addition & 1 deletion pkgs/luxdefi-ui/next/pages-router-font-vars.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import nextFonts from './lux-next-fonts'
import nextFonts from './load-and-return-lux-next-fonts-on-import'
import type NextFontDesc from './next-font-desc'

const PagesRouterFontVars: React.FC = () => {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/luxdefi-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@luxdefi/ui",
"version": "0.2.1",
"version": "0.2.3",
"description": "Library that contains shared UI primitives, styles, and core types",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
Expand Down
4 changes: 0 additions & 4 deletions pkgs/luxdefi-ui/primitives/video-player.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
'use client'
import React from 'react'

import type { Dimensions } from '../types'

interface VideoProps extends React.ComponentPropsWithoutRef<"video"> {
sources: string[]
className?: string
constrainTo?: Dimensions
}

const VideoPlayer = React.forwardRef<HTMLVideoElement, VideoProps>(
({
sources,
className='',
constrainTo,
...rest
}, ref) => {

Expand Down

0 comments on commit 9b2533f

Please sign in to comment.