Skip to content

Commit

Permalink
fix: prevent loading translations on each request (#1000)
Browse files Browse the repository at this point in the history
* prevent loading translations on each request

* remove debug flag

* keep just 1 i18next instance in memory on server side

* reformat if statement
  • Loading branch information
adrai authored Mar 10, 2021
1 parent dfd9244 commit e7c5fad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/createClient/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const config = {
use: [],
} as any

describe('createClientBrowser', () => {
describe('createClientNode', () => {
it('returns a node client', () => {
const client = createClientNode(config)
expect(typeof client.initPromise.then).toEqual('function')
Expand Down
8 changes: 6 additions & 2 deletions src/createClient/node.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import i18n from 'i18next'
import i18nextFSBackend from 'i18next-fs-backend'

import { InternalConfig, CreateClientReturn, InitPromise } from '../types'
import { InternalConfig, CreateClientReturn, InitPromise, I18n } from '../types'

let instance: I18n

export default (config: InternalConfig): CreateClientReturn => {
const instance = i18n.createInstance(config)
if (!instance) {
instance = i18n.createInstance(config)
}
let initPromise: InitPromise

if (!instance.isInitialized) {
Expand Down

1 comment on commit e7c5fad

@vercel
Copy link

@vercel vercel bot commented on e7c5fad Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.