Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: not call getInitialProps method #5398

Merged
merged 1 commit into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions examples/with-prerender-spa/src/pages/About/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import React from 'react';
import { useParams } from 'ice';

function About() {
function About(props) {
const { name } = props;
const { id } = useParams();

return (
<h2>About {id}</h2>
<h2>About {name} {id}</h2>
);
}

About.getStaticPaths = async () => {
return await Promise.resolve(['/about/a', '/about/b', '/about/c']);
};

About.getInitialProps = async () => {
return {
name: 'Jack',
};
};

export default About;
3 changes: 2 additions & 1 deletion packages/plugin-ice-ssr/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## 3.1.3

- [fix] can't get the getStaticPaths method from the dynamic import route component
- [fix] not call the getStaticPaths method from the dynamic import route component
- [fix] not call the getInitialProps method from the dynamic import route component

## 3.1.2

Expand Down
15 changes: 8 additions & 7 deletions packages/plugin-ice-ssr/src/server.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,12 @@ export async function renderStatic(
if (!component) {
const result = await getComponentByPath(
routes,
initialContext.pathname
initialContext.pathname,
);
component = result.component;
getInitialProps = result.getInitialProps;
}
if (component && component.load) {
const loadedPageComponent = await component.load();
component = loadedPageComponent.default;
}

let pageInitialProps = {};
if (getInitialProps) {
console.log('[SSR]', 'getting initial props of page component', initialContext.pathname);
Expand Down Expand Up @@ -260,10 +257,14 @@ export async function getComponentByPath(routes, currPath) {
return matchedRoute.children ? await findMatchRoute(matchedRoute.children) : matchedRoute;
}
}
const routeData = await findMatchRoute(routes)
const routeData = await findMatchRoute(routes);
if (routeData?.component && routeData?.component?.load) {
const loadedPageComponent = await routeData.component.load();
routeData.component = loadedPageComponent.default;
}
return {
component: routeData?.component,
getInitialProps: routeData?.getInitialProps || routeData?.component?.getInitialProps
getInitialProps: routeData?.getInitialProps || routeData?.component?.getInitialProps,
};
<% } else { %>
const matchedComponent = appConfig?.app?.renderComponent;
Expand Down