Skip to content

Commit 624e7bc

Browse files
perf(overmind): improve SSR by not evaluating actions
1 parent e1dbf16 commit 624e7bc

File tree

1 file changed

+14
-5
lines changed
  • packages/node_modules/overmind/src

1 file changed

+14
-5
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,11 @@ export class Overmind<ThisConfig extends IConfiguration>
224224
Create the proxy state tree instance with the state and a wrapper to expose
225225
the eventHub
226226
*/
227-
const proxyStateTree = this.createProxyStateTree(configuration, eventHub)
227+
const proxyStateTree = this.createProxyStateTree(
228+
configuration,
229+
eventHub,
230+
mode.mode === MODE_SSR ? false : IS_DEVELOPMENT
231+
)
228232

229233
this.originalConfiguration = configuration
230234
this.state = proxyStateTree.state
@@ -234,6 +238,10 @@ export class Overmind<ThisConfig extends IConfiguration>
234238
this.options = options
235239
this.mode = mode
236240

241+
if (mode.mode === MODE_SSR) {
242+
return
243+
}
244+
237245
if (
238246
IS_DEVELOPMENT &&
239247
mode.mode === MODE_DEFAULT &&
@@ -282,7 +290,7 @@ export class Overmind<ThisConfig extends IConfiguration>
282290
}
283291
}
284292

285-
if (IS_PRODUCTION) {
293+
if (IS_PRODUCTION && mode.mode === MODE_DEFAULT) {
286294
eventHub.on(EventType.OPERATOR_ASYNC, () => {
287295
proxyStateTree.getMutationTree().flush()
288296
})
@@ -345,14 +353,15 @@ export class Overmind<ThisConfig extends IConfiguration>
345353
}
346354
private createProxyStateTree(
347355
configuration: IConfiguration,
348-
eventHub: EventEmitter<any> | MockedEventEmitter
356+
eventHub: EventEmitter<any> | MockedEventEmitter,
357+
devmode: boolean
349358
) {
350359
const proxyStateTree = new ProxyStateTree(
351360
this.getState(configuration) as any,
352361
{
353-
devmode: IS_DEVELOPMENT,
362+
devmode,
354363
dynamicWrapper: (_, path, func) => func(eventHub, proxyStateTree, path),
355-
onGetter: IS_DEVELOPMENT
364+
onGetter: devmode
356365
? (path, value) => {
357366
// We need to let any initial values be set first
358367
setTimeout(() => {

0 commit comments

Comments
 (0)