Skip to content

Commit 2324627

Browse files
committed
fix: fix some bug
1 parent 51cc3c1 commit 2324627

File tree

9 files changed

+19
-22
lines changed

9 files changed

+19
-22
lines changed

build/client/webpack.base.conf.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ module.exports = {
8989
new webpack.DefinePlugin({
9090
'process.env': JSON.stringify({ NODE_ENV: 'development' }),
9191
__IS_PROD__: false,
92-
__SERVER__: false
92+
__SERVER__: false,
93+
__IS_WEBPACK__: true
9394
})
9495
],
9596
optimization: {

src/client/main/route-config.tsx

+9-11
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,26 @@ export interface IRoute {
88

99
let routes: IRoute[] = []
1010

11-
// 这种不能被做到热更新 那么应该reload啊
12-
// todo 这里有bug
11+
// TODO 不支持热更新
1312
function pageNotFound({ staticContext }: any) {
1413
if (staticContext) {
1514
staticContext.code = 404
1615
}
1716

1817
return (
1918
<div>
20-
<p>404页面page22</p>
21-
<p>12</p>
19+
<p>404页面</p>
2220
</div>
2321
)
2422
}
2523
try {
26-
// if (require.context) {
27-
const context = require.context(`../modules`, true, /.*\/routes\.tsx?$/)
28-
context.keys().forEach((key: string) => {
29-
const route = context(key).default
30-
routes = routes.concat(route)
31-
})
32-
// }
24+
if (__IS_WEBPACK__) {
25+
const context = require.context(`../modules`, true, /.*\/routes\.tsx?$/)
26+
context.keys().forEach((key: string) => {
27+
const route = context(key).default
28+
routes = routes.concat(route)
29+
})
30+
}
3331
} catch (err) {
3432
console.warn(err.message)
3533
}

src/client/types/lib.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ declare module 'isomorphic-style-loader/withStyles'
2424
declare const __SERVER__: boolean
2525

2626
declare const __IS_PROD__: boolean
27+
28+
declare const __IS_WEBPACK__: boolean

src/server/middlewares/ssr.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default async (ctx: Koa.Context, next: Koa.Next): Promise<null> => {
2626
keywords: '默认关键词',
2727
description: '默认描述'
2828
}
29+
// 添加TDK
2930
if (page && page.tdk) {
3031
tdk = page.tdk
3132
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`test genHtml Function should return the correct result when call genHtml 1`] = `"<div class=\\"layout-box\\"><h1>koa+react+ssr</h1><div><p>404页面page22</p><p>12</p></div></div>"`;
3+
exports[`test genHtml Function should return the correct result when call genHtml 1`] = `"<div class=\\"layout-box\\"><div><p>404页面</p></div></div>"`;

tests/components/asyncBundle.spec.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('test AsyncBundle component', () => {
2525
const { rerender } = render(
2626
<AsyncBundle load={() => loader}>{Comp => <Comp />}</AsyncBundle>
2727
)
28+
// TODO 这段测试写的不标准 rerender不是这么用的 不是跟enzyme的update方法一样的理解
2829
await rerender(<AsyncBundle load={() => loader}>{Comp => <Comp />}</AsyncBundle>)
2930
const element = screen.getByText('component')
3031
expect(element).toBeInTheDocument()

tests/demo.spec.js

-6
This file was deleted.

tests/genHtml.spec.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ describe('test genHtml Function', () => {
88
console.log('insertCss')
99
}
1010
const { html } = await genHtml('/404', insertCss, store)
11-
expect(html).toMatch(
12-
`<div class="layout-box"><h1>koa+react+ssr</h1><div><p>404页面page22</p><p>12</p></div></div>`
13-
)
11+
expect(html).toMatch(`<div class="layout-box"><div><p>404页面</p></div></div>`)
1412
expect(html).toMatchSnapshot() // 保存快照
1513
})
1614
})

tests/setupTests.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ import '@testing-library/jest-dom'
33
import React from 'react'
44
// 处理这种情况 https://stackoverflow.com/questions/58070996/how-to-fix-the-warning-uselayouteffect-does-nothing-on-the-server
55
React.useLayoutEffect = React.useEffect
6+
// 模拟非__IS_WEBPACK环境
7+
global.__IS_WEBPACK__ = false

0 commit comments

Comments
 (0)