Skip to content

Commit

Permalink
Revert getStaticData to only return Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Feb 7, 2020
1 parent a642f61 commit d56c583
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions packages/next/next-server/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,25 +526,18 @@ export default class Router implements BaseRouter {
return routeInfo
}

// if we have data in cache resolve with the data
// if not we we resolve with fallback routeInfo

// resolve with fallback routeInfo and promise for data
if (isSSG || isSSP) {
const dataRes = isSSG
? this._getStaticData(as)
: this._getServerData(as)

return Promise.resolve(
typeof dataRes.then !== 'function'
? handleData(dataRes)
: {
...routeInfo,
props: {},
dataRes: this._getData(() =>
dataRes.then((props: any) => handleData(props))
),
}
)
return Promise.resolve({
...routeInfo,
props: {},
dataRes: this._getData(() =>
(isSSG
? this._getStaticData(as)
: this._getServerData(as)
).then((props: any) => handleData(props))
),
})
}

return this._getData<RouteInfo>(() =>
Expand Down Expand Up @@ -755,11 +748,11 @@ export default class Router implements BaseRouter {
})
}

_getStaticData = (asPath: string): Promise<object> | any => {
_getStaticData = (asPath: string): Promise<object> => {
const pathname = prepareRoute(parse(asPath).pathname!)

return process.env.NODE_ENV === 'production' && this.sdc[pathname]
? this.sdc[pathname]
? Promise.resolve(this.sdc[pathname])
: fetchNextData(pathname, null, data => (this.sdc[pathname] = data))
}

Expand Down

0 comments on commit d56c583

Please sign in to comment.