Skip to content

Commit eb525b0

Browse files
committed
feat: remove ssr styled
1 parent 0fc670e commit eb525b0

File tree

9 files changed

+5
-211
lines changed

9 files changed

+5
-211
lines changed

packages/runtime/plugin-runtime/package.json

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@
6464
"jsnext:source": "./src/exports/head.ts",
6565
"default": "./dist/esm/exports/head.js"
6666
},
67-
"./styled": {
68-
"types": "./dist/types/exports/styled.d.ts",
69-
"jsnext:source": "./src/exports/styled.ts",
70-
"default": "./dist/esm/exports/styled.js"
71-
},
7267
"./server": {
7368
"types": "./dist/types/exports/server.d.ts",
7469
"jsnext:source": "./src/exports/server.ts",
@@ -167,9 +162,6 @@
167162
"head": [
168163
"./dist/types/exports/head.d.ts"
169164
],
170-
"styled": [
171-
"./dist/types/exports/styled.d.ts"
172-
],
173165
"server": [
174166
"./dist/types/exports/server.d.ts"
175167
],
@@ -231,16 +223,14 @@
231223
"@swc/helpers": "^0.5.17",
232224
"@types/loadable__component": "^5.13.10",
233225
"@types/react-helmet": "^6.1.11",
234-
"@types/styled-components": "^5.1.34",
235226
"cookie": "0.7.2",
236227
"es-module-lexer": "^1.1.0",
237228
"esbuild": "0.25.5",
238229
"invariant": "^2.2.4",
239230
"isbot": "3.7.1",
240231
"react-helmet": "^6.1.0",
241232
"react-is": "^18",
242-
"react-side-effect": "^2.1.2",
243-
"styled-components": "^5.3.1"
233+
"react-side-effect": "^2.1.2"
244234
},
245235
"peerDependencies": {
246236
"react": ">=17",

packages/runtime/plugin-runtime/src/core/server/stream/createReadableStream.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { PassThrough, Transform } from 'stream';
1+
import { Transform } from 'stream';
22
import { createReadableStreamFromReadable } from '@modern-js/runtime-utils/node';
33
import checkIsBot from 'isbot';
4-
import { ServerStyleSheet } from 'styled-components';
54
import { ESCAPED_SHELL_STREAM_END_MARK } from '../../../common';
65
import { RenderLevel } from '../../constants';
76
import {
@@ -26,19 +25,13 @@ export const createReadableStreamFromElement: CreateReadableStreamFromElement =
2625
const isbot = checkIsBot(request.headers.get('user-agent'));
2726
const onReady = isbot || forceStream2String ? 'onAllReady' : 'onShellReady';
2827

29-
const sheet = new ServerStyleSheet();
30-
3128
const chunkVec: string[] = [];
3229

33-
const root = sheet.collectStyles(rootElement);
34-
3530
return new Promise(resolve => {
36-
const { pipe: reactStreamingPipe } = renderToPipeableStream(root, {
31+
const { pipe: reactStreamingPipe } = renderToPipeableStream(rootElement, {
3732
nonce: config.nonce,
3833
[onReady]() {
39-
const styledComponentsStyleTags = forceStream2String
40-
? sheet.getStyleTags()
41-
: '';
34+
const styledComponentsStyleTags = '';
4235
options[onReady]?.();
4336

4437
getTemplates(htmlTemplate, {
@@ -90,16 +83,7 @@ export const createReadableStreamFromElement: CreateReadableStreamFromElement =
9083
const stream = createReadableStreamFromReadable(body);
9184
resolve(stream);
9285

93-
// Transform the react pipe to a readable stream
94-
// Actually it's for type check, we even can execute `sheet.interleaveWithNodeStream({ pipe })`
95-
// Source code https://github.com/styled-components/styled-components/blob/main/packages/styled-components/src/models/ServerStyleSheet.tsx#L80
96-
const passThrough = new PassThrough();
97-
const styledStream = sheet.interleaveWithNodeStream(passThrough);
98-
reactStreamingPipe(passThrough);
99-
100-
// pipe the styled stream to the body stream
101-
// now only use styled stream, if there is multiple stream, we can abstract it to a function
102-
styledStream.pipe(body);
86+
reactStreamingPipe(body);
10387
});
10488
},
10589

packages/runtime/plugin-runtime/src/core/server/string/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { getSSRConfigByEntry, safeReplace } from '../utils';
1818
import { LoadableCollector } from './loadable';
1919
import { prefetch } from './prefetch';
2020
import { SSRDataCollector } from './ssrData';
21-
import { StyledCollector } from './styledComponent';
2221
import type { ChunkSet, Collector } from './types';
2322

2423
export const renderString: RenderString = async (
@@ -64,7 +63,6 @@ export const renderString: RenderString = async (
6463
}
6564

6665
const collectors = [
67-
new StyledCollector(chunkSet),
6866
new LoadableCollector({
6967
stats: loadableStats,
7068
nonce: config.nonce,

packages/runtime/plugin-runtime/src/core/server/string/styledComponent.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/runtime/plugin-runtime/src/exports/styled.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/runtime/plugin-runtime/tests/ssr/__snapshots__/renderString.test.ts.snap

Lines changed: 0 additions & 28 deletions
This file was deleted.

packages/runtime/plugin-runtime/tests/ssr/fixtures/string-ssr/App.tsx

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/runtime/plugin-runtime/tests/ssr/renderString.test.ts

Lines changed: 0 additions & 85 deletions
This file was deleted.

pnpm-lock.yaml

Lines changed: 0 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)