create-plasmic-app 0.0.39 → 0.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/strategies/nextjs.js +14 -1
- package/dist/templates/nextjs.js +18 -15
- package/package.json +1 -1
- package/src/strategies/nextjs.ts +16 -2
- package/src/templates/nextjs.ts +18 -15
|
@@ -41,8 +41,8 @@ const nextjsStrategy = {
|
|
|
41
41
|
}),
|
|
42
42
|
overwriteConfig: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
43
|
const { projectPath, scheme } = args;
|
|
44
|
+
const nextjsConfigFile = path_1.default.join(projectPath, "next.config.js");
|
|
44
45
|
if (scheme === "codegen") {
|
|
45
|
-
const nextjsConfigFile = path_1.default.join(projectPath, "next.config.js");
|
|
46
46
|
yield fs_1.promises.writeFile(nextjsConfigFile, `
|
|
47
47
|
module.exports = {
|
|
48
48
|
eslint: {
|
|
@@ -53,6 +53,19 @@ module.exports = {
|
|
|
53
53
|
};
|
|
54
54
|
`);
|
|
55
55
|
}
|
|
56
|
+
else {
|
|
57
|
+
yield fs_1.promises.writeFile(nextjsConfigFile, `
|
|
58
|
+
/** @type {import('next').NextConfig} */
|
|
59
|
+
const nextConfig = {
|
|
60
|
+
// Turn off React StrictMode for now, as react-aria (used by Plasmic)
|
|
61
|
+
// has some troubles with it. See
|
|
62
|
+
// https://github.com/adobe/react-spectrum/labels/strict%20mode
|
|
63
|
+
reactStrictMode: false,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = nextConfig
|
|
67
|
+
`);
|
|
68
|
+
}
|
|
56
69
|
}),
|
|
57
70
|
generateFiles: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
71
|
// this is supposed to be called for loader case, so we are supposed to remove
|
package/dist/templates/nextjs.js
CHANGED
|
@@ -34,19 +34,21 @@ function makeNextjsCatchallPage(format) {
|
|
|
34
34
|
const ts = format === "ts";
|
|
35
35
|
return `
|
|
36
36
|
import * as React from "react";
|
|
37
|
-
import { PlasmicComponent } from "@plasmicapp/loader-nextjs";
|
|
38
|
-
${file_utils_1.ifTs(ts, `import { GetStaticPaths, GetStaticProps } from "next";\n`)}
|
|
39
37
|
import {
|
|
38
|
+
PlasmicComponent,
|
|
39
|
+
extractPlasmicQueryData,
|
|
40
40
|
ComponentRenderData,
|
|
41
41
|
PlasmicRootProvider,
|
|
42
|
-
} from "@plasmicapp/loader-
|
|
42
|
+
} from "@plasmicapp/loader-nextjs";
|
|
43
|
+
${file_utils_1.ifTs(ts, `import { GetStaticPaths, GetStaticProps } from "next";\n`)}
|
|
43
44
|
import Error from "next/error";
|
|
44
45
|
import { PLASMIC } from "../plasmic-init";
|
|
45
46
|
|
|
46
47
|
export default function PlasmicLoaderPage(props${file_utils_1.ifTs(ts, `: {
|
|
47
48
|
plasmicData?: ComponentRenderData;
|
|
49
|
+
queryCache?: Record<string, any>;
|
|
48
50
|
}`)}) {
|
|
49
|
-
const { plasmicData } = props;
|
|
51
|
+
const { plasmicData, queryCache } = props;
|
|
50
52
|
if (!plasmicData || plasmicData.entryCompMetas.length === 0) {
|
|
51
53
|
return <Error statusCode={404} />;
|
|
52
54
|
}
|
|
@@ -54,6 +56,7 @@ export default function PlasmicLoaderPage(props${file_utils_1.ifTs(ts, `: {
|
|
|
54
56
|
<PlasmicRootProvider
|
|
55
57
|
loader={PLASMIC}
|
|
56
58
|
prefetchedData={plasmicData}
|
|
59
|
+
prefetchedQueryData={queryCache}
|
|
57
60
|
>
|
|
58
61
|
<PlasmicComponent component={plasmicData.entryCompMetas[0].name} />
|
|
59
62
|
</PlasmicRootProvider>
|
|
@@ -64,18 +67,18 @@ export const getStaticProps${file_utils_1.ifTs(ts, `: GetStaticProps`)} = async
|
|
|
64
67
|
const { catchall } = context.params ?? {};
|
|
65
68
|
const plasmicPath = typeof catchall === 'string' ? catchall : Array.isArray(catchall) ? \`/\${catchall.join('/')}\` : '/';
|
|
66
69
|
const plasmicData = await PLASMIC.maybeFetchComponentData(plasmicPath);
|
|
67
|
-
if (plasmicData) {
|
|
68
|
-
return {
|
|
69
|
-
props: { plasmicData },
|
|
70
|
-
|
|
71
|
-
// Use revalidate if you want incremental static regeneration
|
|
72
|
-
revalidate: 60
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
70
|
+
if (!plasmicData) {
|
|
76
71
|
// non-Plasmic catch-all
|
|
77
|
-
props: {}
|
|
78
|
-
}
|
|
72
|
+
return { props: {} };
|
|
73
|
+
}
|
|
74
|
+
// Cache the necessary data fetched for the page
|
|
75
|
+
const queryCache = await extractPlasmicQueryData(
|
|
76
|
+
<PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>
|
|
77
|
+
<PlasmicComponent component={plasmicData.entryCompMetas[0].name} />
|
|
78
|
+
</PlasmicRootProvider>
|
|
79
|
+
);
|
|
80
|
+
// Use revalidate if you want incremental static regeneration
|
|
81
|
+
return { props: { plasmicData, queryCache }, revalidate: 60 };
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
export const getStaticPaths${file_utils_1.ifTs(ts, `: GetStaticPaths`)} = async () => {
|
package/package.json
CHANGED
package/src/strategies/nextjs.ts
CHANGED
|
@@ -36,9 +36,8 @@ const nextjsStrategy: CPAStrategy = {
|
|
|
36
36
|
},
|
|
37
37
|
overwriteConfig: async (args) => {
|
|
38
38
|
const { projectPath, scheme } = args;
|
|
39
|
-
|
|
39
|
+
const nextjsConfigFile = path.join(projectPath, "next.config.js");
|
|
40
40
|
if (scheme === "codegen") {
|
|
41
|
-
const nextjsConfigFile = path.join(projectPath, "next.config.js");
|
|
42
41
|
await fs.writeFile(
|
|
43
42
|
nextjsConfigFile,
|
|
44
43
|
`
|
|
@@ -51,6 +50,21 @@ module.exports = {
|
|
|
51
50
|
};
|
|
52
51
|
`
|
|
53
52
|
);
|
|
53
|
+
} else {
|
|
54
|
+
await fs.writeFile(
|
|
55
|
+
nextjsConfigFile,
|
|
56
|
+
`
|
|
57
|
+
/** @type {import('next').NextConfig} */
|
|
58
|
+
const nextConfig = {
|
|
59
|
+
// Turn off React StrictMode for now, as react-aria (used by Plasmic)
|
|
60
|
+
// has some troubles with it. See
|
|
61
|
+
// https://github.com/adobe/react-spectrum/labels/strict%20mode
|
|
62
|
+
reactStrictMode: false,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = nextConfig
|
|
66
|
+
`
|
|
67
|
+
)
|
|
54
68
|
}
|
|
55
69
|
},
|
|
56
70
|
generateFiles: async (args) => {
|
package/src/templates/nextjs.ts
CHANGED
|
@@ -37,12 +37,13 @@ export function makeNextjsCatchallPage(format: "ts" | "js"): string {
|
|
|
37
37
|
const ts = format === "ts";
|
|
38
38
|
return `
|
|
39
39
|
import * as React from "react";
|
|
40
|
-
import { PlasmicComponent } from "@plasmicapp/loader-nextjs";
|
|
41
|
-
${ifTs(ts, `import { GetStaticPaths, GetStaticProps } from "next";\n`)}
|
|
42
40
|
import {
|
|
41
|
+
PlasmicComponent,
|
|
42
|
+
extractPlasmicQueryData,
|
|
43
43
|
ComponentRenderData,
|
|
44
44
|
PlasmicRootProvider,
|
|
45
|
-
} from "@plasmicapp/loader-
|
|
45
|
+
} from "@plasmicapp/loader-nextjs";
|
|
46
|
+
${ifTs(ts, `import { GetStaticPaths, GetStaticProps } from "next";\n`)}
|
|
46
47
|
import Error from "next/error";
|
|
47
48
|
import { PLASMIC } from "../plasmic-init";
|
|
48
49
|
|
|
@@ -50,9 +51,10 @@ export default function PlasmicLoaderPage(props${ifTs(
|
|
|
50
51
|
ts,
|
|
51
52
|
`: {
|
|
52
53
|
plasmicData?: ComponentRenderData;
|
|
54
|
+
queryCache?: Record<string, any>;
|
|
53
55
|
}`
|
|
54
56
|
)}) {
|
|
55
|
-
const { plasmicData } = props;
|
|
57
|
+
const { plasmicData, queryCache } = props;
|
|
56
58
|
if (!plasmicData || plasmicData.entryCompMetas.length === 0) {
|
|
57
59
|
return <Error statusCode={404} />;
|
|
58
60
|
}
|
|
@@ -60,6 +62,7 @@ export default function PlasmicLoaderPage(props${ifTs(
|
|
|
60
62
|
<PlasmicRootProvider
|
|
61
63
|
loader={PLASMIC}
|
|
62
64
|
prefetchedData={plasmicData}
|
|
65
|
+
prefetchedQueryData={queryCache}
|
|
63
66
|
>
|
|
64
67
|
<PlasmicComponent component={plasmicData.entryCompMetas[0].name} />
|
|
65
68
|
</PlasmicRootProvider>
|
|
@@ -73,18 +76,18 @@ export const getStaticProps${ifTs(
|
|
|
73
76
|
const { catchall } = context.params ?? {};
|
|
74
77
|
const plasmicPath = typeof catchall === 'string' ? catchall : Array.isArray(catchall) ? \`/\${catchall.join('/')}\` : '/';
|
|
75
78
|
const plasmicData = await PLASMIC.maybeFetchComponentData(plasmicPath);
|
|
76
|
-
if (plasmicData) {
|
|
77
|
-
return {
|
|
78
|
-
props: { plasmicData },
|
|
79
|
-
|
|
80
|
-
// Use revalidate if you want incremental static regeneration
|
|
81
|
-
revalidate: 60
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
79
|
+
if (!plasmicData) {
|
|
85
80
|
// non-Plasmic catch-all
|
|
86
|
-
props: {}
|
|
87
|
-
}
|
|
81
|
+
return { props: {} };
|
|
82
|
+
}
|
|
83
|
+
// Cache the necessary data fetched for the page
|
|
84
|
+
const queryCache = await extractPlasmicQueryData(
|
|
85
|
+
<PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>
|
|
86
|
+
<PlasmicComponent component={plasmicData.entryCompMetas[0].name} />
|
|
87
|
+
</PlasmicRootProvider>
|
|
88
|
+
);
|
|
89
|
+
// Use revalidate if you want incremental static regeneration
|
|
90
|
+
return { props: { plasmicData, queryCache }, revalidate: 60 };
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
export const getStaticPaths${ifTs(ts, `: GetStaticPaths`)} = async () => {
|