Skip to content

Commit

Permalink
Merge pull request #2 from AhaOfficial/develop
Browse files Browse the repository at this point in the history
fix: SSR 시 class 내에서 다른 store 의 참조 오류 문제 수정
  • Loading branch information
hm-lee committed Feb 25, 2021
2 parents 33d9150 + 53e407b commit df41572
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<br/>

<center><b>📮 넥스트 틀 버전:</b> 2021-Apeach-1.0.0</center>
<center><b>📮 넥스트 틀 버전:</b> 2021-Apeach-1.0.1</center>

<br/>
<br/>
Expand Down
2 changes: 1 addition & 1 deletion core/universal-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export const useSSR = async <
const pagePrefetcher = (appContext.Component as any).onPrefetch
if (typeof pagePrefetcher !== 'undefined') await pagePrefetcher(appContext)

return process.browser ? stores : makeStateJSON(stores)
return stores
}

/**
Expand Down
4 changes: 2 additions & 2 deletions interfaces/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export type ServiceContext = AppContext & {
ctx: ServicePageContext
}

export interface IUser {
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface IUser {}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-template",
"version": "1.0.0",
"version": "1.0.1",
"scripts": {
"dev": "BROWSERSLIST_IGNORE_OLD_DATA=true next -p 3000",
"build": "BROWSERSLIST_IGNORE_OLD_DATA=true next build",
Expand Down
7 changes: 5 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { observer } from 'mobx-react'

// * 서비스 관련 파일들을 불러옵니다.
import Stores from 'stores'
import { StoreProvider, useSSR } from 'core/universal-state'
import { makeStateJSON, StoreProvider, useSSR } from 'core/universal-state'
import LayoutDefault from 'components/layouts/Default'
import Favicon from 'components/head/Favicon'
import nextSeoConfig from 'next-seo.config'
Expand Down Expand Up @@ -110,11 +110,14 @@ const Page = observer(({ Component, pageProps }) => {
*/
App.getInitialProps = async (context) => {
// 매 서버 요청마다 상태 저장소 정보를 별도로 구성합니다.
const stateJSON = await useSSR(context, Stores)
let stateJSON = await useSSR(context, Stores)

// 기존 getInitialProps 를 실행합니다.
const appProps = await NextApp.getInitialProps(context)

// JSON 내 순환 참조를 방지합니다.
if (!process.browser) stateJSON = makeStateJSON(stateJSON)

return { ...appProps, stateJSON } as AppInitialProps
}

Expand Down

0 comments on commit df41572

Please sign in to comment.