Skip to content

Commit

Permalink
Merge pull request #240 from cmux/0.13
Browse files Browse the repository at this point in the history
fix SSR store purging issue
  • Loading branch information
Diablohu authored Apr 15, 2020
2 parents cc7e767 + f526c9b commit 67fd410
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## [Unreleased]

## [0.13.16] - 2020-04-16

**koot**

- 优化
- 优化 SSR _Store_ 处理

## [0.13.15] - 2020-04-15

**koot**
Expand Down
33 changes: 21 additions & 12 deletions packages/koot/ReactApp/server/middlewares/isomorphic/ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ const ssr = (ctx) =>
if (__DEV__) return resolve(result);

// setTimeout(function () {
for (const key of Object.keys(thisContext).filter(
(key) => key !== 'global' && key !== KOAContext
))
delete thisContext[key];
purgeObject(thisContext.global);
delete thisContext.global;
// delete thisContext[KOAContext]
if (thisContext && typeof thisContext === 'object') {
for (const key of Object.keys(thisContext).filter(
(key) => key !== 'global' && key !== KOAContext
))
delete thisContext[key];
purgeObject(thisContext.global);
delete thisContext.global;
// delete thisContext[KOAContext]
}
thisContext = undefined;
purgeSSRContext(ctx);

Expand Down Expand Up @@ -199,13 +201,20 @@ const purgeSSRContext = (ctx) => {
if (typeof ctx[SSRContext] === 'object') {
purgeObject(ctx[SSRContext].connectedComponents);
purgeObject(ctx[SSRContext].History);
purgeObject(ctx[SSRContext].Store);
if (typeof ctx[SSRContext].Store === 'object') {
delete ctx[SSRContext].Store['Symbol(observable)'];
}
// purgeObject(ctx[SSRContext].Store);
purgeObject(ctx[SSRContext].styleMap);
purgeObject(ctx[SSRContext].template);

// store
if (typeof ctx[SSRContext].Store === 'object') {
// delete ctx[SSRContext].Store['Symbol(observable)'];
let state = ctx[SSRContext].Store.getState();
purgeObject(state);
state = undefined;
for (const key of Object.keys(ctx[SSRContext].Store))
delete ctx[SSRContext].Store[key];
}

for (const key of Object.keys(ctx[SSRContext]))
delete ctx[SSRContext][key];
}
Expand All @@ -216,7 +225,7 @@ const purgeSSRContext = (ctx) => {
};

const purgeObject = (obj) => {
if (typeof obj !== 'object') return;
if (!obj || typeof obj !== 'object') return;
for (const key of Object.keys(obj)) {
if (typeof obj[key] === 'object') purgeObject(obj[key]);
delete obj[key];
Expand Down
3 changes: 1 addition & 2 deletions test/projects/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"private": true,
"sideEffects": false,
"koot": {
"version": "0.13.14"
"version": "0.13.15"
},
"devDependencies": {
"@types/inquirer": "^6.5.0",
Expand Down Expand Up @@ -111,7 +111,6 @@
"sync-request": "^6.1.0",
"terminate": "^2.1.2",
"typescript": "^3.8.3",
"vm2": "^3.9.1",
"xmlify": "^1.1.0",
"yargs": "^15.3.1",
"@babel/core": "^7.8.7",
Expand Down
3 changes: 1 addition & 2 deletions test/projects/standard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"private": true,
"sideEffects": false,
"koot": {
"version": "0.13.14"
"version": "0.13.15"
},
"devDependencies": {
"@types/inquirer": "^6.5.0",
Expand Down Expand Up @@ -135,7 +135,6 @@
"sync-request": "^6.1.0",
"terminate": "^2.1.2",
"typescript": "^3.8.3",
"vm2": "^3.9.1",
"xmlify": "^1.1.0",
"yargs": "^15.3.1",
"@babel/core": "^7.8.7",
Expand Down

0 comments on commit 67fd410

Please sign in to comment.