Skip to content

Commit 85d2a5f

Browse files
committed
Improves Tailwind detection performance and reliability
1 parent a0beda5 commit 85d2a5f

File tree

18 files changed

+47
-13
lines changed

18 files changed

+47
-13
lines changed

docs/components/markdown/markdown.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ body {
110110

111111
You can use the `tocRenderer` prop to render a table of contents from your Markdown content. The headers will be automatically detected and rendered in the order they appear. You need to place the `<Toc />` component in your Markdown content to render the table of contents.
112112

113+
You can also use the `id` attribute in your headers to link to them directly.
114+
113115
<Frame background="subtle"><img src="../../images/previews/markdown-344947c9/document.1.jpg" style={{ width: '100%', height: 'auto', maxHeight: '500px', borderRadius: "0.25rem", overflow: "hidden", border: '1px solid #E5E4E2' }} /></Frame>
114116

115117
<div style={{paddingTop: "1rem", paddingBottom: "1rem"}}><CodeBlocks>

docs/sortedDocs.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/ui/templates.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ icon: list
88
<CardGroup>
99
<Card title="Scientific" href="../../../ui/templates/scientific-report">
1010
<div style={{ marginTop: "1rem", borderRadius: "0.25rem", overflow: "hidden" }}>
11-
<img src="../images/previews/ui-templates-scientific-report-31829950/document.1.jpg"/>
11+
<img src="../images/previews/ui-templates-scientific-report-7f68dcf5/document.1.jpg"/>
1212
</div>
1313
</Card>
1414
<Card title="With charts" href="../../../ui/templates/report-charts">
@@ -23,7 +23,7 @@ icon: list
2323
<CardGroup>
2424
<Card title="Receipt" href="../../../ui/templates/receipt">
2525
<div style={{ marginTop: "1rem", borderRadius: "0.25rem", overflow: "hidden" }}>
26-
<img src="../images/previews/ui-templates-receipt-4906d507/document.1.jpg"/>
26+
<img src="../images/previews/ui-templates-receipt-644d535a/document.1.jpg"/>
2727
</div>
2828
</Card>
2929
</CardGroup>
@@ -43,12 +43,12 @@ icon: list
4343
<CardGroup>
4444
<Card title="Basic" href="../../../ui/templates/invoice">
4545
<div style={{ marginTop: "1rem", borderRadius: "0.25rem", overflow: "hidden" }}>
46-
<img src="../images/previews/ui-templates-invoice-808342e7/document.1.jpg"/>
46+
<img src="../images/previews/ui-templates-invoice-c1137a92/document.1.jpg"/>
4747
</div>
4848
</Card>
4949
<Card title="Advanced with QR" href="../../../ui/templates/invoice-advanced">
5050
<div style={{ marginTop: "1rem", borderRadius: "0.25rem", overflow: "hidden" }}>
51-
<img src="../images/previews/ui-templates-invoice-advanced-089aa4f4/document.1.jpg"/>
51+
<img src="../images/previews/ui-templates-invoice-advanced-657df4ea/document.1.jpg"/>
5252
</div>
5353
</Card>
5454
</CardGroup>

docs/ui/templates/invoice-advanced.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ icon: file-invoice
44
category: Invoices
55
---
66

7-
<Frame background="subtle"><img src="../../images/previews/ui-templates-invoice-advanced-089aa4f4/document.1.jpg" style={{ width: '100%', height: 'auto', maxHeight: '500px', borderRadius: "0.25rem", overflow: "hidden", border: '1px solid #E5E4E2' }} /></Frame>
7+
<Frame background="subtle"><img src="../../images/previews/ui-templates-invoice-advanced-657df4ea/document.1.jpg" style={{ width: '100%', height: 'auto', maxHeight: '500px', borderRadius: "0.25rem", overflow: "hidden", border: '1px solid #E5E4E2' }} /></Frame>
88

99
```jsx
1010
import { Footnote, PageBottom, Tailwind, CSS } from "@fileforge/react-print";

docs/ui/templates/invoice.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ icon: file-invoice
44
category: Invoices
55
---
66

7-
<Frame background="subtle"><img src="../../images/previews/ui-templates-invoice-808342e7/document.1.jpg" style={{ width: '100%', height: 'auto', maxHeight: '500px', borderRadius: "0.25rem", overflow: "hidden", border: '1px solid #E5E4E2' }} /></Frame>
7+
<Frame background="subtle"><img src="../../images/previews/ui-templates-invoice-c1137a92/document.1.jpg" style={{ width: '100%', height: 'auto', maxHeight: '500px', borderRadius: "0.25rem", overflow: "hidden", border: '1px solid #E5E4E2' }} /></Frame>
88

99
```jsx
1010
import { Footnote, PageBottom, Tailwind } from "@fileforge/react-print";

docs/ui/templates/receipt.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ icon: receipt
44
category: Receipts
55
---
66

7-
<Frame background="subtle"><img src="../../images/previews/ui-templates-receipt-4906d507/document.1.jpg" style={{ width: '100%', height: 'auto', maxHeight: '500px', borderRadius: "0.25rem", overflow: "hidden", border: '1px solid #E5E4E2' }} /></Frame>
7+
<Frame background="subtle"><img src="../../images/previews/ui-templates-receipt-644d535a/document.1.jpg" style={{ width: '100%', height: 'auto', maxHeight: '500px', borderRadius: "0.25rem", overflow: "hidden", border: '1px solid #E5E4E2' }} /></Frame>
88

99
```jsx
1010
import { Footnote, Tailwind } from "@fileforge/react-print";

docs/ui/templates/scientific-report.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ icon: flask
44
category: Reports
55
---
66

7-
<Frame background="subtle"><img src="../../images/previews/ui-templates-scientific-report-31829950/document.1.jpg" style={{ width: '100%', height: 'auto', maxHeight: '500px', borderRadius: "0.25rem", overflow: "hidden", border: '1px solid #E5E4E2' }} /></Frame>
7+
<Frame background="subtle"><img src="../../images/previews/ui-templates-scientific-report-7f68dcf5/document.1.jpg" style={{ width: '100%', height: 'auto', maxHeight: '500px', borderRadius: "0.25rem", overflow: "hidden", border: '1px solid #E5E4E2' }} /></Frame>
88

99
```jsx
1010
import React, { createContext, useEffect, useState } from "react";

src/tailwind/tailwind.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55

66
import { DocConfig } from "docgen/types";
77
import React from "react";
8-
import postcss, { Processor } from "postcss";
8+
import postcss from "postcss";
99
// import type { Config as TailwindConfig } from "tailwindcss";
1010
// @ts-ignore
1111
import postcssColorFunctionalNotation from "postcss-color-functional-notation";
1212

13-
import { quickSafeRenderToString } from "./utils.resend";
1413
import type { CorePluginsConfig } from "tailwindcss/types/config";
1514

1615
import { CSS } from "../css/css";
@@ -21,6 +20,7 @@ import { createTailwindcssPlugin } from "@mhsdesign/jit-browser-tailwindcss";
2120

2221
// @ts-ignore
2322
import isPseudoClass from "@csstools/postcss-is-pseudo-class";
23+
import { renderToString } from "react-dom/server";
2424

2525
export const Tailwind = ({
2626
children,
@@ -38,7 +38,15 @@ export const Tailwind = ({
3838
*/
3939
config?: any; // Omit<TailwindConfig, "content">;
4040
}) => {
41-
const markup = quickSafeRenderToString(children);
41+
const markup = renderToString(<>{children}</>);
42+
43+
const classNamesList = (markup.match(/class="([^"]*)"/g) || [])
44+
.map((match) => {
45+
return match.substring(7, match.length - 1).split(" ");
46+
})
47+
.flat();
48+
49+
const classNamesSet = new Set(classNamesList);
4250

4351
const corePlugins = config?.corePlugins as CorePluginsConfig;
4452

@@ -61,7 +69,13 @@ export const Tailwind = ({
6169
const { css } = postcss([
6270
createTailwindcssPlugin({
6371
tailwindConfig,
64-
content: [{ content: markup, extension: "html" }],
72+
content: [
73+
{
74+
content: `<div class="${Array.from(classNamesSet).join(" ")}"
75+
}"></div>`,
76+
extension: "html",
77+
},
78+
],
6579
}),
6680
// postcssCssVariables,
6781
isPseudoClass(),

tests/compile.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ test("works with tailwind", async () => {
2626
expect(html).toContain("rgba(239, 68, 68");
2727
});
2828

29+
test("smoke test tailwind", async () => {
30+
const TestComponent = () => {
31+
return (
32+
<Tailwind>
33+
{Array.from({ length: 1000000 }).map((_, i) => (
34+
<div key={i} className="bg-red-500">
35+
Test
36+
</div>
37+
))}
38+
</Tailwind>
39+
);
40+
};
41+
42+
const html = await compile(<TestComponent />);
43+
44+
expect(html).toContain("rgba(239, 68, 68");
45+
});
46+
2947
test("works with tailwind dark", async () => {
3048
const TestComponent = () => (
3149
<Tailwind

0 commit comments

Comments
 (0)