Skip to content

Commit f9e1da1

Browse files
authored
Consider case when getInitialProps comes first (#42)
1 parent f72fde2 commit f9e1da1

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,6 @@ impl NextSuperJsonTransformer {
610610
let mut first = None;
611611

612612
items.iter_mut().enumerate().any(|(pos, item)| {
613-
// check initial props
614-
item.visit_mut_children_with(self);
615-
616613
let found = match item {
617614
// check has ssg props
618615
ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl { decl, .. })) => {
@@ -666,7 +663,7 @@ impl NextSuperJsonTransformer {
666663
};
667664

668665
if found {
669-
if first.is_some() || self.use_init_props {
666+
if first.is_some() {
670667
self.has_multiple_props = true;
671668
return true;
672669
}
@@ -680,6 +677,13 @@ impl NextSuperJsonTransformer {
680677
return;
681678
}
682679

680+
// check initial props
681+
if first.is_none() {
682+
items
683+
.iter_mut()
684+
.for_each(|item| item.visit_mut_children_with(self));
685+
}
686+
683687
self.props.export.orig = first;
684688

685689
if ssg_prop_ident.is_some() && !self.props.skip {

tests/fixture/skip/multiple-exports/code.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ export default function Page() {
22
return <div>Page</div>;
33
}
44

5+
Page.getInitialProps = () => {
6+
return {};
7+
}
8+
59
export const getStaticProps = () => {
610
return {
711
props: {},
@@ -12,8 +16,4 @@ export const getServerSideProps = () => {
1216
return {
1317
props: {},
1418
};
15-
}
16-
17-
Page.getInitialProps = () => {
18-
return {};
1919
}

tests/fixture/skip/multiple-exports/output.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ export default function Page() {
22
return <div>Page</div>;
33
}
44

5+
Page.getInitialProps = () => {
6+
return {};
7+
}
8+
59
export const getStaticProps = () => {
610
return {
711
props: {},
@@ -12,8 +16,4 @@ export const getServerSideProps = () => {
1216
return {
1317
props: {},
1418
};
15-
}
16-
17-
Page.getInitialProps = () => {
18-
return {};
1919
}

0 commit comments

Comments
 (0)