reactjs / reactjs/react-docgen

When postcss modules are present, in some scenarios react-docgen tries to parse css files

Aperta
#892 2 commenti 6 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
TypeScript
Stelle
3.8k
Fork
316
Merge medio
5h 7m
PR unite (30g)
4

Descrizione

Background

In certain scenarios react-docgen tries to parse CSS modules.

This yields an error as follows:

Use case

See related Storybook issue https://github.com/storybookjs/storybook/issues/25662 and stackblitz reproduction https://stackblitz.com/edit/github-cwovgn-yvzreq

Have a component like so

import React from "react"
import styles, { stylesheet } from "./Container.module.css"

const Container = ({ children }) => (
  <div>
    {children}
  </div>
)

export default Container;
export stylesheet;

And where the css file contains an @import

@import url("../../css/variables.css");

The babel config passed to react-docgen doesn't take into account the .babelrc file and attempts to parse the .css file as JavaScript.

This causes an error like so

[vite] Internal server error: /path/to/Container.module.css: Support for the experimental syntax 'decorators' isn't currently enabled (1:1):

Is there anyway to configure react-docgen to ignore .css files in this case?

If you're wondering why are we importing and exporting the processed stylesheet, we're building a critical css component that inlines CSS needed for the first paint. We're doing this by using rollup-post-css-modules to import postcss modules but also export the built stylesheet so it can be collated in a reliable fashion (ie the class names don't change from what is rendered in the component).

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dalla riproduzione StackBlitz collegata e dalla relativa issue di Storybook, quindi traccia il modo in cui react-docgen utilizza la configurazione Babel fornita quando il componente importa ed esporta un modulo CSS. Il lavoro è completato quando il file CSS non viene più analizzato come JavaScript, mentre l’estrazione della documentazione per il componente React continua a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
react, typescript
Ambito
tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.