Skip to content

Commit

Permalink
refactor: Use serialize-javascript (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
isaachinman authored Feb 21, 2021
1 parent cbbdd8a commit ce3ca48
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
"i18next": "^19.8.4",
"i18next-fs-backend": "^1.0.7",
"i18next-http-backend": "^1.0.21",
"react-i18next": "^11.7.3"
"react-i18next": "^11.7.3",
"serialize-javascript": "^5.0.1"
},
"peerDependencies": {
"next": ">= 9.5.0",
Expand Down
4 changes: 3 additions & 1 deletion src/appWithTranslation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ export const appWithTranslation = <P extends Record<string, unknown>>(WrappedCom
userConfig,
} = props.pageProps._nextI18Next

const parsedUserConfig = Function(`'use strict';return(${userConfig})`)()

locale = initialLocale;

({ i18n } = createClient({
...createConfig({
...userConfig,
...parsedUserConfig,
lng: initialLocale,
}),
lng: initialLocale,
Expand Down
3 changes: 2 additions & 1 deletion src/serverSideTranslations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs'
import serialize from 'serialize-javascript'
import path from 'path'

import { createConfig } from './config/createConfig'
Expand Down Expand Up @@ -43,7 +44,7 @@ export const serverSideTranslations = async (
_nextI18Next: {
initialI18nStore,
initialLocale,
userConfig,
userConfig: serialize(userConfig),
}
}
}
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7300,6 +7300,13 @@ serialize-javascript@^4.0.0:
dependencies:
randombytes "^2.1.0"

serialize-javascript@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-5.0.1.tgz#7886ec848049a462467a97d3d918ebb2aaf934f4"
integrity sha512-SaaNal9imEO737H2c05Og0/8LUXG7EnsZyMa8MzkmuHoELfT6txuj0cMqRj6zfPKnmQ1yasR4PCJc8x+M4JSPA==
dependencies:
randombytes "^2.1.0"

set-blocking@^2.0.0, set-blocking@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
Expand Down

0 comments on commit ce3ca48

Please sign in to comment.