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

Doesn't work in Storybook #72

Closed
2 tasks done
boar-is opened this issue Dec 13, 2023 · 6 comments
Closed
2 tasks done

Doesn't work in Storybook #72

boar-is opened this issue Dec 13, 2023 · 6 comments
Labels
bug Something isn't working where: package The issue corresponds to the distribution package

Comments

@boar-is
Copy link

boar-is commented Dec 13, 2023

Font Name (Geist Sans/Geist Mono):

  • Geist Sans
  • Geist Mono

Description of the Issue:
Importing the font into Storybook breaks it. Importing fonts via next/font works fine, however.

Steps to Reproduce:

  1. Create a Next app with Storybook
  2. Create a rootCss variable
import { GeistMono } from 'geist/font/mono'
import { GeistSans } from 'geist/font/sans'

import cs from '~/app/_lib/react/cs' // a utility to join classes

const rootCss = cs(
  GeistSans.variable,
  GeistMono.variable,
  'text-foreground max-w-full bg-background font-sans antialiased',
)

export default rootCss
  1. Use it in Storybook's preview:
import type { Preview } from '@storybook/react'

import '~/app/globals.css'

const preview = {
  decorators: [
    (Story) => <div className={rootCss}><Story/></div>
  ],
  // ...
} satisfies Preview

export default preview
  1. Have an error:
next_font_local__WEBPACK_IMPORTED_MODULE_0___default(...) is not a function
TypeError: next_font_local__WEBPACK_IMPORTED_MODULE_0___default(...) is not a function
    at ./node_modules/.pnpm/geist@1.2.0_next@14.0.4/node_modules/geist/dist/mono.js (http://localhost:6006/vendors-node_modules_pnpm_babel_runtime_7_23_5_node_modules_babel_runtime_helpers_esm_defineP-4ea83d.iframe.bundle.js:19620:73)
    at __webpack_require__ (http://localhost:6006/runtime~main.iframe.bundle.js:28:33)
    at fn (http://localhost:6006/runtime~main.iframe.bundle.js:301:21)
    at ./app/_lib/react/root-css.tsx (http://localhost:6006/main.iframe.bundle.js:593:73)
    at __webpack_require__ (http://localhost:6006/runtime~main.iframe.bundle.js:28:33)
    at fn (http://localhost:6006/runtime~main.iframe.bundle.js:301:21)
    at ./.storybook/decorators/theme/index.tsx (http://localhost:6006/main.iframe.bundle.js:292:81)
    at __webpack_require__ (http://localhost:6006/runtime~main.iframe.bundle.js:28:33)
    at fn (http://localhost:6006/runtime~main.iframe.bundle.js:301:21)
    at ./.storybook/preview.tsx (http://localhost:6006/main.iframe.bundle.js:529:75)

Expected Behavior:
Should work

Screenshots:
image

Environment (please complete the following information):

  • OS: N/A
  • Software: Next.js+Storybook
  • Version of the Font: 1.2.0
@boar-is boar-is added the bug Something isn't working label Dec 13, 2023
@AugustinMauroy
Copy link

same issue @BorisZubchenko have you found any solution ?

@boar-is
Copy link
Author

boar-is commented Jan 5, 2024

Unfortunately, no. I've returned to Inter for now.

@AugustinMauroy
Copy link

ok thanks I'ill do that

@igorgladkoborodov
Copy link

Hi everyone. I used this workaround to make it work on my project:

  1. Install and setup @storybook/nextjs as described here https://storybook.js.org/docs/8.0/get-started/nextjs

  2. Setup staticDirs in .storybook/main.ts:

  staticDirs: [
    {
      from: "../node_modules/geist/dist/fonts/geist-sans",
      to: "/fonts/geist-sans",
    },
    {
      from: "../node_modules/geist/dist/fonts/geist-mono",
      to: "/fonts/geist-mono",
    },
  ],
};
  1. Use localFont directly in .storybook/preview.tsx:
import localFont from "next/font/local";
import type { Preview } from "@storybook/react";

import "../src/app/globals.css";

const GeistSans = localFont({
  src: "../fonts/geist-sans/Geist-Variable.woff2",
  variable: "--font-geist-sans",
});

const GeistMono = localFont({
  src: "../fonts/geist-mono/GeistMono-Variable.woff2",
  variable: "--font-geist-mono",
});

const preview: Preview = {
  decorators: [
    (Story) => (
      <div className={`${GeistMono.variable} ${GeistSans.variable}`}>
        <Story />
      </div>
    ),
  ],
};

export default preview;

@guidoferreyra guidoferreyra added the where: package The issue corresponds to the distribution package label Feb 23, 2024
Gyozadaigaku added a commit to Gyozadaigaku/shadcn-design-system that referenced this issue Mar 31, 2024
Doesn't work in Storybook
via: vercel/geist-font#72
@Francois-Esquire
Copy link

Francois-Esquire commented May 14, 2024

Using the localFont API didn't quite work for me, I used the preview-head.html to get this working with the same staticDirs config... don't like it, but it works.

<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
  href="https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&display=swap"
  rel="stylesheet"
/>
<style>
  @font-face {
    font-family: "Geist Sans";
    src: url("fonts/geist-sans/Geist-Variable.woff2");
  }
  @font-face {
    font-family: "Geist Mono";
    src: url("fonts/geist-mono/Geist-Variable.woff2");
  }
  .dm-serif-display-regular {
    font-family: "DM Serif Display", serif;
    font-weight: 400;
    font-style: normal;
  }
  .dm-serif-display-regular-italic {
    font-family: "DM Serif Display", serif;
    font-weight: 400;
    font-style: italic;
  }
  :root {
    --font-dm_serif_display: "DM Serif Display", serif;
    --font-geist-sans: "Geist Sans", sans-serif;
    --font-geist-mono: "Geist Mono", monospace;
  }
</style>

@JohnPhamous
Copy link
Contributor

I think this has the same root cause as #59

Closing this as a duplicate of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working where: package The issue corresponds to the distribution package
Projects
None yet
Development

No branches or pull requests

6 participants