Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use initImmediate in SSR #461

Merged
merged 1 commit into from Aug 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions __tests__/config/create-config.test.ts
Expand Up @@ -48,6 +48,7 @@ describe('create configuration in non-production environment', () => {
})

it('creates default non-production configuration', () => {
isServer.mockReturnValue(true)
const config = createConfig({})

expect(config.defaultLanguage).toEqual('en')
Expand All @@ -72,6 +73,8 @@ describe('create configuration in non-production environment', () => {

expect(config.react.wait).toEqual(true)

expect(config.initImmediate).toEqual(false)

expect(config.preload).toEqual(['en'])

expect(config.ns).toEqual(['common', 'file1', 'file2'])
Expand Down Expand Up @@ -161,6 +164,8 @@ describe('create configuration in non-production environment', () => {

expect(config.react.wait).toEqual(true)

expect(config.initImmediate).toEqual(true)

expect(config.preload).toBeUndefined()

expect(config.ns).toEqual(['common'])
Expand Down
1 change: 1 addition & 0 deletions __tests__/middlewares/next-i18next-middleware.test.ts
Expand Up @@ -23,6 +23,7 @@ jest.mock('../../src/utils', () => ({
subpathFromLng: jest.fn(),
lngFromReq: jest.fn(),
removeSubpath: jest.fn(),
isServer: jest.fn(),
}))

describe('next-18next middleware', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/config/default-config.ts
@@ -1,3 +1,5 @@
import { isServer } from '../utils'

const DEFAULT_LANGUAGE = 'en'
const OTHER_LANGUAGES = []
const DEFAULT_NAMESPACE = 'common'
Expand Down Expand Up @@ -35,6 +37,9 @@ const config = {
},
strictMode: true,
errorStackTraceLimit: 0,
get initImmediate() {
return !isServer()
}
}

export default config
1 change: 1 addition & 0 deletions tsconfig.json
Expand Up @@ -3,6 +3,7 @@
"esModuleInterop": true,
"noEmit": true,
"lib": ["esnext", "dom"],
"target": "es5",
"jsx": "react"
},
"include": [
Expand Down