Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit f9f872a

Browse files
committed
feat(build): use dynamic rendering and remove ssr
1 parent 9deaab6 commit f9f872a

File tree

19 files changed

+474
-871
lines changed

19 files changed

+474
-871
lines changed

packages/client/assets/style/code.css

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@import './variable';
2+
@import url('https://fonts.googleapis.com/css?family=Source+Code+Pro');
3+
4+
pre {
5+
background: var(--color-white);
6+
border-radius: 10px;
7+
min-width: 50%;
8+
max-width: 90%;
9+
width: auto;
10+
}
11+
12+
code {
13+
font-family: 'Source Code Pro', monospace;
14+
}
15+
16+
section {
17+
& > pre[class*='language-'] {
18+
margin: 0.5em auto;
19+
20+
& > code[class*='language-'] {
21+
& .token.operator {
22+
background: inherit;
23+
}
24+
}
25+
}
26+
}
27+
28+
section > pre > code[class*='language-'],
29+
section > pre[class*='language-'] {
30+
font-size: 1.4rem;
31+
line-height: 1.2;
32+
}
33+
34+
@media screen and (min-width: 768px) {
35+
section > pre > code[class*='language-'],
36+
section > pre[class*='language-'] {
37+
font-size: 2rem;
38+
}
39+
}

packages/client/assets/style/common.css

+2-37
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@import './variable';
22
@import './sidebar.css';
3-
@import url('https://fonts.googleapis.com/css?family=Source+Code+Pro'); /* for highlight.js */
43

54
html {
65
font-size: 62.5%;
@@ -31,39 +30,6 @@ img {
3130
margin: 0 auto;
3231
}
3332

34-
pre {
35-
background: var(--color-white);
36-
border-radius: 10px;
37-
min-width: 50%;
38-
max-width: 90%;
39-
width: auto;
40-
}
41-
42-
pre[class*='language-'] {
43-
margin: 0.5em auto;
44-
}
45-
46-
code {
47-
font-family: 'Source Code Pro', monospace !important;
48-
padding: 0 3px;
49-
}
50-
51-
code[class*='language-'],
52-
pre[class*='language-'] {
53-
font-size: 1.4rem;
54-
line-height: 1.2;
55-
}
56-
@media screen and (min-width: 768px) {
57-
code[class*='language-'],
58-
pre[class*='language-'] {
59-
font-size: 2rem;
60-
}
61-
}
62-
63-
#root {
64-
display: flex;
65-
}
66-
6733
.fa-hatena:before {
6834
content: 'B!';
6935
font-family: Verdana;
@@ -74,9 +40,8 @@ pre[class*='language-'] {
7440
background: transparent;
7541
}
7642

77-
/* overwrite prismjs */
78-
.token.operator {
79-
background: inherit;
43+
#root {
44+
display: flex;
8045
}
8146

8247
#webslides {

packages/client/src/components/ContentView/Base.js

+17-35
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { useEffect, memo } from 'react';
2-
import Prism from 'prismjs';
32
import classnames from 'classnames';
43
import { setup as setupWebSlides } from '../../setup/webSlides';
54
import { createVMEnv } from '../../utils/createVMEnv';
5+
import { getSearchParams } from '../../utils/getSearchParams';
66

77
const articleClass = process.env.IS_VERTICAL ? 'vertical' : undefined;
88
let mermaid = null;
@@ -21,47 +21,30 @@ async function setupMermaid() {
2121
}
2222

2323
export const Base = memo(
24-
({ slides, onChangeSlideIndex, hash, isJumpPage, showIndex }) => {
25-
// for SSR
26-
if (process.env.NODE_ENV !== 'production') {
24+
({ slides, onChangeSlideIndex, hash, showIndex }) => {
25+
if (import.meta.webpackHot) {
2726
useEffect(() => {
28-
if (process.env.CHART) {
29-
reloadChart();
30-
}
27+
(async () => {
28+
const { Prism } = await import(/* webpackPreload: true */ '../../setup/prism');
3129

32-
Prism.highlightAll();
30+
if (process.env.CHART) {
31+
reloadChart();
32+
}
33+
Prism.highlightAll();
34+
})();
3335
}, [hash]);
3436
}
3537

36-
// useEffect is called too late
37-
// delay Event Loop one round
38-
// but on Node.js this line is an error, so put it in useEffect
39-
if (process.env.BUILD_STAGE !== 'ssr') {
40-
// 0 page
41-
if (process.env.SSR && !isJumpPage) {
42-
setupSlides();
43-
Prism.highlightAll();
44-
} else {
45-
setTimeout(() => {
46-
setupSlides();
47-
Prism.highlightAll();
48-
}, 0);
49-
}
50-
51-
const hasExecutableCode = slides.some(
52-
({ fusumaProps }) => fusumaProps.hasExecutableCode === 'true'
53-
);
38+
useEffect(() => {
39+
setupSlides();
5440

55-
if (hasExecutableCode) {
56-
createVMEnv();
41+
if (!getSearchParams().get('ssr')) {
42+
// don't run when creating html
43+
import(/* webpackPreload: true */ '../../setup/prism');
5744
}
58-
}
59-
60-
useEffect(() => {
61-
if (process.env.SSR) {
62-
setupSlides();
45+
if (slides.some(({ fusumaProps }) => !!fusumaProps.hasExecutableCode)) {
46+
createVMEnv();
6347
}
64-
6548
if (process.env.CHART && !mermaid) {
6649
setupMermaid();
6750
}
@@ -76,7 +59,6 @@ export const Base = memo(
7659
if (process.env.CHART) {
7760
reloadChart();
7861
}
79-
8062
if (onChangeSlideIndex) {
8163
onChangeSlideIndex(e.detail.currentSlide0);
8264
}

packages/client/src/entryPoints/Client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AppContainer } from '../components/AppContainer';
66
import '../setup/css';
77

88
function createBody(slides = [], hash = 0) {
9-
const renderMethod = module.hot ? render : hydrate;
9+
const renderMethod = import.meta.webpackHot ? render : hydrate;
1010

1111
renderMethod(<AppContainer slides={slides} hash={hash} />, document.getElementById('root'));
1212
}

packages/client/src/entryPoints/Server.js

-27
This file was deleted.

packages/client/src/hooks/useContentComponent.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { useEffect, useState } from 'react';
22
import { Base } from '../components/ContentView/Base';
33

44
export function useContentComponent(mode) {
5-
// need to set the default value for SSR
6-
const [ContentComponent, setContentComponent] = useState(mode === 'common' ? Base : null);
5+
const [ContentComponent, setContentComponent] = useState(null);
76

87
useEffect(() => {
98
(async () => {

packages/client/src/setup/prism.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Prism from 'prismjs';
2+
import '../../assets/style/code.css';
3+
4+
Prism.highlightAll();
5+
6+
export { Prism };

0 commit comments

Comments
 (0)