Skip to content

Commit

Permalink
fix: pass shared data params to 'getInitailProps'
Browse files Browse the repository at this point in the history
  • Loading branch information
front-end-captain committed May 15, 2021
1 parent 2c9d182 commit b0e1cd7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
Expand Up @@ -42,6 +42,7 @@ export function injectPreparerComponentProps(WrappedComponent: ComponentType<any
}

async componentDidMount() {
window.__SHARED_DATA__ = window.__SHARED_DATA__ || {};
this.setState({ loading: null });

if (!window.__USE_SSR__) {
Expand All @@ -62,7 +63,7 @@ export function injectPreparerComponentProps(WrappedComponent: ComponentType<any
params: {},
query: query,
url: window.location.pathname,
})
}, window.__SHARED_DATA__)
: {};

this.setState({
Expand Down
Expand Up @@ -49,6 +49,7 @@ export function injectRouteComponentProps(
}

async componentDidMount() {
window.__SHARED_DATA__ = {};
this.setState({ loading: null });

if ((this.props.history && this.props.history.action !== "POP") || !window.__USE_SSR__) {
Expand All @@ -73,7 +74,7 @@ export function injectRouteComponentProps(
params: this.props.match.params,
query,
url: this.props.location.pathname,
})
}, window.__SHARED_DATA__)
: {};

this.setState({
Expand Down
Expand Up @@ -88,6 +88,7 @@ async function serverRender(
basename: entry.route.basename,
};

// @ts-ignore
let preparerProps = {};

let App = <StaticRouter {...staticRouterProps} context={staticRouterContext} />;
Expand All @@ -105,7 +106,7 @@ async function serverRender(
// @ts-ignore
store,
query: context.query,
});
}, shared);
}
<%_ } _%>

Expand All @@ -117,7 +118,6 @@ async function serverRender(
App = (
<StaticRouter {...staticRouterProps} context={staticRouterContext}>
<Layout
{...wrapperInitProps}
// @ts-ignore
location={staticRouterContext.location}
matchedRouteList={matchedRouteList}
Expand All @@ -139,7 +139,6 @@ async function serverRender(
App = (
<StaticRouter {...staticRouterProps} context={staticRouterContext}>
<Layout
{...wrapperInitProps}
// @ts-ignore
location={staticRouterContext.location}
matchedRouteList={matchedRouteList}
Expand Down Expand Up @@ -178,7 +177,7 @@ async function serverRender(
App = (
<StaticRouter {...staticRouterProps} context={staticRouterContext}>
<Layout
{...wrapperInitProps}
{...initProps}
// @ts-ignore
location={staticRouterContext.location}
matchedRouteList={matchedRouteList}
Expand Down
Expand Up @@ -2,6 +2,7 @@ interface Window {
__USE_SSR__?: boolean;
__INITIAL_DATA__?: any;
__INITIAL_STATE__?: any;
__SHARED_DATA__: any,
}

declare const __IS_BROWSER__: boolean | undefined;
Expand Down

0 comments on commit b0e1cd7

Please sign in to comment.