Skip to content

Commit 632b9c2

Browse files
author
Kalle Ott
committed
fix: make sure react-dom/server is not imported in client bundle
BREAKING: createSpriteSheetString and renderSpriteSheetToString have to be imported from "react-lazy-svg/dist/ssr"
1 parent 76dec56 commit 632b9c2

22 files changed

+3962
-3603
lines changed

.eslintrc.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es6: true,
5+
node: true,
6+
},
7+
extends: [
8+
'plugin:react/recommended',
9+
'plugin:@typescript-eslint/eslint-recommended',
10+
'prettier',
11+
'plugin:react-hooks/recommended',
12+
],
13+
globals: {
14+
Atomics: 'readonly',
15+
SharedArrayBuffer: 'readonly',
16+
},
17+
parser: '@typescript-eslint/parser',
18+
parserOptions: {
19+
ecmaFeatures: {
20+
jsx: true,
21+
},
22+
ecmaVersion: 2018,
23+
sourceType: 'module',
24+
},
25+
plugins: ['react', '@typescript-eslint'],
26+
rules: {
27+
'react/prop-types': 0,
28+
},
29+
};

.github/workflows/test.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,30 @@ name: Node.js Package
33
on: push
44

55
jobs:
6-
build:
6+
test:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v2
1010
- uses: actions/setup-node@v1
1111
with:
12-
node-version: 12
12+
node-version: 14
1313
- run: yarn --pure-lockfile
1414
- run: yarn test
15+
lint:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- uses: actions/setup-node@v1
20+
with:
21+
node-version: 14
22+
- run: yarn --pure-lockfile
23+
- run: yarn lint
24+
build:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v2
28+
- uses: actions/setup-node@v1
29+
with:
30+
node-version: 14
31+
- run: yarn --pure-lockfile
32+
- run: yarn build

.husky/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
<p align="center" style="color: #343a40">
2-
<icon style="font-size:100px;" alt="sloth emoji">🦥</icon>
3-
<h1 align="center">react-lazy-svg</h1>
4-
</p>
1+
<p align="center"><img alt="sloth emoji" src="https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/160/apple/271/sloth_1f9a5.png" /></p>
2+
3+
<h1 align="center">react-lazy-svg</h1>
54
<p align="center" style="font-size: 1.2rem;">The easy way to use SVG sprite-sheets</p>
65

76
react-lazy-svg is a simple way to use SVGs with the performance benefits of a

babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', { targets: { node: 'current' } }],
4+
'@babel/preset-typescript',
5+
],
6+
};

example/package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@
99
"start:prod": "NODE_ENV=production node build/server.js"
1010
},
1111
"dependencies": {
12-
"fastify": "^2.15.1",
13-
"fastify-static": "^2.7.0",
14-
"razzle": "^3.1.3",
15-
"razzle-plugin-typescript": "^3.1.3",
12+
"fastify": "^3.13.0",
13+
"fastify-static": "^4.0.1",
14+
"razzle": "^3.3.13",
15+
"razzle-plugin-typescript": "^3.3.13",
1616
"react": "link:../node_modules/react",
1717
"react-dom": "link:../node_modules/react-dom",
1818
"react-lazy-svg": "link:../"
1919
},
2020
"devDependencies": {
21-
"@types/node": "^14.0.9",
21+
"@types/node": "^14.14.32",
2222
"@types/react": "link:../node_modules/@types/react",
2323
"@types/react-dom": "link:../node_modules/@types/react-dom",
24-
"@types/webpack-env": "^1.15.2",
25-
"tslint": "^6.1.2",
26-
"typescript": "^3.9.3"
24+
"@types/webpack-env": "^1.16.0",
25+
"typescript": "^4.2.3"
2726
}
2827
}

example/razzle.config.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
module.exports = {
2-
plugins: ['typescript'],
2+
plugins: [
3+
{
4+
name: 'typescript',
5+
options: {
6+
forkTsChecker: {
7+
tsconfig: './tsconfig.json',
8+
tslint: undefined,
9+
watch: './src',
10+
typeCheck: true,
11+
},
12+
},
13+
},
14+
],
315
};

example/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import app from './server';
22

3-
app.listen(5001, 'localhost', function(err, address) {
3+
app.listen(5001, 'localhost', function (err, address) {
44
if (err) {
5-
app.log.error(err);
5+
app.log.error(err.message, err);
66
process.exit(1);
77
}
88
app.log.info(`server listening on ${address}!`);

example/src/server.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ import React from 'react';
33
import fastify from 'fastify';
44
import { renderToString } from 'react-dom/server';
55
import fastifyStatic from 'fastify-static';
6-
import {
7-
SpriteContextProvider,
8-
IconsCache,
9-
createSpriteSheetString,
10-
} from 'react-lazy-svg';
6+
import { SpriteContextProvider, IconsCache } from 'react-lazy-svg';
7+
import { createSpriteSheetString } from 'react-lazy-svg/dist/ssr';
118
import { readSvg } from './serverLoadSvg';
129

1310
const assets = require(process.env.RAZZLE_ASSETS_MANIFEST!);

example/src/serverLoadSvg.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const readSvg = async (url: string) => {
1515
if (url.startsWith(cdnBase)) {
1616
url = path.join(
1717
process.cwd(),
18-
url.replace(cdnBase, './build/public/static/media/')
18+
url.replace(cdnBase, './build/public/static/media/'),
1919
);
2020
}
2121

0 commit comments

Comments
 (0)