Skip to content

Commit e1d02a5

Browse files
committedMay 7, 2024
Fix importing icons when using Next.js SSG/SSR, for real this time.
1 parent 60706c2 commit e1d02a5

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed
 

‎generate-module.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ function checkNameClashes (icons) {
4848
fse.mkdirpSync(path.join(__dirname, 'package', 'esm', 'light'))
4949

5050
for (const { name, filename, svgPath } of icons) {
51-
const code = `import createIcon from './util/createIcon'
52-
export default createIcon('${svgPath}', '${name}')
53-
`
51+
const code = `
52+
"use client";
53+
import createIcon from './util/createIcon'
54+
export default createIcon('${svgPath}', '${name}')
55+
`
5456

5557
// es module
5658
fse.writeFileSync(path.join(__dirname, 'package', 'esm', `${filename || name}.js`), babel.transform(code, {
@@ -70,9 +72,11 @@ function checkNameClashes (icons) {
7072
}
7173

7274
for (const { name, filename, svgPath } of lightIcons) {
73-
const code = `import createIcon from '../util/createIcon'
74-
export default createIcon('${svgPath}', '${name}')
75-
`
75+
const code = `
76+
"use client";
77+
import createIcon from '../util/createIcon'
78+
export default createIcon('${svgPath}', '${name}')
79+
`
7680

7781
// es module
7882
fse.writeFileSync(path.join(__dirname, 'package', 'esm', 'light', `${filename || name}.js`), babel.transform(code, {

‎src/util/createIcon.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"use client";
21
import { createSvgIcon } from "@mui/material/utils";
32

43
export default (path, name) => createSvgIcon(<path d={path} />, name);

0 commit comments

Comments
 (0)
Please sign in to comment.