create-plasmic-app 0.0.38 → 0.0.41

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.
@@ -150,6 +150,27 @@ const HeadComponents = [
150
150
  key="plasmic-preamble"
151
151
  src="https://static1.plasmic.app/preamble.js"
152
152
  />,
153
+ <script
154
+ key="plasmic-hmr"
155
+ type="text/javascript"
156
+ dangerouslySetInnerHTML={{
157
+ __html: \`
158
+ if (typeof window !== "undefined" && /\\\\/plasmic-host\\\\/?$/.test(window.location.pathname)) {
159
+ const RealEventSource = window.EventSource;
160
+ window.EventSource = function(url, config) {
161
+ if (/[^a-zA-Z]hmr($|[^a-zA-Z])/.test(url)) {
162
+ console.warn("Plasmic: disabled EventSource request for", url);
163
+ return {
164
+ onerror() {}, onmessage() {}, onopen() {}, close() {}
165
+ };
166
+ } else {
167
+ return new RealEventSource(url, config);
168
+ }
169
+ }
170
+ }
171
+ \`,
172
+ }}
173
+ />
153
174
  ]
154
175
 
155
176
  const isProduction = process.env.NODE_ENV === "production"
@@ -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-react";
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-plasmic-app",
3
- "version": "0.0.38",
3
+ "version": "0.0.41",
4
4
  "description": "Create Plasmic-powered React apps",
5
5
  "main": "./dist/lib.js",
6
6
  "types": "./dist/lib.d.ts",
@@ -167,6 +167,27 @@ const HeadComponents = [
167
167
  key="plasmic-preamble"
168
168
  src="https://static1.plasmic.app/preamble.js"
169
169
  />,
170
+ <script
171
+ key="plasmic-hmr"
172
+ type="text/javascript"
173
+ dangerouslySetInnerHTML={{
174
+ __html: \`
175
+ if (typeof window !== "undefined" && /\\\\/plasmic-host\\\\/?$/.test(window.location.pathname)) {
176
+ const RealEventSource = window.EventSource;
177
+ window.EventSource = function(url, config) {
178
+ if (/[^a-zA-Z]hmr($|[^a-zA-Z])/.test(url)) {
179
+ console.warn("Plasmic: disabled EventSource request for", url);
180
+ return {
181
+ onerror() {}, onmessage() {}, onopen() {}, close() {}
182
+ };
183
+ } else {
184
+ return new RealEventSource(url, config);
185
+ }
186
+ }
187
+ }
188
+ \`,
189
+ }}
190
+ />
170
191
  ]
171
192
 
172
193
  const isProduction = process.env.NODE_ENV === "production"
@@ -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-react";
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 () => {
Binary file
Binary file
Binary file