@plasmicapp/loader-nextjs 1.0.432 → 2.0.0-alpha.1
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/index.d.ts +1 -31
- package/dist/index.esm.js +25 -30
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +6 -11
- package/dist/index.js.map +3 -3
- package/dist/react-server.d.ts +3 -196
- package/dist/react-server.esm.js +5 -65
- package/dist/react-server.esm.js.map +2 -2
- package/dist/react-server.js +5 -61
- package/dist/react-server.js.map +3 -3
- package/package.json +22 -15
- package/react-server-conditional.d.ts +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
|
|
3
|
-
import { ExtractPlasmicQueryData as __EXPERMIENTAL__ExtractPlasmicQueryData } from '@plasmicapp/nextjs-app-router';
|
|
4
3
|
import { CodeComponentMeta } from '@plasmicapp/loader-react';
|
|
5
4
|
import { ComponentLookupSpec } from '@plasmicapp/loader-react';
|
|
6
5
|
import { ComponentMeta } from '@plasmicapp/loader-react/react-server-conditional';
|
|
@@ -38,8 +37,6 @@ import { usePlasmicQueryData } from '@plasmicapp/loader-react';
|
|
|
38
37
|
import { useSelector } from '@plasmicapp/loader-react';
|
|
39
38
|
import { useSelectors } from '@plasmicapp/loader-react';
|
|
40
39
|
|
|
41
|
-
export { __EXPERMIENTAL__ExtractPlasmicQueryData }
|
|
42
|
-
|
|
43
40
|
export { CodeComponentMeta }
|
|
44
41
|
|
|
45
42
|
export { ComponentMeta }
|
|
@@ -103,34 +100,7 @@ export { GlobalActionsProvider }
|
|
|
103
100
|
|
|
104
101
|
export { InitOptions }
|
|
105
102
|
|
|
106
|
-
export declare function initPlasmicLoader(opts:
|
|
107
|
-
|
|
108
|
-
export declare interface NextInitOptions extends InitOptions {
|
|
109
|
-
/**
|
|
110
|
-
* next/navigation doesn't exist prior to Next.js 13, so Plasmic can't assume the dependency exists.
|
|
111
|
-
* If you use the App Router (which depends on next/navigation), you'll need to pass the module here.
|
|
112
|
-
*
|
|
113
|
-
* ```tsx
|
|
114
|
-
* import { initPlasmicLoader } from "@plasmicapp/loader-nextjs/react-server-conditional";
|
|
115
|
-
* import * as NextNavigation from "next/navigation";
|
|
116
|
-
*
|
|
117
|
-
* export const PLASMIC = initPlasmicLoader({
|
|
118
|
-
* nextNavigation: NextNavigation,
|
|
119
|
-
* projects: [
|
|
120
|
-
* // your projects
|
|
121
|
-
* ],
|
|
122
|
-
* });
|
|
123
|
-
* ```
|
|
124
|
-
*/
|
|
125
|
-
nextNavigation?: {
|
|
126
|
-
notFound: unknown;
|
|
127
|
-
redirect: unknown;
|
|
128
|
-
useParams: unknown;
|
|
129
|
-
usePathname: unknown;
|
|
130
|
-
useRouter: unknown;
|
|
131
|
-
useSearchParams: unknown;
|
|
132
|
-
};
|
|
133
|
-
}
|
|
103
|
+
export declare function initPlasmicLoader(opts: InitOptions): NextJsPlasmicComponentLoader;
|
|
134
104
|
|
|
135
105
|
export declare class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {
|
|
136
106
|
constructor(internal: InternalPlasmicComponentLoader);
|
package/dist/index.esm.js
CHANGED
|
@@ -61,29 +61,9 @@ import {
|
|
|
61
61
|
PlasmicComponentLoader,
|
|
62
62
|
extractPlasmicQueryData as internalExtractPlasmicQueryData
|
|
63
63
|
} from "@plasmicapp/loader-react";
|
|
64
|
-
import {
|
|
65
|
-
DataCtxReader,
|
|
66
|
-
DataProvider,
|
|
67
|
-
GlobalActionsContext,
|
|
68
|
-
GlobalActionsProvider,
|
|
69
|
-
PageParamsProvider,
|
|
70
|
-
PlasmicCanvasContext,
|
|
71
|
-
PlasmicCanvasHost,
|
|
72
|
-
PlasmicComponent,
|
|
73
|
-
PlasmicTranslatorContext,
|
|
74
|
-
plasmicPrepass,
|
|
75
|
-
repeatedElement,
|
|
76
|
-
useDataEnv,
|
|
77
|
-
usePlasmicCanvasComponentInfo,
|
|
78
|
-
usePlasmicCanvasContext,
|
|
79
|
-
usePlasmicComponent,
|
|
80
|
-
usePlasmicQueryData,
|
|
81
|
-
useSelector,
|
|
82
|
-
useSelectors
|
|
83
|
-
} from "@plasmicapp/loader-react";
|
|
84
|
-
import { ExtractPlasmicQueryData } from "@plasmicapp/nextjs-app-router";
|
|
85
64
|
import NextHead from "next/head.js";
|
|
86
65
|
import NextLink from "next/link.js";
|
|
66
|
+
import * as NextNavigation from "next/navigation.js";
|
|
87
67
|
import * as NextRouter from "next/router.js";
|
|
88
68
|
import Script from "next/script";
|
|
89
69
|
import * as React2 from "react";
|
|
@@ -196,8 +176,7 @@ function makeCache(opts) {
|
|
|
196
176
|
);
|
|
197
177
|
return new FileCache(cachePath);
|
|
198
178
|
}
|
|
199
|
-
function initPlasmicLoaderWithCache(initFn,
|
|
200
|
-
var _b = _a, { nextNavigation } = _b, opts = __objRest(_b, ["nextNavigation"]);
|
|
179
|
+
function initPlasmicLoaderWithCache(initFn, opts) {
|
|
201
180
|
const isBrowser = typeof window !== "undefined";
|
|
202
181
|
const isProd = process.env.NODE_ENV === "production";
|
|
203
182
|
const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;
|
|
@@ -209,7 +188,8 @@ function initPlasmicLoaderWithCache(initFn, _a) {
|
|
|
209
188
|
platform: "nextjs",
|
|
210
189
|
platformOptions: {
|
|
211
190
|
nextjs: {
|
|
212
|
-
appDir:
|
|
191
|
+
appDir: true
|
|
192
|
+
// always true now that we require next@>=13
|
|
213
193
|
}
|
|
214
194
|
},
|
|
215
195
|
// For Nextjs 12, revalidate may in fact re-use an existing instance
|
|
@@ -322,6 +302,26 @@ function wrapRouterContext(element) {
|
|
|
322
302
|
}
|
|
323
303
|
|
|
324
304
|
// src/index.tsx
|
|
305
|
+
import {
|
|
306
|
+
DataCtxReader,
|
|
307
|
+
DataProvider,
|
|
308
|
+
GlobalActionsContext,
|
|
309
|
+
GlobalActionsProvider,
|
|
310
|
+
PageParamsProvider,
|
|
311
|
+
PlasmicCanvasContext,
|
|
312
|
+
PlasmicCanvasHost,
|
|
313
|
+
PlasmicComponent,
|
|
314
|
+
PlasmicTranslatorContext,
|
|
315
|
+
plasmicPrepass,
|
|
316
|
+
repeatedElement,
|
|
317
|
+
useDataEnv,
|
|
318
|
+
usePlasmicCanvasComponentInfo,
|
|
319
|
+
usePlasmicCanvasContext,
|
|
320
|
+
usePlasmicComponent,
|
|
321
|
+
usePlasmicQueryData,
|
|
322
|
+
useSelector,
|
|
323
|
+
useSelectors
|
|
324
|
+
} from "@plasmicapp/loader-react";
|
|
325
325
|
var reactMajorVersion = +React2.version.split(".")[0];
|
|
326
326
|
function filterCodeFromRenderData(data) {
|
|
327
327
|
if (reactMajorVersion >= 18 && !!data.bundle.bundleKey) {
|
|
@@ -427,13 +427,9 @@ function initPlasmicLoader(opts) {
|
|
|
427
427
|
loader.registerModules({
|
|
428
428
|
"next/head": NextHead,
|
|
429
429
|
"next/link": NextLink,
|
|
430
|
+
"next/navigation": NextNavigation,
|
|
430
431
|
"next/router": NextRouter
|
|
431
432
|
});
|
|
432
|
-
if (opts.nextNavigation) {
|
|
433
|
-
loader.registerModules({
|
|
434
|
-
"next/navigation": opts.nextNavigation
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
433
|
return loader;
|
|
438
434
|
}
|
|
439
435
|
function extractPlasmicQueryData(element) {
|
|
@@ -560,7 +556,6 @@ export {
|
|
|
560
556
|
PlasmicComponent,
|
|
561
557
|
PlasmicRootProvider,
|
|
562
558
|
PlasmicTranslatorContext,
|
|
563
|
-
ExtractPlasmicQueryData as __EXPERMIENTAL__ExtractPlasmicQueryData,
|
|
564
559
|
extractPlasmicQueryData,
|
|
565
560
|
initPlasmicLoader,
|
|
566
561
|
plasmicPrepass,
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.tsx", "../src/cache.ts", "../src/server-require.ts", "../src/mocks.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { CodeModule } from \"@plasmicapp/loader-core\";\nimport {\n PlasmicRootProvider as CommonPlasmicRootProvider,\n ComponentLookupSpec,\n FetchComponentDataOpts as InternalFetchComponentDataOpts,\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n extractPlasmicQueryData as internalExtractPlasmicQueryData,\n} from \"@plasmicapp/loader-react\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nexport {\n DataCtxReader,\n DataProvider,\n GlobalActionsContext,\n GlobalActionsProvider,\n PageParamsProvider,\n PlasmicCanvasContext,\n PlasmicCanvasHost,\n PlasmicComponent,\n PlasmicTranslatorContext,\n plasmicPrepass,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasComponentInfo,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\n CustomFunctionMeta,\n PlasmicTranslator,\n PropType,\n TokenRegistration,\n} from \"@plasmicapp/loader-react\";\nexport { ExtractPlasmicQueryData as __EXPERMIENTAL__ExtractPlasmicQueryData } from \"@plasmicapp/nextjs-app-router\";\nexport * from \"./shared-exports\";\n// NextHead and NextLink must be default imported (`import Pkg`) instead of a namespace import (`import * as Pkg`).\n// Otherwise, there's a Next.js 12 bug when referencing these dependencies due to default import interop.\n// The transpiled CommonJS code would create a `default` field on the package,\n// causing React to think it's an invalid React object:\n// ```\n// const NextHead = __defaultInterop(require('next/head.js'))\n// assert(typeof NextHead === 'object')\n// assert(typeof NextHead.default === 'function')\n// ```\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport * as NextRouter from \"next/router.js\";\nimport Script from \"next/script\";\nimport * as React from \"react\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport { wrapRouterContext } from \"./mocks\";\nimport type { ComponentRenderData, NextInitOptions } from \"./shared-exports\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: Partial<{\n [key: string]: string;\n }>;\n};\n\nconst reactMajorVersion = +React.version.split(\".\")[0];\n\nfunction filterCodeFromRenderData(data: ComponentRenderData) {\n if (reactMajorVersion >= 18 && !!data.bundle.bundleKey) {\n // Keep the entrypoints\n const entrypoints = new Set([\n ...data.entryCompMetas.map((compMeta) => compMeta.entry),\n \"root-provider.js\",\n ...data.bundle.projects\n .map((x) => x.globalContextsProviderFileName)\n .filter((x) => !!x),\n ...data.bundle.components\n .filter((c) => c.isGlobalContextProvider)\n .map((c) => c.entry),\n ...data.bundle.globalGroups.map((g) => g.contextFile),\n ]);\n\n data.bundle.modules.browser = data.bundle.modules.browser.map((module) => {\n if (module.type !== \"code\" || entrypoints.has(module.fileName)) {\n return module;\n }\n return { ...module, code: \"\" };\n });\n }\n}\n\nexport interface FetchComponentDataOpts extends InternalFetchComponentDataOpts {\n /**\n * Defer loading code chunks to script tags, reducing initial payload size.\n */\n deferChunks?: boolean;\n}\n\nexport class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {\n constructor(internal: InternalPlasmicComponentLoader) {\n super(internal);\n }\n\n async getActiveVariation(opts: {\n req?: ServerRequest;\n res?: ServerResponse;\n known?: Record<string, string>;\n traits: Record<string, string | number | boolean>;\n }) {\n const extractBuiltinTraits = () => {\n const url = new URL(\n opts.req?.url ?? \"/\",\n `https://${opts.req?.headers.host ?? \"server.side\"}`\n );\n return {\n pageUrl: url.href,\n };\n };\n\n return this._getActiveVariation({\n enableUnseededExperiments: true,\n traits: {\n ...extractBuiltinTraits(),\n ...opts.traits,\n },\n getKnownValue: (key: string) => {\n if (opts.known) {\n return opts.known[key];\n } else {\n return opts.req?.cookies[`plasmic:${key}`] ?? undefined;\n }\n },\n updateKnownValue: (key: string, value: string) => {\n if (opts.res) {\n const cookie = `plasmic:${key}=${value}`;\n const resCookie = opts.res?.getHeader(\"Set-Cookie\") ?? [];\n let newCookies: string[] = [];\n if (Array.isArray(resCookie)) {\n newCookies = [...resCookie, `plasmic:${key}=${value}`];\n } else {\n newCookies = [`${resCookie}`, cookie];\n }\n\n opts.res?.setHeader(\"Set-Cookie\", newCookies);\n }\n },\n });\n }\n\n maybeFetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData | null>;\n maybeFetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData | null>;\n async maybeFetchComponentData(\n ...args: any[]\n ): Promise<ComponentRenderData | null> {\n const data = await super.maybeFetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n data &&\n (opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault))\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n\n fetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData>;\n fetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData>;\n async fetchComponentData(...args: any[]): Promise<ComponentRenderData> {\n const data = await super.fetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault)\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n}\n\nfunction parseFetchComponentDataArgs(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n): { specs: ComponentLookupSpec[]; opts?: FetchComponentDataOpts };\nfunction parseFetchComponentDataArgs(...specs: ComponentLookupSpec[]): {\n specs: ComponentLookupSpec[];\n opts?: FetchComponentDataOpts;\n};\nfunction parseFetchComponentDataArgs(...args: any[]) {\n let specs: ComponentLookupSpec[];\n let opts: FetchComponentDataOpts | undefined;\n if (Array.isArray(args[0])) {\n specs = args[0];\n opts = args[1];\n } else {\n specs = args;\n opts = undefined;\n }\n return { specs, opts };\n}\n\nexport function initPlasmicLoader(opts: NextInitOptions) {\n const loader = initPlasmicLoaderWithCache<NextJsPlasmicComponentLoader>(\n (opts) =>\n new NextJsPlasmicComponentLoader(\n new InternalPlasmicComponentLoader(opts)\n ),\n opts\n );\n loader.registerModules({\n \"next/head\": NextHead,\n \"next/link\": NextLink,\n \"next/router\": NextRouter,\n });\n if (opts.nextNavigation) {\n loader.registerModules({\n \"next/navigation\": opts.nextNavigation,\n });\n }\n return loader;\n}\n\n/**\n * Performs a prepass over Plasmic content, kicking off the necessary\n * data fetches, and populating the fetched data into a cache. This\n * cache can be passed as prefetchedQueryData into PlasmicRootProvider.\n *\n * To limit rendering errors that can occur when you do this, we recommend\n * that you pass in _only_ the PlasmicComponents that you are planning to use\n * as the argument. For example:\n *\n * const cache = await extractPlasmicQueryData(\n * <PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>\n * <PlasmicComponent component=\"Home\" componentProps={{\n * // Specify the component prop overrides you are planning to use\n * // to render the page, as they may change what data is fetched.\n * ...\n * }} />\n * <PlasmicComponent component=\"NavBar\" componentProps={{\n * ...\n * }} />\n * ...\n * </PlasmicRootProvider>\n * );\n *\n * If your PlasmicComponent will be wrapping components that require special\n * context set up, you should also wrap the element above with those context\n * providers.\n *\n * You should avoid passing in elements that are not related to Plasmic, as any\n * rendering errors from those elements during the prepass may result in data\n * not being populated in the cache.\n *\n * @param element a React element containing instances of PlasmicComponent.\n * Will attempt to satisfy all data needs from usePlasmicDataQuery()\n * in this element tree.\n * @returns an object mapping query key to fetched data\n */\nexport async function extractPlasmicQueryData(element: React.ReactElement) {\n return internalExtractPlasmicQueryData(await wrapRouterContext(element));\n}\n\nconst PlasmicNextLink = React.forwardRef(function PlasmicNextLink(\n props: React.ComponentProps<typeof NextLink>,\n ref: React.Ref<HTMLAnchorElement>\n) {\n // Basically renders NextLink, except when href is undefined,\n // which freaks out NextLink :-/\n if (props.href) {\n const {\n href,\n replace,\n scroll,\n shallow,\n passHref,\n prefetch,\n locale,\n ...rest\n } = props;\n // If this is a fragment identifier link, then we set\n // scroll={false} so that smooth scrolling works\n const isFragment = typeof href === \"string\" && href.startsWith(\"#\");\n // We use legacyBehavior, because we don't know which\n // version of next the user has installed\n return (\n <NextLink\n href={href}\n replace={replace}\n scroll={scroll != null ? scroll : isFragment ? false : undefined}\n shallow={shallow}\n passHref={passHref}\n prefetch={prefetch}\n locale={locale}\n {...({ legacyBehavior: true } as any)}\n >\n <a {...rest} ref={ref} />\n </NextLink>\n );\n } else {\n return <a {...props} href={undefined} ref={ref} />;\n }\n});\n\nexport function PlasmicRootProvider(\n // We omit Head but still allow override for Link\n props: Omit<\n React.ComponentProps<typeof CommonPlasmicRootProvider>,\n \"Head\"\n > & { skipChunks?: boolean }\n) {\n return (\n <>\n {!props.skipChunks &&\n renderDynamicPayloadScripts(props.loader, props.prefetchedData)}\n <CommonPlasmicRootProvider\n Head={NextHead}\n Link={PlasmicNextLink}\n {...props}\n />\n </>\n );\n}\n\nfunction renderDynamicPayloadScripts(\n loader: PlasmicComponentLoader,\n prefetchedData: ComponentRenderData | undefined\n) {\n const missingModulesData =\n prefetchedData &&\n prefetchedData.bundle.modules.browser.filter(\n (module): module is CodeModule => module.type === \"code\" && !module.code\n );\n if (!missingModulesData || missingModulesData.length === 0) {\n return null;\n }\n\n const isBrowser = typeof window !== \"undefined\";\n\n if (isBrowser) {\n // `next/script` seems to not be correctly added to `<head>` in the initial\n // HTML sometimes when using custom documents:\n // https://linear.app/plasmic/issue/PLA-10652\n\n // Make sure to create the promises in this case - the script to actually fetch\n // the chunks will be added once hydration is completed.\n if (!(globalThis as any).__PlasmicBundlePromises) {\n (globalThis as any).__PlasmicBundlePromises = {};\n }\n for (const { fileName } of missingModulesData) {\n if (!(globalThis as any).__PlasmicBundlePromises[fileName]) {\n (globalThis as any).__PlasmicBundlePromises[fileName] = new Promise(\n (resolve) => {\n (globalThis as any).__PlasmicBundlePromises[\n \"__promise_resolve_\" + fileName\n ] = resolve;\n }\n );\n }\n }\n }\n\n return (\n <>\n <Script\n strategy=\"beforeInteractive\"\n key={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n dangerouslySetInnerHTML={{\n __html: `\n if (!globalThis.__PlasmicBundlePromises) {\n globalThis.__PlasmicBundlePromises = {};\n }\n ${missingModulesData\n .map(\n (\n module\n ) => `if (!globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}]) {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}] = new Promise((resolve) => {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n \"__promise_resolve_\" + module.fileName\n )}] = resolve;\n })\n }\n `\n )\n .join(\"\\n\")}`.trim(),\n }}\n ></Script>\n <Script\n strategy=\"beforeInteractive\"\n key={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n defer\n async\n src={loader.getChunksUrl(prefetchedData.bundle, missingModulesData)}\n />\n </>\n );\n}\n", "import { LoaderBundleOutput } from \"@plasmicapp/loader-core\";\nimport type { InitOptions } from \"@plasmicapp/loader-react/react-server-conditional\";\nimport type * as Watcher from \"@plasmicapp/watcher\";\nimport { PHASE_PRODUCTION_BUILD } from \"next/constants\";\nimport path from \"path\";\nimport { serverRequire, serverRequireFs } from \"./server-require\";\nimport type { NextInitOptions } from \"./shared-exports\";\n\nclass FileCache {\n constructor(private filePath: string) {}\n\n async get() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n const data = (await fs.promises.readFile(this.filePath)).toString();\n return JSON.parse(data);\n } catch {\n return undefined;\n }\n }\n\n async set(data: LoaderBundleOutput) {\n const fs = await serverRequireFs();\n try {\n await fs.promises.writeFile(this.filePath, JSON.stringify(data));\n } catch (err) {\n console.warn(`Error writing to Plasmic cache: ${err}`);\n }\n }\n\n async clear() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction hashString(str: string) {\n let h = 0,\n i = 0;\n for (; i < str.length; h &= h) h = 31 * h + str.charCodeAt(i++);\n return Math.abs(h);\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${hashString(\n [...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")\n )}${opts.preview ? \"-preview\" : \"\"}-cache.json`\n );\n return new FileCache(cachePath);\n}\n\nexport function initPlasmicLoaderWithCache<\n T extends {\n clearCache(): void;\n }\n>(\n initFn: (opts: InitOptions) => T,\n { nextNavigation, ...opts }: NextInitOptions\n): T {\n const isBrowser = typeof window !== \"undefined\";\n const isProd = process.env.NODE_ENV === \"production\";\n const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;\n const cache = isBrowser || isProd ? undefined : makeCache(opts);\n const loader = initFn({\n onClientSideFetch: \"warn\",\n ...opts,\n cache,\n platform: \"nextjs\",\n platformOptions: {\n nextjs: {\n appDir: !!nextNavigation,\n },\n },\n // For Nextjs 12, revalidate may in fact re-use an existing instance\n // of PlasmicComponentLoader that's already in memory, so we need to\n // make sure we don't re-use the data cached in memory.\n // We also enforce this for dev mode, so that we don't have to restart\n // the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader\n // We also enforce that during build phase, we re-use the data cached in memory\n // to avoid re-fetching the data from Plasmic servers.\n alwaysFresh: !isBuildPhase && !isBrowser,\n });\n\n if (!isProd) {\n const stringOpts = JSON.stringify(opts);\n\n if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {\n console.warn(\n `PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.\\n`\n );\n }\n\n process.env.PLASMIC_OPTS = stringOpts;\n }\n\n if (cache) {\n if (!isProd) {\n if (process.env.PLASMIC_WATCHED !== \"true\") {\n (async () => {\n process.env.PLASMIC_WATCHED = \"true\";\n console.log(`Subscribing to Plasmic changes...`);\n\n // Import using serverRequire, so webpack doesn't bundle us into client bundle\n try {\n const PlasmicRemoteChangeWatcher = (\n await serverRequire<typeof Watcher>(\"@plasmicapp/watcher\")\n ).PlasmicRemoteChangeWatcher;\n const watcher = new PlasmicRemoteChangeWatcher({\n projects: opts.projects,\n host: opts.host,\n });\n\n const clearCache = () => {\n cache.clear();\n loader.clearCache();\n };\n\n watcher.subscribe({\n onUpdate: () => {\n if (opts.preview) {\n clearCache();\n }\n },\n onPublish: () => {\n if (!opts.preview) {\n clearCache();\n }\n },\n });\n } catch (e) {\n console.warn(\"Couldn't subscribe to Plasmic changes\", e);\n }\n })();\n }\n } else {\n cache.clear();\n loader.clearCache();\n }\n }\n return loader;\n}\n", "import type * as FS from \"fs\";\n\nlet secretRequire: ((module: string) => any) | undefined;\ntry {\n // Secretly use require/import without webpack knowing\n // eslint-disable-next-line\n secretRequire = eval(\"require\");\n} catch (err) {\n try {\n // eslint-disable-next-line\n secretRequire = eval(\"(module) => import(module)\");\n } catch (err) {\n secretRequire = undefined;\n }\n}\n\nexport async function serverRequire<T>(module: string): Promise<T> {\n if (!secretRequire) {\n throw new Error(\n `Unexpected serverRequire() -- can only do this from a Node server!`\n );\n }\n return secretRequire(module) as Promise<T>;\n}\n\nexport async function tryServerRequire<T>(\n module: string\n): Promise<T | undefined> {\n try {\n const require = await serverRequire<T>(module);\n return require;\n } catch {\n return undefined;\n }\n}\n\nexport async function tryServerRequires<T>(\n modules: string[]\n): Promise<T | undefined> {\n for (const module of modules) {\n const require = await tryServerRequire<T>(module);\n if (require != null) {\n return require;\n }\n }\n return undefined;\n}\n\nexport async function serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n", "import type * as RouterContextType from \"next/dist/shared/lib/router-context.shared-runtime\";\nimport type { NextRouter } from \"next/router\";\nimport * as React from \"react\";\nimport { tryServerRequires } from \"./server-require\";\n\nconst fakeRouter: NextRouter = {\n push: async () => {\n return true;\n },\n replace: async () => {\n return true;\n },\n reload: () => {},\n back: () => {},\n forward: () => {},\n prefetch: async () => {\n return;\n },\n beforePopState: () => {},\n events: {\n on: () => {},\n off: () => {},\n emit: () => {},\n },\n route: \"/\",\n asPath: \"/\",\n basePath: \"/\",\n pathname: \"/\",\n query: {},\n isFallback: false,\n isLocaleDomain: false,\n isReady: true,\n isPreview: false,\n};\n\nexport async function wrapRouterContext(element: React.ReactElement) {\n const RouterContext = (\n await tryServerRequires<typeof RouterContextType>([\n \"next/dist/shared/lib/router-context.shared-runtime\",\n \"next/dist/shared/lib/router-context\",\n ])\n )?.RouterContext;\n return !!RouterContext?.Provider ? (\n <RouterContext.Provider value={fakeRouter}>\n {element}\n </RouterContext.Provider>\n ) : (\n element\n );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA,EACE,uBAAuB;AAAA,EAGvB;AAAA,EACA;AAAA,EACA,2BAA2B;AAAA,OACtB;AAEP
|
|
4
|
+
"sourcesContent": ["import type { CodeModule } from \"@plasmicapp/loader-core\";\nimport {\n PlasmicRootProvider as CommonPlasmicRootProvider,\n ComponentLookupSpec,\n FetchComponentDataOpts as InternalFetchComponentDataOpts,\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n extractPlasmicQueryData as internalExtractPlasmicQueryData,\n} from \"@plasmicapp/loader-react\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport * as NextNavigation from \"next/navigation.js\";\nimport * as NextRouter from \"next/router.js\";\nimport Script from \"next/script\";\nimport * as React from \"react\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport { wrapRouterContext } from \"./mocks\";\nimport type { ComponentRenderData, InitOptions } from \"./shared-exports\";\n\nexport * from \"./shared-exports\";\n\n// client-only exports\nexport {\n DataCtxReader,\n DataProvider,\n GlobalActionsContext,\n GlobalActionsProvider,\n PageParamsProvider,\n PlasmicCanvasContext,\n PlasmicCanvasHost,\n PlasmicComponent,\n PlasmicTranslatorContext,\n plasmicPrepass,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasComponentInfo,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\n CustomFunctionMeta,\n PlasmicTranslator,\n PropType,\n TokenRegistration,\n} from \"@plasmicapp/loader-react\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: Partial<{\n [key: string]: string;\n }>;\n};\n\nconst reactMajorVersion = +React.version.split(\".\")[0];\n\nfunction filterCodeFromRenderData(data: ComponentRenderData) {\n if (reactMajorVersion >= 18 && !!data.bundle.bundleKey) {\n // Keep the entrypoints\n const entrypoints = new Set([\n ...data.entryCompMetas.map((compMeta) => compMeta.entry),\n \"root-provider.js\",\n ...data.bundle.projects\n .map((x) => x.globalContextsProviderFileName)\n .filter((x) => !!x),\n ...data.bundle.components\n .filter((c) => c.isGlobalContextProvider)\n .map((c) => c.entry),\n ...data.bundle.globalGroups.map((g) => g.contextFile),\n ]);\n\n data.bundle.modules.browser = data.bundle.modules.browser.map((module) => {\n if (module.type !== \"code\" || entrypoints.has(module.fileName)) {\n return module;\n }\n return { ...module, code: \"\" };\n });\n }\n}\n\nexport interface FetchComponentDataOpts extends InternalFetchComponentDataOpts {\n /**\n * Defer loading code chunks to script tags, reducing initial payload size.\n */\n deferChunks?: boolean;\n}\n\nexport class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {\n constructor(internal: InternalPlasmicComponentLoader) {\n super(internal);\n }\n\n async getActiveVariation(opts: {\n req?: ServerRequest;\n res?: ServerResponse;\n known?: Record<string, string>;\n traits: Record<string, string | number | boolean>;\n }) {\n const extractBuiltinTraits = () => {\n const url = new URL(\n opts.req?.url ?? \"/\",\n `https://${opts.req?.headers.host ?? \"server.side\"}`\n );\n return {\n pageUrl: url.href,\n };\n };\n\n return this._getActiveVariation({\n enableUnseededExperiments: true,\n traits: {\n ...extractBuiltinTraits(),\n ...opts.traits,\n },\n getKnownValue: (key: string) => {\n if (opts.known) {\n return opts.known[key];\n } else {\n return opts.req?.cookies[`plasmic:${key}`] ?? undefined;\n }\n },\n updateKnownValue: (key: string, value: string) => {\n if (opts.res) {\n const cookie = `plasmic:${key}=${value}`;\n const resCookie = opts.res?.getHeader(\"Set-Cookie\") ?? [];\n let newCookies: string[] = [];\n if (Array.isArray(resCookie)) {\n newCookies = [...resCookie, `plasmic:${key}=${value}`];\n } else {\n newCookies = [`${resCookie}`, cookie];\n }\n\n opts.res?.setHeader(\"Set-Cookie\", newCookies);\n }\n },\n });\n }\n\n maybeFetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData | null>;\n maybeFetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData | null>;\n async maybeFetchComponentData(\n ...args: any[]\n ): Promise<ComponentRenderData | null> {\n const data = await super.maybeFetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n data &&\n (opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault))\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n\n fetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData>;\n fetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData>;\n async fetchComponentData(...args: any[]): Promise<ComponentRenderData> {\n const data = await super.fetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault)\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n}\n\nfunction parseFetchComponentDataArgs(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n): { specs: ComponentLookupSpec[]; opts?: FetchComponentDataOpts };\nfunction parseFetchComponentDataArgs(...specs: ComponentLookupSpec[]): {\n specs: ComponentLookupSpec[];\n opts?: FetchComponentDataOpts;\n};\nfunction parseFetchComponentDataArgs(...args: any[]) {\n let specs: ComponentLookupSpec[];\n let opts: FetchComponentDataOpts | undefined;\n if (Array.isArray(args[0])) {\n specs = args[0];\n opts = args[1];\n } else {\n specs = args;\n opts = undefined;\n }\n return { specs, opts };\n}\n\nexport function initPlasmicLoader(\n opts: InitOptions\n): NextJsPlasmicComponentLoader {\n const loader = initPlasmicLoaderWithCache<NextJsPlasmicComponentLoader>(\n (opts) =>\n new NextJsPlasmicComponentLoader(\n new InternalPlasmicComponentLoader(opts)\n ),\n opts\n );\n loader.registerModules({\n \"next/head\": NextHead,\n \"next/link\": NextLink,\n \"next/navigation\": NextNavigation,\n \"next/router\": NextRouter,\n });\n return loader;\n}\n\n/**\n * Performs a prepass over Plasmic content, kicking off the necessary\n * data fetches, and populating the fetched data into a cache. This\n * cache can be passed as prefetchedQueryData into PlasmicRootProvider.\n *\n * To limit rendering errors that can occur when you do this, we recommend\n * that you pass in _only_ the PlasmicComponents that you are planning to use\n * as the argument. For example:\n *\n * const cache = await extractPlasmicQueryData(\n * <PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>\n * <PlasmicComponent component=\"Home\" componentProps={{\n * // Specify the component prop overrides you are planning to use\n * // to render the page, as they may change what data is fetched.\n * ...\n * }} />\n * <PlasmicComponent component=\"NavBar\" componentProps={{\n * ...\n * }} />\n * ...\n * </PlasmicRootProvider>\n * );\n *\n * If your PlasmicComponent will be wrapping components that require special\n * context set up, you should also wrap the element above with those context\n * providers.\n *\n * You should avoid passing in elements that are not related to Plasmic, as any\n * rendering errors from those elements during the prepass may result in data\n * not being populated in the cache.\n *\n * @param element a React element containing instances of PlasmicComponent.\n * Will attempt to satisfy all data needs from usePlasmicDataQuery()\n * in this element tree.\n * @returns an object mapping query key to fetched data\n */\nexport async function extractPlasmicQueryData(element: React.ReactElement) {\n return internalExtractPlasmicQueryData(await wrapRouterContext(element));\n}\n\nconst PlasmicNextLink = React.forwardRef(function PlasmicNextLink(\n props: React.ComponentProps<typeof NextLink>,\n ref: React.Ref<HTMLAnchorElement>\n) {\n // Basically renders NextLink, except when href is undefined,\n // which freaks out NextLink :-/\n if (props.href) {\n const {\n href,\n replace,\n scroll,\n shallow,\n passHref,\n prefetch,\n locale,\n ...rest\n } = props;\n // If this is a fragment identifier link, then we set\n // scroll={false} so that smooth scrolling works\n const isFragment = typeof href === \"string\" && href.startsWith(\"#\");\n // We use legacyBehavior, because we don't know which\n // version of next the user has installed\n return (\n <NextLink\n href={href}\n replace={replace}\n scroll={scroll != null ? scroll : isFragment ? false : undefined}\n shallow={shallow}\n passHref={passHref}\n prefetch={prefetch}\n locale={locale}\n {...({ legacyBehavior: true } as any)}\n >\n <a {...rest} ref={ref} />\n </NextLink>\n );\n } else {\n return <a {...props} href={undefined} ref={ref} />;\n }\n});\n\nexport function PlasmicRootProvider(\n // We omit Head but still allow override for Link\n props: Omit<\n React.ComponentProps<typeof CommonPlasmicRootProvider>,\n \"Head\"\n > & { skipChunks?: boolean }\n) {\n return (\n <>\n {!props.skipChunks &&\n renderDynamicPayloadScripts(props.loader, props.prefetchedData)}\n <CommonPlasmicRootProvider\n Head={NextHead}\n Link={PlasmicNextLink}\n {...props}\n />\n </>\n );\n}\n\nfunction renderDynamicPayloadScripts(\n loader: PlasmicComponentLoader,\n prefetchedData: ComponentRenderData | undefined\n) {\n const missingModulesData =\n prefetchedData &&\n prefetchedData.bundle.modules.browser.filter(\n (module): module is CodeModule => module.type === \"code\" && !module.code\n );\n if (!missingModulesData || missingModulesData.length === 0) {\n return null;\n }\n\n const isBrowser = typeof window !== \"undefined\";\n\n if (isBrowser) {\n // `next/script` seems to not be correctly added to `<head>` in the initial\n // HTML sometimes when using custom documents:\n // https://linear.app/plasmic/issue/PLA-10652\n\n // Make sure to create the promises in this case - the script to actually fetch\n // the chunks will be added once hydration is completed.\n if (!(globalThis as any).__PlasmicBundlePromises) {\n (globalThis as any).__PlasmicBundlePromises = {};\n }\n for (const { fileName } of missingModulesData) {\n if (!(globalThis as any).__PlasmicBundlePromises[fileName]) {\n (globalThis as any).__PlasmicBundlePromises[fileName] = new Promise(\n (resolve) => {\n (globalThis as any).__PlasmicBundlePromises[\n \"__promise_resolve_\" + fileName\n ] = resolve;\n }\n );\n }\n }\n }\n\n return (\n <>\n <Script\n strategy=\"beforeInteractive\"\n key={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n dangerouslySetInnerHTML={{\n __html: `\n if (!globalThis.__PlasmicBundlePromises) {\n globalThis.__PlasmicBundlePromises = {};\n }\n ${missingModulesData\n .map(\n (\n module\n ) => `if (!globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}]) {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}] = new Promise((resolve) => {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n \"__promise_resolve_\" + module.fileName\n )}] = resolve;\n })\n }\n `\n )\n .join(\"\\n\")}`.trim(),\n }}\n ></Script>\n <Script\n strategy=\"beforeInteractive\"\n key={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n defer\n async\n src={loader.getChunksUrl(prefetchedData.bundle, missingModulesData)}\n />\n </>\n );\n}\n", "import { LoaderBundleOutput } from \"@plasmicapp/loader-core\";\nimport type { InitOptions } from \"@plasmicapp/loader-react/react-server-conditional\";\nimport type * as Watcher from \"@plasmicapp/watcher\";\nimport { PHASE_PRODUCTION_BUILD } from \"next/constants\";\nimport path from \"path\";\nimport { serverRequire, serverRequireFs } from \"./server-require\";\n\nclass FileCache {\n constructor(private filePath: string) {}\n\n async get() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n const data = (await fs.promises.readFile(this.filePath)).toString();\n return JSON.parse(data);\n } catch {\n return undefined;\n }\n }\n\n async set(data: LoaderBundleOutput) {\n const fs = await serverRequireFs();\n try {\n await fs.promises.writeFile(this.filePath, JSON.stringify(data));\n } catch (err) {\n console.warn(`Error writing to Plasmic cache: ${err}`);\n }\n }\n\n async clear() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction hashString(str: string) {\n let h = 0,\n i = 0;\n for (; i < str.length; h &= h) h = 31 * h + str.charCodeAt(i++);\n return Math.abs(h);\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${hashString(\n [...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")\n )}${opts.preview ? \"-preview\" : \"\"}-cache.json`\n );\n return new FileCache(cachePath);\n}\n\nexport function initPlasmicLoaderWithCache<\n T extends {\n clearCache(): void;\n }\n>(initFn: (opts: InitOptions) => T, opts: InitOptions): T {\n const isBrowser = typeof window !== \"undefined\";\n const isProd = process.env.NODE_ENV === \"production\";\n const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;\n const cache = isBrowser || isProd ? undefined : makeCache(opts);\n const loader = initFn({\n onClientSideFetch: \"warn\",\n ...opts,\n cache,\n platform: \"nextjs\",\n platformOptions: {\n nextjs: {\n appDir: true, // always true now that we require next@>=13\n },\n },\n // For Nextjs 12, revalidate may in fact re-use an existing instance\n // of PlasmicComponentLoader that's already in memory, so we need to\n // make sure we don't re-use the data cached in memory.\n // We also enforce this for dev mode, so that we don't have to restart\n // the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader\n // We also enforce that during build phase, we re-use the data cached in memory\n // to avoid re-fetching the data from Plasmic servers.\n alwaysFresh: !isBuildPhase && !isBrowser,\n });\n\n if (!isProd) {\n const stringOpts = JSON.stringify(opts);\n\n if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {\n console.warn(\n `PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.\\n`\n );\n }\n\n process.env.PLASMIC_OPTS = stringOpts;\n }\n\n if (cache) {\n if (!isProd) {\n if (process.env.PLASMIC_WATCHED !== \"true\") {\n (async () => {\n process.env.PLASMIC_WATCHED = \"true\";\n console.log(`Subscribing to Plasmic changes...`);\n\n // Import using serverRequire, so webpack doesn't bundle us into client bundle\n try {\n const PlasmicRemoteChangeWatcher = (\n await serverRequire<typeof Watcher>(\"@plasmicapp/watcher\")\n ).PlasmicRemoteChangeWatcher;\n const watcher = new PlasmicRemoteChangeWatcher({\n projects: opts.projects,\n host: opts.host,\n });\n\n const clearCache = () => {\n cache.clear();\n loader.clearCache();\n };\n\n watcher.subscribe({\n onUpdate: () => {\n if (opts.preview) {\n clearCache();\n }\n },\n onPublish: () => {\n if (!opts.preview) {\n clearCache();\n }\n },\n });\n } catch (e) {\n console.warn(\"Couldn't subscribe to Plasmic changes\", e);\n }\n })();\n }\n } else {\n cache.clear();\n loader.clearCache();\n }\n }\n return loader;\n}\n", "import type * as FS from \"fs\";\n\nlet secretRequire: ((module: string) => any) | undefined;\ntry {\n // Secretly use require/import without webpack knowing\n // eslint-disable-next-line\n secretRequire = eval(\"require\");\n} catch (err) {\n try {\n // eslint-disable-next-line\n secretRequire = eval(\"(module) => import(module)\");\n } catch (err) {\n secretRequire = undefined;\n }\n}\n\nexport async function serverRequire<T>(module: string): Promise<T> {\n if (!secretRequire) {\n throw new Error(\n `Unexpected serverRequire() -- can only do this from a Node server!`\n );\n }\n return secretRequire(module) as Promise<T>;\n}\n\nexport async function tryServerRequire<T>(\n module: string\n): Promise<T | undefined> {\n try {\n const require = await serverRequire<T>(module);\n return require;\n } catch {\n return undefined;\n }\n}\n\nexport async function tryServerRequires<T>(\n modules: string[]\n): Promise<T | undefined> {\n for (const module of modules) {\n const require = await tryServerRequire<T>(module);\n if (require != null) {\n return require;\n }\n }\n return undefined;\n}\n\nexport async function serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n", "import type * as RouterContextType from \"next/dist/shared/lib/router-context.shared-runtime\";\nimport type { NextRouter } from \"next/router\";\nimport * as React from \"react\";\nimport { tryServerRequires } from \"./server-require\";\n\nconst fakeRouter: NextRouter = {\n push: async () => {\n return true;\n },\n replace: async () => {\n return true;\n },\n reload: () => {},\n back: () => {},\n forward: () => {},\n prefetch: async () => {\n return;\n },\n beforePopState: () => {},\n events: {\n on: () => {},\n off: () => {},\n emit: () => {},\n },\n route: \"/\",\n asPath: \"/\",\n basePath: \"/\",\n pathname: \"/\",\n query: {},\n isFallback: false,\n isLocaleDomain: false,\n isReady: true,\n isPreview: false,\n};\n\nexport async function wrapRouterContext(element: React.ReactElement) {\n const RouterContext = (\n await tryServerRequires<typeof RouterContextType>([\n \"next/dist/shared/lib/router-context.shared-runtime\",\n \"next/dist/shared/lib/router-context\",\n ])\n )?.RouterContext;\n return !!RouterContext?.Provider ? (\n <RouterContext.Provider value={fakeRouter}>\n {element}\n </RouterContext.Provider>\n ) : (\n element\n );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA,EACE,uBAAuB;AAAA,EAGvB;AAAA,EACA;AAAA,EACA,2BAA2B;AAAA,OACtB;AAEP,OAAO,cAAc;AACrB,OAAO,cAAc;AACrB,YAAY,oBAAoB;AAChC,YAAY,gBAAgB;AAC5B,OAAO,YAAY;AACnB,YAAYA,YAAW;;;ACZvB,SAAS,8BAA8B;AACvC,OAAO,UAAU;;;ACFjB,IAAI;AACJ,IAAI;AAGF,kBAAgB,KAAK,SAAS;AAChC,SAAS,KAAP;AACA,MAAI;AAEF,oBAAgB,KAAK,4BAA4B;AAAA,EACnD,SAASC,MAAP;AACA,oBAAgB;A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
}
|
package/dist/index.js
CHANGED
|
@@ -93,7 +93,6 @@ __export(src_exports, {
|
|
|
93
93
|
PlasmicComponent: () => import_loader_react2.PlasmicComponent,
|
|
94
94
|
PlasmicRootProvider: () => PlasmicRootProvider,
|
|
95
95
|
PlasmicTranslatorContext: () => import_loader_react2.PlasmicTranslatorContext,
|
|
96
|
-
__EXPERMIENTAL__ExtractPlasmicQueryData: () => import_nextjs_app_router.ExtractPlasmicQueryData,
|
|
97
96
|
extractPlasmicQueryData: () => extractPlasmicQueryData,
|
|
98
97
|
initPlasmicLoader: () => initPlasmicLoader,
|
|
99
98
|
plasmicPrepass: () => import_loader_react2.plasmicPrepass,
|
|
@@ -108,10 +107,9 @@ __export(src_exports, {
|
|
|
108
107
|
});
|
|
109
108
|
module.exports = __toCommonJS(src_exports);
|
|
110
109
|
var import_loader_react = require("@plasmicapp/loader-react");
|
|
111
|
-
var import_loader_react2 = require("@plasmicapp/loader-react");
|
|
112
|
-
var import_nextjs_app_router = require("@plasmicapp/nextjs-app-router");
|
|
113
110
|
var import_head = __toESM(require("next/head.js"));
|
|
114
111
|
var import_link = __toESM(require("next/link.js"));
|
|
112
|
+
var NextNavigation = __toESM(require("next/navigation.js"));
|
|
115
113
|
var NextRouter = __toESM(require("next/router.js"));
|
|
116
114
|
var import_script = __toESM(require("next/script"));
|
|
117
115
|
var React2 = __toESM(require("react"));
|
|
@@ -224,8 +222,7 @@ function makeCache(opts) {
|
|
|
224
222
|
);
|
|
225
223
|
return new FileCache(cachePath);
|
|
226
224
|
}
|
|
227
|
-
function initPlasmicLoaderWithCache(initFn,
|
|
228
|
-
var _b = _a, { nextNavigation } = _b, opts = __objRest(_b, ["nextNavigation"]);
|
|
225
|
+
function initPlasmicLoaderWithCache(initFn, opts) {
|
|
229
226
|
const isBrowser = typeof window !== "undefined";
|
|
230
227
|
const isProd = process.env.NODE_ENV === "production";
|
|
231
228
|
const isBuildPhase = process.env.NEXT_PHASE === import_constants.PHASE_PRODUCTION_BUILD;
|
|
@@ -237,7 +234,8 @@ function initPlasmicLoaderWithCache(initFn, _a) {
|
|
|
237
234
|
platform: "nextjs",
|
|
238
235
|
platformOptions: {
|
|
239
236
|
nextjs: {
|
|
240
|
-
appDir:
|
|
237
|
+
appDir: true
|
|
238
|
+
// always true now that we require next@>=13
|
|
241
239
|
}
|
|
242
240
|
},
|
|
243
241
|
// For Nextjs 12, revalidate may in fact re-use an existing instance
|
|
@@ -350,6 +348,7 @@ function wrapRouterContext(element) {
|
|
|
350
348
|
}
|
|
351
349
|
|
|
352
350
|
// src/index.tsx
|
|
351
|
+
var import_loader_react2 = require("@plasmicapp/loader-react");
|
|
353
352
|
var reactMajorVersion = +React2.version.split(".")[0];
|
|
354
353
|
function filterCodeFromRenderData(data) {
|
|
355
354
|
if (reactMajorVersion >= 18 && !!data.bundle.bundleKey) {
|
|
@@ -455,13 +454,9 @@ function initPlasmicLoader(opts) {
|
|
|
455
454
|
loader.registerModules({
|
|
456
455
|
"next/head": import_head.default,
|
|
457
456
|
"next/link": import_link.default,
|
|
457
|
+
"next/navigation": NextNavigation,
|
|
458
458
|
"next/router": NextRouter
|
|
459
459
|
});
|
|
460
|
-
if (opts.nextNavigation) {
|
|
461
|
-
loader.registerModules({
|
|
462
|
-
"next/navigation": opts.nextNavigation
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
460
|
return loader;
|
|
466
461
|
}
|
|
467
462
|
function extractPlasmicQueryData(element) {
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.tsx", "../src/cache.ts", "../src/server-require.ts", "../src/mocks.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { CodeModule } from \"@plasmicapp/loader-core\";\nimport {\n PlasmicRootProvider as CommonPlasmicRootProvider,\n ComponentLookupSpec,\n FetchComponentDataOpts as InternalFetchComponentDataOpts,\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n extractPlasmicQueryData as internalExtractPlasmicQueryData,\n} from \"@plasmicapp/loader-react\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nexport {\n DataCtxReader,\n DataProvider,\n GlobalActionsContext,\n GlobalActionsProvider,\n PageParamsProvider,\n PlasmicCanvasContext,\n PlasmicCanvasHost,\n PlasmicComponent,\n PlasmicTranslatorContext,\n plasmicPrepass,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasComponentInfo,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\n CustomFunctionMeta,\n PlasmicTranslator,\n PropType,\n TokenRegistration,\n} from \"@plasmicapp/loader-react\";\nexport { ExtractPlasmicQueryData as __EXPERMIENTAL__ExtractPlasmicQueryData } from \"@plasmicapp/nextjs-app-router\";\nexport * from \"./shared-exports\";\n// NextHead and NextLink must be default imported (`import Pkg`) instead of a namespace import (`import * as Pkg`).\n// Otherwise, there's a Next.js 12 bug when referencing these dependencies due to default import interop.\n// The transpiled CommonJS code would create a `default` field on the package,\n// causing React to think it's an invalid React object:\n// ```\n// const NextHead = __defaultInterop(require('next/head.js'))\n// assert(typeof NextHead === 'object')\n// assert(typeof NextHead.default === 'function')\n// ```\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport * as NextRouter from \"next/router.js\";\nimport Script from \"next/script\";\nimport * as React from \"react\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport { wrapRouterContext } from \"./mocks\";\nimport type { ComponentRenderData, NextInitOptions } from \"./shared-exports\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: Partial<{\n [key: string]: string;\n }>;\n};\n\nconst reactMajorVersion = +React.version.split(\".\")[0];\n\nfunction filterCodeFromRenderData(data: ComponentRenderData) {\n if (reactMajorVersion >= 18 && !!data.bundle.bundleKey) {\n // Keep the entrypoints\n const entrypoints = new Set([\n ...data.entryCompMetas.map((compMeta) => compMeta.entry),\n \"root-provider.js\",\n ...data.bundle.projects\n .map((x) => x.globalContextsProviderFileName)\n .filter((x) => !!x),\n ...data.bundle.components\n .filter((c) => c.isGlobalContextProvider)\n .map((c) => c.entry),\n ...data.bundle.globalGroups.map((g) => g.contextFile),\n ]);\n\n data.bundle.modules.browser = data.bundle.modules.browser.map((module) => {\n if (module.type !== \"code\" || entrypoints.has(module.fileName)) {\n return module;\n }\n return { ...module, code: \"\" };\n });\n }\n}\n\nexport interface FetchComponentDataOpts extends InternalFetchComponentDataOpts {\n /**\n * Defer loading code chunks to script tags, reducing initial payload size.\n */\n deferChunks?: boolean;\n}\n\nexport class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {\n constructor(internal: InternalPlasmicComponentLoader) {\n super(internal);\n }\n\n async getActiveVariation(opts: {\n req?: ServerRequest;\n res?: ServerResponse;\n known?: Record<string, string>;\n traits: Record<string, string | number | boolean>;\n }) {\n const extractBuiltinTraits = () => {\n const url = new URL(\n opts.req?.url ?? \"/\",\n `https://${opts.req?.headers.host ?? \"server.side\"}`\n );\n return {\n pageUrl: url.href,\n };\n };\n\n return this._getActiveVariation({\n enableUnseededExperiments: true,\n traits: {\n ...extractBuiltinTraits(),\n ...opts.traits,\n },\n getKnownValue: (key: string) => {\n if (opts.known) {\n return opts.known[key];\n } else {\n return opts.req?.cookies[`plasmic:${key}`] ?? undefined;\n }\n },\n updateKnownValue: (key: string, value: string) => {\n if (opts.res) {\n const cookie = `plasmic:${key}=${value}`;\n const resCookie = opts.res?.getHeader(\"Set-Cookie\") ?? [];\n let newCookies: string[] = [];\n if (Array.isArray(resCookie)) {\n newCookies = [...resCookie, `plasmic:${key}=${value}`];\n } else {\n newCookies = [`${resCookie}`, cookie];\n }\n\n opts.res?.setHeader(\"Set-Cookie\", newCookies);\n }\n },\n });\n }\n\n maybeFetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData | null>;\n maybeFetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData | null>;\n async maybeFetchComponentData(\n ...args: any[]\n ): Promise<ComponentRenderData | null> {\n const data = await super.maybeFetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n data &&\n (opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault))\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n\n fetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData>;\n fetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData>;\n async fetchComponentData(...args: any[]): Promise<ComponentRenderData> {\n const data = await super.fetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault)\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n}\n\nfunction parseFetchComponentDataArgs(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n): { specs: ComponentLookupSpec[]; opts?: FetchComponentDataOpts };\nfunction parseFetchComponentDataArgs(...specs: ComponentLookupSpec[]): {\n specs: ComponentLookupSpec[];\n opts?: FetchComponentDataOpts;\n};\nfunction parseFetchComponentDataArgs(...args: any[]) {\n let specs: ComponentLookupSpec[];\n let opts: FetchComponentDataOpts | undefined;\n if (Array.isArray(args[0])) {\n specs = args[0];\n opts = args[1];\n } else {\n specs = args;\n opts = undefined;\n }\n return { specs, opts };\n}\n\nexport function initPlasmicLoader(opts: NextInitOptions) {\n const loader = initPlasmicLoaderWithCache<NextJsPlasmicComponentLoader>(\n (opts) =>\n new NextJsPlasmicComponentLoader(\n new InternalPlasmicComponentLoader(opts)\n ),\n opts\n );\n loader.registerModules({\n \"next/head\": NextHead,\n \"next/link\": NextLink,\n \"next/router\": NextRouter,\n });\n if (opts.nextNavigation) {\n loader.registerModules({\n \"next/navigation\": opts.nextNavigation,\n });\n }\n return loader;\n}\n\n/**\n * Performs a prepass over Plasmic content, kicking off the necessary\n * data fetches, and populating the fetched data into a cache. This\n * cache can be passed as prefetchedQueryData into PlasmicRootProvider.\n *\n * To limit rendering errors that can occur when you do this, we recommend\n * that you pass in _only_ the PlasmicComponents that you are planning to use\n * as the argument. For example:\n *\n * const cache = await extractPlasmicQueryData(\n * <PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>\n * <PlasmicComponent component=\"Home\" componentProps={{\n * // Specify the component prop overrides you are planning to use\n * // to render the page, as they may change what data is fetched.\n * ...\n * }} />\n * <PlasmicComponent component=\"NavBar\" componentProps={{\n * ...\n * }} />\n * ...\n * </PlasmicRootProvider>\n * );\n *\n * If your PlasmicComponent will be wrapping components that require special\n * context set up, you should also wrap the element above with those context\n * providers.\n *\n * You should avoid passing in elements that are not related to Plasmic, as any\n * rendering errors from those elements during the prepass may result in data\n * not being populated in the cache.\n *\n * @param element a React element containing instances of PlasmicComponent.\n * Will attempt to satisfy all data needs from usePlasmicDataQuery()\n * in this element tree.\n * @returns an object mapping query key to fetched data\n */\nexport async function extractPlasmicQueryData(element: React.ReactElement) {\n return internalExtractPlasmicQueryData(await wrapRouterContext(element));\n}\n\nconst PlasmicNextLink = React.forwardRef(function PlasmicNextLink(\n props: React.ComponentProps<typeof NextLink>,\n ref: React.Ref<HTMLAnchorElement>\n) {\n // Basically renders NextLink, except when href is undefined,\n // which freaks out NextLink :-/\n if (props.href) {\n const {\n href,\n replace,\n scroll,\n shallow,\n passHref,\n prefetch,\n locale,\n ...rest\n } = props;\n // If this is a fragment identifier link, then we set\n // scroll={false} so that smooth scrolling works\n const isFragment = typeof href === \"string\" && href.startsWith(\"#\");\n // We use legacyBehavior, because we don't know which\n // version of next the user has installed\n return (\n <NextLink\n href={href}\n replace={replace}\n scroll={scroll != null ? scroll : isFragment ? false : undefined}\n shallow={shallow}\n passHref={passHref}\n prefetch={prefetch}\n locale={locale}\n {...({ legacyBehavior: true } as any)}\n >\n <a {...rest} ref={ref} />\n </NextLink>\n );\n } else {\n return <a {...props} href={undefined} ref={ref} />;\n }\n});\n\nexport function PlasmicRootProvider(\n // We omit Head but still allow override for Link\n props: Omit<\n React.ComponentProps<typeof CommonPlasmicRootProvider>,\n \"Head\"\n > & { skipChunks?: boolean }\n) {\n return (\n <>\n {!props.skipChunks &&\n renderDynamicPayloadScripts(props.loader, props.prefetchedData)}\n <CommonPlasmicRootProvider\n Head={NextHead}\n Link={PlasmicNextLink}\n {...props}\n />\n </>\n );\n}\n\nfunction renderDynamicPayloadScripts(\n loader: PlasmicComponentLoader,\n prefetchedData: ComponentRenderData | undefined\n) {\n const missingModulesData =\n prefetchedData &&\n prefetchedData.bundle.modules.browser.filter(\n (module): module is CodeModule => module.type === \"code\" && !module.code\n );\n if (!missingModulesData || missingModulesData.length === 0) {\n return null;\n }\n\n const isBrowser = typeof window !== \"undefined\";\n\n if (isBrowser) {\n // `next/script` seems to not be correctly added to `<head>` in the initial\n // HTML sometimes when using custom documents:\n // https://linear.app/plasmic/issue/PLA-10652\n\n // Make sure to create the promises in this case - the script to actually fetch\n // the chunks will be added once hydration is completed.\n if (!(globalThis as any).__PlasmicBundlePromises) {\n (globalThis as any).__PlasmicBundlePromises = {};\n }\n for (const { fileName } of missingModulesData) {\n if (!(globalThis as any).__PlasmicBundlePromises[fileName]) {\n (globalThis as any).__PlasmicBundlePromises[fileName] = new Promise(\n (resolve) => {\n (globalThis as any).__PlasmicBundlePromises[\n \"__promise_resolve_\" + fileName\n ] = resolve;\n }\n );\n }\n }\n }\n\n return (\n <>\n <Script\n strategy=\"beforeInteractive\"\n key={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n dangerouslySetInnerHTML={{\n __html: `\n if (!globalThis.__PlasmicBundlePromises) {\n globalThis.__PlasmicBundlePromises = {};\n }\n ${missingModulesData\n .map(\n (\n module\n ) => `if (!globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}]) {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}] = new Promise((resolve) => {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n \"__promise_resolve_\" + module.fileName\n )}] = resolve;\n })\n }\n `\n )\n .join(\"\\n\")}`.trim(),\n }}\n ></Script>\n <Script\n strategy=\"beforeInteractive\"\n key={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n defer\n async\n src={loader.getChunksUrl(prefetchedData.bundle, missingModulesData)}\n />\n </>\n );\n}\n", "import { LoaderBundleOutput } from \"@plasmicapp/loader-core\";\nimport type { InitOptions } from \"@plasmicapp/loader-react/react-server-conditional\";\nimport type * as Watcher from \"@plasmicapp/watcher\";\nimport { PHASE_PRODUCTION_BUILD } from \"next/constants\";\nimport path from \"path\";\nimport { serverRequire, serverRequireFs } from \"./server-require\";\nimport type { NextInitOptions } from \"./shared-exports\";\n\nclass FileCache {\n constructor(private filePath: string) {}\n\n async get() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n const data = (await fs.promises.readFile(this.filePath)).toString();\n return JSON.parse(data);\n } catch {\n return undefined;\n }\n }\n\n async set(data: LoaderBundleOutput) {\n const fs = await serverRequireFs();\n try {\n await fs.promises.writeFile(this.filePath, JSON.stringify(data));\n } catch (err) {\n console.warn(`Error writing to Plasmic cache: ${err}`);\n }\n }\n\n async clear() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction hashString(str: string) {\n let h = 0,\n i = 0;\n for (; i < str.length; h &= h) h = 31 * h + str.charCodeAt(i++);\n return Math.abs(h);\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${hashString(\n [...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")\n )}${opts.preview ? \"-preview\" : \"\"}-cache.json`\n );\n return new FileCache(cachePath);\n}\n\nexport function initPlasmicLoaderWithCache<\n T extends {\n clearCache(): void;\n }\n>(\n initFn: (opts: InitOptions) => T,\n { nextNavigation, ...opts }: NextInitOptions\n): T {\n const isBrowser = typeof window !== \"undefined\";\n const isProd = process.env.NODE_ENV === \"production\";\n const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;\n const cache = isBrowser || isProd ? undefined : makeCache(opts);\n const loader = initFn({\n onClientSideFetch: \"warn\",\n ...opts,\n cache,\n platform: \"nextjs\",\n platformOptions: {\n nextjs: {\n appDir: !!nextNavigation,\n },\n },\n // For Nextjs 12, revalidate may in fact re-use an existing instance\n // of PlasmicComponentLoader that's already in memory, so we need to\n // make sure we don't re-use the data cached in memory.\n // We also enforce this for dev mode, so that we don't have to restart\n // the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader\n // We also enforce that during build phase, we re-use the data cached in memory\n // to avoid re-fetching the data from Plasmic servers.\n alwaysFresh: !isBuildPhase && !isBrowser,\n });\n\n if (!isProd) {\n const stringOpts = JSON.stringify(opts);\n\n if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {\n console.warn(\n `PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.\\n`\n );\n }\n\n process.env.PLASMIC_OPTS = stringOpts;\n }\n\n if (cache) {\n if (!isProd) {\n if (process.env.PLASMIC_WATCHED !== \"true\") {\n (async () => {\n process.env.PLASMIC_WATCHED = \"true\";\n console.log(`Subscribing to Plasmic changes...`);\n\n // Import using serverRequire, so webpack doesn't bundle us into client bundle\n try {\n const PlasmicRemoteChangeWatcher = (\n await serverRequire<typeof Watcher>(\"@plasmicapp/watcher\")\n ).PlasmicRemoteChangeWatcher;\n const watcher = new PlasmicRemoteChangeWatcher({\n projects: opts.projects,\n host: opts.host,\n });\n\n const clearCache = () => {\n cache.clear();\n loader.clearCache();\n };\n\n watcher.subscribe({\n onUpdate: () => {\n if (opts.preview) {\n clearCache();\n }\n },\n onPublish: () => {\n if (!opts.preview) {\n clearCache();\n }\n },\n });\n } catch (e) {\n console.warn(\"Couldn't subscribe to Plasmic changes\", e);\n }\n })();\n }\n } else {\n cache.clear();\n loader.clearCache();\n }\n }\n return loader;\n}\n", "import type * as FS from \"fs\";\n\nlet secretRequire: ((module: string) => any) | undefined;\ntry {\n // Secretly use require/import without webpack knowing\n // eslint-disable-next-line\n secretRequire = eval(\"require\");\n} catch (err) {\n try {\n // eslint-disable-next-line\n secretRequire = eval(\"(module) => import(module)\");\n } catch (err) {\n secretRequire = undefined;\n }\n}\n\nexport async function serverRequire<T>(module: string): Promise<T> {\n if (!secretRequire) {\n throw new Error(\n `Unexpected serverRequire() -- can only do this from a Node server!`\n );\n }\n return secretRequire(module) as Promise<T>;\n}\n\nexport async function tryServerRequire<T>(\n module: string\n): Promise<T | undefined> {\n try {\n const require = await serverRequire<T>(module);\n return require;\n } catch {\n return undefined;\n }\n}\n\nexport async function tryServerRequires<T>(\n modules: string[]\n): Promise<T | undefined> {\n for (const module of modules) {\n const require = await tryServerRequire<T>(module);\n if (require != null) {\n return require;\n }\n }\n return undefined;\n}\n\nexport async function serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n", "import type * as RouterContextType from \"next/dist/shared/lib/router-context.shared-runtime\";\nimport type { NextRouter } from \"next/router\";\nimport * as React from \"react\";\nimport { tryServerRequires } from \"./server-require\";\n\nconst fakeRouter: NextRouter = {\n push: async () => {\n return true;\n },\n replace: async () => {\n return true;\n },\n reload: () => {},\n back: () => {},\n forward: () => {},\n prefetch: async () => {\n return;\n },\n beforePopState: () => {},\n events: {\n on: () => {},\n off: () => {},\n emit: () => {},\n },\n route: \"/\",\n asPath: \"/\",\n basePath: \"/\",\n pathname: \"/\",\n query: {},\n isFallback: false,\n isLocaleDomain: false,\n isReady: true,\n isPreview: false,\n};\n\nexport async function wrapRouterContext(element: React.ReactElement) {\n const RouterContext = (\n await tryServerRequires<typeof RouterContextType>([\n \"next/dist/shared/lib/router-context.shared-runtime\",\n \"next/dist/shared/lib/router-context\",\n ])\n )?.RouterContext;\n return !!RouterContext?.Provider ? (\n <RouterContext.Provider value={fakeRouter}>\n {element}\n </RouterContext.Provider>\n ) : (\n element\n );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import type { CodeModule } from \"@plasmicapp/loader-core\";\nimport {\n PlasmicRootProvider as CommonPlasmicRootProvider,\n ComponentLookupSpec,\n FetchComponentDataOpts as InternalFetchComponentDataOpts,\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n extractPlasmicQueryData as internalExtractPlasmicQueryData,\n} from \"@plasmicapp/loader-react\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport * as NextNavigation from \"next/navigation.js\";\nimport * as NextRouter from \"next/router.js\";\nimport Script from \"next/script\";\nimport * as React from \"react\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport { wrapRouterContext } from \"./mocks\";\nimport type { ComponentRenderData, InitOptions } from \"./shared-exports\";\n\nexport * from \"./shared-exports\";\n\n// client-only exports\nexport {\n DataCtxReader,\n DataProvider,\n GlobalActionsContext,\n GlobalActionsProvider,\n PageParamsProvider,\n PlasmicCanvasContext,\n PlasmicCanvasHost,\n PlasmicComponent,\n PlasmicTranslatorContext,\n plasmicPrepass,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasComponentInfo,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\n CustomFunctionMeta,\n PlasmicTranslator,\n PropType,\n TokenRegistration,\n} from \"@plasmicapp/loader-react\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: Partial<{\n [key: string]: string;\n }>;\n};\n\nconst reactMajorVersion = +React.version.split(\".\")[0];\n\nfunction filterCodeFromRenderData(data: ComponentRenderData) {\n if (reactMajorVersion >= 18 && !!data.bundle.bundleKey) {\n // Keep the entrypoints\n const entrypoints = new Set([\n ...data.entryCompMetas.map((compMeta) => compMeta.entry),\n \"root-provider.js\",\n ...data.bundle.projects\n .map((x) => x.globalContextsProviderFileName)\n .filter((x) => !!x),\n ...data.bundle.components\n .filter((c) => c.isGlobalContextProvider)\n .map((c) => c.entry),\n ...data.bundle.globalGroups.map((g) => g.contextFile),\n ]);\n\n data.bundle.modules.browser = data.bundle.modules.browser.map((module) => {\n if (module.type !== \"code\" || entrypoints.has(module.fileName)) {\n return module;\n }\n return { ...module, code: \"\" };\n });\n }\n}\n\nexport interface FetchComponentDataOpts extends InternalFetchComponentDataOpts {\n /**\n * Defer loading code chunks to script tags, reducing initial payload size.\n */\n deferChunks?: boolean;\n}\n\nexport class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {\n constructor(internal: InternalPlasmicComponentLoader) {\n super(internal);\n }\n\n async getActiveVariation(opts: {\n req?: ServerRequest;\n res?: ServerResponse;\n known?: Record<string, string>;\n traits: Record<string, string | number | boolean>;\n }) {\n const extractBuiltinTraits = () => {\n const url = new URL(\n opts.req?.url ?? \"/\",\n `https://${opts.req?.headers.host ?? \"server.side\"}`\n );\n return {\n pageUrl: url.href,\n };\n };\n\n return this._getActiveVariation({\n enableUnseededExperiments: true,\n traits: {\n ...extractBuiltinTraits(),\n ...opts.traits,\n },\n getKnownValue: (key: string) => {\n if (opts.known) {\n return opts.known[key];\n } else {\n return opts.req?.cookies[`plasmic:${key}`] ?? undefined;\n }\n },\n updateKnownValue: (key: string, value: string) => {\n if (opts.res) {\n const cookie = `plasmic:${key}=${value}`;\n const resCookie = opts.res?.getHeader(\"Set-Cookie\") ?? [];\n let newCookies: string[] = [];\n if (Array.isArray(resCookie)) {\n newCookies = [...resCookie, `plasmic:${key}=${value}`];\n } else {\n newCookies = [`${resCookie}`, cookie];\n }\n\n opts.res?.setHeader(\"Set-Cookie\", newCookies);\n }\n },\n });\n }\n\n maybeFetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData | null>;\n maybeFetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData | null>;\n async maybeFetchComponentData(\n ...args: any[]\n ): Promise<ComponentRenderData | null> {\n const data = await super.maybeFetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n data &&\n (opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault))\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n\n fetchComponentData(\n ...specs: ComponentLookupSpec[]\n ): Promise<ComponentRenderData>;\n fetchComponentData(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n ): Promise<ComponentRenderData>;\n async fetchComponentData(...args: any[]): Promise<ComponentRenderData> {\n const data = await super.fetchComponentData(...args);\n const { opts } = parseFetchComponentDataArgs(...args);\n if (\n opts?.deferChunks ||\n (opts?.deferChunks === undefined && data.bundle.deferChunksByDefault)\n ) {\n filterCodeFromRenderData(data);\n }\n return data;\n }\n}\n\nfunction parseFetchComponentDataArgs(\n specs: ComponentLookupSpec[],\n opts?: FetchComponentDataOpts\n): { specs: ComponentLookupSpec[]; opts?: FetchComponentDataOpts };\nfunction parseFetchComponentDataArgs(...specs: ComponentLookupSpec[]): {\n specs: ComponentLookupSpec[];\n opts?: FetchComponentDataOpts;\n};\nfunction parseFetchComponentDataArgs(...args: any[]) {\n let specs: ComponentLookupSpec[];\n let opts: FetchComponentDataOpts | undefined;\n if (Array.isArray(args[0])) {\n specs = args[0];\n opts = args[1];\n } else {\n specs = args;\n opts = undefined;\n }\n return { specs, opts };\n}\n\nexport function initPlasmicLoader(\n opts: InitOptions\n): NextJsPlasmicComponentLoader {\n const loader = initPlasmicLoaderWithCache<NextJsPlasmicComponentLoader>(\n (opts) =>\n new NextJsPlasmicComponentLoader(\n new InternalPlasmicComponentLoader(opts)\n ),\n opts\n );\n loader.registerModules({\n \"next/head\": NextHead,\n \"next/link\": NextLink,\n \"next/navigation\": NextNavigation,\n \"next/router\": NextRouter,\n });\n return loader;\n}\n\n/**\n * Performs a prepass over Plasmic content, kicking off the necessary\n * data fetches, and populating the fetched data into a cache. This\n * cache can be passed as prefetchedQueryData into PlasmicRootProvider.\n *\n * To limit rendering errors that can occur when you do this, we recommend\n * that you pass in _only_ the PlasmicComponents that you are planning to use\n * as the argument. For example:\n *\n * const cache = await extractPlasmicQueryData(\n * <PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>\n * <PlasmicComponent component=\"Home\" componentProps={{\n * // Specify the component prop overrides you are planning to use\n * // to render the page, as they may change what data is fetched.\n * ...\n * }} />\n * <PlasmicComponent component=\"NavBar\" componentProps={{\n * ...\n * }} />\n * ...\n * </PlasmicRootProvider>\n * );\n *\n * If your PlasmicComponent will be wrapping components that require special\n * context set up, you should also wrap the element above with those context\n * providers.\n *\n * You should avoid passing in elements that are not related to Plasmic, as any\n * rendering errors from those elements during the prepass may result in data\n * not being populated in the cache.\n *\n * @param element a React element containing instances of PlasmicComponent.\n * Will attempt to satisfy all data needs from usePlasmicDataQuery()\n * in this element tree.\n * @returns an object mapping query key to fetched data\n */\nexport async function extractPlasmicQueryData(element: React.ReactElement) {\n return internalExtractPlasmicQueryData(await wrapRouterContext(element));\n}\n\nconst PlasmicNextLink = React.forwardRef(function PlasmicNextLink(\n props: React.ComponentProps<typeof NextLink>,\n ref: React.Ref<HTMLAnchorElement>\n) {\n // Basically renders NextLink, except when href is undefined,\n // which freaks out NextLink :-/\n if (props.href) {\n const {\n href,\n replace,\n scroll,\n shallow,\n passHref,\n prefetch,\n locale,\n ...rest\n } = props;\n // If this is a fragment identifier link, then we set\n // scroll={false} so that smooth scrolling works\n const isFragment = typeof href === \"string\" && href.startsWith(\"#\");\n // We use legacyBehavior, because we don't know which\n // version of next the user has installed\n return (\n <NextLink\n href={href}\n replace={replace}\n scroll={scroll != null ? scroll : isFragment ? false : undefined}\n shallow={shallow}\n passHref={passHref}\n prefetch={prefetch}\n locale={locale}\n {...({ legacyBehavior: true } as any)}\n >\n <a {...rest} ref={ref} />\n </NextLink>\n );\n } else {\n return <a {...props} href={undefined} ref={ref} />;\n }\n});\n\nexport function PlasmicRootProvider(\n // We omit Head but still allow override for Link\n props: Omit<\n React.ComponentProps<typeof CommonPlasmicRootProvider>,\n \"Head\"\n > & { skipChunks?: boolean }\n) {\n return (\n <>\n {!props.skipChunks &&\n renderDynamicPayloadScripts(props.loader, props.prefetchedData)}\n <CommonPlasmicRootProvider\n Head={NextHead}\n Link={PlasmicNextLink}\n {...props}\n />\n </>\n );\n}\n\nfunction renderDynamicPayloadScripts(\n loader: PlasmicComponentLoader,\n prefetchedData: ComponentRenderData | undefined\n) {\n const missingModulesData =\n prefetchedData &&\n prefetchedData.bundle.modules.browser.filter(\n (module): module is CodeModule => module.type === \"code\" && !module.code\n );\n if (!missingModulesData || missingModulesData.length === 0) {\n return null;\n }\n\n const isBrowser = typeof window !== \"undefined\";\n\n if (isBrowser) {\n // `next/script` seems to not be correctly added to `<head>` in the initial\n // HTML sometimes when using custom documents:\n // https://linear.app/plasmic/issue/PLA-10652\n\n // Make sure to create the promises in this case - the script to actually fetch\n // the chunks will be added once hydration is completed.\n if (!(globalThis as any).__PlasmicBundlePromises) {\n (globalThis as any).__PlasmicBundlePromises = {};\n }\n for (const { fileName } of missingModulesData) {\n if (!(globalThis as any).__PlasmicBundlePromises[fileName]) {\n (globalThis as any).__PlasmicBundlePromises[fileName] = new Promise(\n (resolve) => {\n (globalThis as any).__PlasmicBundlePromises[\n \"__promise_resolve_\" + fileName\n ] = resolve;\n }\n );\n }\n }\n }\n\n return (\n <>\n <Script\n strategy=\"beforeInteractive\"\n key={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"init:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n dangerouslySetInnerHTML={{\n __html: `\n if (!globalThis.__PlasmicBundlePromises) {\n globalThis.__PlasmicBundlePromises = {};\n }\n ${missingModulesData\n .map(\n (\n module\n ) => `if (!globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}]) {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n module.fileName\n )}] = new Promise((resolve) => {\n globalThis.__PlasmicBundlePromises[${JSON.stringify(\n \"__promise_resolve_\" + module.fileName\n )}] = resolve;\n })\n }\n `\n )\n .join(\"\\n\")}`.trim(),\n }}\n ></Script>\n <Script\n strategy=\"beforeInteractive\"\n key={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n id={\"load:\" + missingModulesData.map((m) => m.fileName).join(\";\")}\n defer\n async\n src={loader.getChunksUrl(prefetchedData.bundle, missingModulesData)}\n />\n </>\n );\n}\n", "import { LoaderBundleOutput } from \"@plasmicapp/loader-core\";\nimport type { InitOptions } from \"@plasmicapp/loader-react/react-server-conditional\";\nimport type * as Watcher from \"@plasmicapp/watcher\";\nimport { PHASE_PRODUCTION_BUILD } from \"next/constants\";\nimport path from \"path\";\nimport { serverRequire, serverRequireFs } from \"./server-require\";\n\nclass FileCache {\n constructor(private filePath: string) {}\n\n async get() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n const data = (await fs.promises.readFile(this.filePath)).toString();\n return JSON.parse(data);\n } catch {\n return undefined;\n }\n }\n\n async set(data: LoaderBundleOutput) {\n const fs = await serverRequireFs();\n try {\n await fs.promises.writeFile(this.filePath, JSON.stringify(data));\n } catch (err) {\n console.warn(`Error writing to Plasmic cache: ${err}`);\n }\n }\n\n async clear() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction hashString(str: string) {\n let h = 0,\n i = 0;\n for (; i < str.length; h &= h) h = 31 * h + str.charCodeAt(i++);\n return Math.abs(h);\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${hashString(\n [...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")\n )}${opts.preview ? \"-preview\" : \"\"}-cache.json`\n );\n return new FileCache(cachePath);\n}\n\nexport function initPlasmicLoaderWithCache<\n T extends {\n clearCache(): void;\n }\n>(initFn: (opts: InitOptions) => T, opts: InitOptions): T {\n const isBrowser = typeof window !== \"undefined\";\n const isProd = process.env.NODE_ENV === \"production\";\n const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;\n const cache = isBrowser || isProd ? undefined : makeCache(opts);\n const loader = initFn({\n onClientSideFetch: \"warn\",\n ...opts,\n cache,\n platform: \"nextjs\",\n platformOptions: {\n nextjs: {\n appDir: true, // always true now that we require next@>=13\n },\n },\n // For Nextjs 12, revalidate may in fact re-use an existing instance\n // of PlasmicComponentLoader that's already in memory, so we need to\n // make sure we don't re-use the data cached in memory.\n // We also enforce this for dev mode, so that we don't have to restart\n // the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader\n // We also enforce that during build phase, we re-use the data cached in memory\n // to avoid re-fetching the data from Plasmic servers.\n alwaysFresh: !isBuildPhase && !isBrowser,\n });\n\n if (!isProd) {\n const stringOpts = JSON.stringify(opts);\n\n if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {\n console.warn(\n `PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.\\n`\n );\n }\n\n process.env.PLASMIC_OPTS = stringOpts;\n }\n\n if (cache) {\n if (!isProd) {\n if (process.env.PLASMIC_WATCHED !== \"true\") {\n (async () => {\n process.env.PLASMIC_WATCHED = \"true\";\n console.log(`Subscribing to Plasmic changes...`);\n\n // Import using serverRequire, so webpack doesn't bundle us into client bundle\n try {\n const PlasmicRemoteChangeWatcher = (\n await serverRequire<typeof Watcher>(\"@plasmicapp/watcher\")\n ).PlasmicRemoteChangeWatcher;\n const watcher = new PlasmicRemoteChangeWatcher({\n projects: opts.projects,\n host: opts.host,\n });\n\n const clearCache = () => {\n cache.clear();\n loader.clearCache();\n };\n\n watcher.subscribe({\n onUpdate: () => {\n if (opts.preview) {\n clearCache();\n }\n },\n onPublish: () => {\n if (!opts.preview) {\n clearCache();\n }\n },\n });\n } catch (e) {\n console.warn(\"Couldn't subscribe to Plasmic changes\", e);\n }\n })();\n }\n } else {\n cache.clear();\n loader.clearCache();\n }\n }\n return loader;\n}\n", "import type * as FS from \"fs\";\n\nlet secretRequire: ((module: string) => any) | undefined;\ntry {\n // Secretly use require/import without webpack knowing\n // eslint-disable-next-line\n secretRequire = eval(\"require\");\n} catch (err) {\n try {\n // eslint-disable-next-line\n secretRequire = eval(\"(module) => import(module)\");\n } catch (err) {\n secretRequire = undefined;\n }\n}\n\nexport async function serverRequire<T>(module: string): Promise<T> {\n if (!secretRequire) {\n throw new Error(\n `Unexpected serverRequire() -- can only do this from a Node server!`\n );\n }\n return secretRequire(module) as Promise<T>;\n}\n\nexport async function tryServerRequire<T>(\n module: string\n): Promise<T | undefined> {\n try {\n const require = await serverRequire<T>(module);\n return require;\n } catch {\n return undefined;\n }\n}\n\nexport async function tryServerRequires<T>(\n modules: string[]\n): Promise<T | undefined> {\n for (const module of modules) {\n const require = await tryServerRequire<T>(module);\n if (require != null) {\n return require;\n }\n }\n return undefined;\n}\n\nexport async function serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n", "import type * as RouterContextType from \"next/dist/shared/lib/router-context.shared-runtime\";\nimport type { NextRouter } from \"next/router\";\nimport * as React from \"react\";\nimport { tryServerRequires } from \"./server-require\";\n\nconst fakeRouter: NextRouter = {\n push: async () => {\n return true;\n },\n replace: async () => {\n return true;\n },\n reload: () => {},\n back: () => {},\n forward: () => {},\n prefetch: async () => {\n return;\n },\n beforePopState: () => {},\n events: {\n on: () => {},\n off: () => {},\n emit: () => {},\n },\n route: \"/\",\n asPath: \"/\",\n basePath: \"/\",\n pathname: \"/\",\n query: {},\n isFallback: false,\n isLocaleDomain: false,\n isReady: true,\n isPreview: false,\n};\n\nexport async function wrapRouterContext(element: React.ReactElement) {\n const RouterContext = (\n await tryServerRequires<typeof RouterContextType>([\n \"next/dist/shared/lib/router-context.shared-runtime\",\n \"next/dist/shared/lib/router-context\",\n ])\n )?.RouterContext;\n return !!RouterContext?.Provider ? (\n <RouterContext.Provider value={fakeRouter}>\n {element}\n </RouterContext.Provider>\n ) : (\n element\n );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAOO;AAEP,kBAAqB;AACrB,kBAAqB;AACrB,qBAAgC;AAChC,iBAA4B;AAC5B,oBAAmB;AACnB,IAAAA,SAAuB;;;ACZvB,uBAAuC;AACvC,kBAAiB;;;ACFjB,IAAI;AACJ,IAAI;AAGF,kBAAgB,KAAK,SAAS;AAChC,SAAS,KAAP;AACA,MAAI;AAEF,oBAAgB,KAAK,4BAA4B;AAAA,EACnD,SAASC,MAAP;AACA,oBAAgB;AAAA,EAClB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wB,QAAQ,GAAG;AAC1D,QAAC,WAAmB,wBAAwB,QAAQ,IAAI,IAAI;AAAA,UAC1D,CAAC,YAAY;AACX,YAAC,WAAmB,wBAClB,uBAAuB,QACzB,IAAI;AAAA,UACN;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SACE,4DACE;AAAA,IAAC,cAAAO;AAAA,IAAA;AAAA,MACC,UAAS;AAAA,MACT,KAAK,UAAU,mBAAmB,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG;AAAA,MACjE,IAAI,UAAU,mBAAmB,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG;AAAA,MAChE,yBAAyB;AAAA,QACvB,QAAQ;AAAA;AAAA;AAAA;AAAA,cAIJ,mBACC;AAAA,UACC,CACEP,YACG,2CAA2C,KAAK;AAAA,YACnDA,QAAO;AAAA,UACT;AAAA,uDACuC,KAAK;AAAA,YACxCA,QAAO;AAAA,UACT;AAAA,yDACuC,KAAK;AAAA,YACxC,uBAAuBA,QAAO;AAAA,UAChC;AAAA;AAAA;AAAA;AAAA,QAIN,EACC,KAAK,IAAI,IAAI,KAAK;AAAA,MACzB;AAAA;AAAA,EACD,GACD;AAAA,IAAC,cAAAO;AAAA,IAAA;AAAA,MACC,UAAS;AAAA,MACT,KAAK,UAAU,mBAAmB,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG;AAAA,MACjE,IAAI,UAAU,mBAAmB,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG;AAAA,MAChE,OAAK;AAAA,MACL,OAAK;AAAA,MACL,KAAK,OAAO,aAAa,eAAe,QAAQ,kBAAkB;AAAA;AAAA,EACpE,CACF;AAEJ;",
|
|
6
|
+
"names": ["React", "err", "module", "require", "path", "err", "import_loader_react", "module", "opts", "NextHead", "NextLink", "internalExtractPlasmicQueryData", "PlasmicNextLink", "CommonPlasmicRootProvider", "Script"]
|
|
7
7
|
}
|
package/dist/react-server.d.ts
CHANGED
|
@@ -1,191 +1,22 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
|
|
3
|
-
import { fetchExtractedHeadMetadata as __EXPERMIENTAL__fetchExtractedHeadMetadata } from '@plasmicapp/nextjs-app-router/react-server';
|
|
4
|
-
import { fetchExtractedQueryData as __EXPERMIENTAL__fetchExtractedQueryData } from '@plasmicapp/nextjs-app-router/react-server';
|
|
5
|
-
import { withPlasmicMetadata as __EXPERMIENTAL__withPlasmicMetadata } from '@plasmicapp/nextjs-app-router/react-server';
|
|
6
|
-
import { CodeComponentMeta } from '@plasmicapp/loader-react';
|
|
7
|
-
import { ComponentLookupSpec } from '@plasmicapp/loader-react';
|
|
8
3
|
import { ComponentMeta } from '@plasmicapp/loader-react/react-server-conditional';
|
|
9
4
|
import { ComponentRenderData } from '@plasmicapp/loader-react/react-server-conditional';
|
|
10
|
-
import {
|
|
11
|
-
import { DataCtxReader } from '@plasmicapp/loader-react';
|
|
12
|
-
import { DataProvider } from '@plasmicapp/loader-react';
|
|
13
|
-
import { ExtractPlasmicQueryData } from '@plasmicapp/nextjs-app-router';
|
|
14
|
-
import { FetchComponentDataOpts as FetchComponentDataOpts_2 } from '@plasmicapp/loader-react';
|
|
15
|
-
import { GlobalActionsContext } from '@plasmicapp/loader-react';
|
|
16
|
-
import { GlobalActionsProvider } from '@plasmicapp/loader-react';
|
|
17
|
-
import { IncomingMessage } from 'http';
|
|
5
|
+
import type { IncomingMessage } from 'http';
|
|
18
6
|
import { InitOptions } from '@plasmicapp/loader-react/react-server-conditional';
|
|
19
7
|
import { InternalPlasmicComponentLoader } from '@plasmicapp/loader-react/react-server';
|
|
20
|
-
import { InternalPlasmicComponentLoader as InternalPlasmicComponentLoader_2 } from '@plasmicapp/loader-react';
|
|
21
8
|
import { PageMeta } from '@plasmicapp/loader-react/react-server-conditional';
|
|
22
9
|
import { PageMetadata } from '@plasmicapp/loader-react/react-server-conditional';
|
|
23
|
-
import { PageParamsProvider } from '@plasmicapp/loader-react';
|
|
24
|
-
import { PlasmicCanvasContext } from '@plasmicapp/loader-react';
|
|
25
|
-
import { PlasmicCanvasHost } from '@plasmicapp/loader-react';
|
|
26
|
-
import { PlasmicComponent } from '@plasmicapp/loader-react';
|
|
27
10
|
import { PlasmicComponentLoader } from '@plasmicapp/loader-react/react-server';
|
|
28
|
-
import {
|
|
29
|
-
import { plasmicPrepass } from '@plasmicapp/loader-react';
|
|
30
|
-
import { PlasmicRootProvider as PlasmicRootProvider_2 } from '@plasmicapp/loader-react';
|
|
31
|
-
import { PlasmicTranslator } from '@plasmicapp/loader-react';
|
|
32
|
-
import { PlasmicTranslatorContext } from '@plasmicapp/loader-react';
|
|
33
|
-
import { PropType } from '@plasmicapp/loader-react';
|
|
34
|
-
import { default as React_2 } from 'react';
|
|
35
|
-
import * as React_3 from 'react';
|
|
36
|
-
import { repeatedElement } from '@plasmicapp/loader-react';
|
|
37
|
-
import { ServerResponse } from 'http';
|
|
38
|
-
import { TokenRegistration } from '@plasmicapp/loader-react';
|
|
39
|
-
import { useDataEnv } from '@plasmicapp/loader-react';
|
|
40
|
-
import { usePlasmicCanvasComponentInfo } from '@plasmicapp/loader-react';
|
|
41
|
-
import { usePlasmicCanvasContext } from '@plasmicapp/loader-react';
|
|
42
|
-
import { usePlasmicComponent } from '@plasmicapp/loader-react';
|
|
43
|
-
import { usePlasmicQueryData } from '@plasmicapp/loader-react';
|
|
44
|
-
import { useSelector } from '@plasmicapp/loader-react';
|
|
45
|
-
import { useSelectors } from '@plasmicapp/loader-react';
|
|
46
|
-
|
|
47
|
-
export declare const __EXPERMIENTAL__extractPlasmicQueryData: (element: React_2.ReactElement, loader: ClientExports.NextJsPlasmicComponentLoader) => Promise<Record<string, any>>;
|
|
48
|
-
|
|
49
|
-
export { __EXPERMIENTAL__fetchExtractedHeadMetadata }
|
|
50
|
-
|
|
51
|
-
export { __EXPERMIENTAL__fetchExtractedQueryData }
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Helper function to extract Plasmic data.
|
|
55
|
-
*
|
|
56
|
-
* Given the <PlasmicClientRootProvider> element and current pathname + search
|
|
57
|
-
* params, returns:
|
|
58
|
-
* - The extracted query data, if `plasmicSsr` search param is set
|
|
59
|
-
* - A copy of the root provider element with the extracted query data, otherwise
|
|
60
|
-
*/
|
|
61
|
-
export declare function __EXPERMIENTAL__withExtractPlasmicQueryData(plasmicRootProvider: React_2.ReactElement, { pathname, searchParams, }: {
|
|
62
|
-
pathname: string;
|
|
63
|
-
searchParams: Record<string, string | string[]> | undefined;
|
|
64
|
-
}): Promise<React_2.JSX.Element>;
|
|
65
|
-
|
|
66
|
-
export { __EXPERMIENTAL__withPlasmicMetadata }
|
|
67
|
-
|
|
68
|
-
declare namespace ClientExports {
|
|
69
|
-
export {
|
|
70
|
-
initPlasmicLoader_2 as initPlasmicLoader,
|
|
71
|
-
extractPlasmicQueryData,
|
|
72
|
-
PlasmicRootProvider,
|
|
73
|
-
DataCtxReader,
|
|
74
|
-
DataProvider,
|
|
75
|
-
GlobalActionsContext,
|
|
76
|
-
GlobalActionsProvider,
|
|
77
|
-
PageParamsProvider,
|
|
78
|
-
PlasmicCanvasContext,
|
|
79
|
-
PlasmicCanvasHost,
|
|
80
|
-
PlasmicComponent,
|
|
81
|
-
PlasmicTranslatorContext,
|
|
82
|
-
plasmicPrepass,
|
|
83
|
-
repeatedElement,
|
|
84
|
-
useDataEnv,
|
|
85
|
-
usePlasmicCanvasComponentInfo,
|
|
86
|
-
usePlasmicCanvasContext,
|
|
87
|
-
usePlasmicComponent,
|
|
88
|
-
usePlasmicQueryData,
|
|
89
|
-
useSelector,
|
|
90
|
-
useSelectors,
|
|
91
|
-
CodeComponentMeta,
|
|
92
|
-
CustomFunctionMeta,
|
|
93
|
-
PlasmicTranslator,
|
|
94
|
-
PropType,
|
|
95
|
-
TokenRegistration,
|
|
96
|
-
ExtractPlasmicQueryData as __EXPERMIENTAL__ExtractPlasmicQueryData,
|
|
97
|
-
FetchComponentDataOpts,
|
|
98
|
-
NextJsPlasmicComponentLoader_2 as NextJsPlasmicComponentLoader,
|
|
99
|
-
NextInitOptions,
|
|
100
|
-
ComponentMeta,
|
|
101
|
-
ComponentRenderData,
|
|
102
|
-
InitOptions,
|
|
103
|
-
PageMeta,
|
|
104
|
-
PageMetadata
|
|
105
|
-
}
|
|
106
|
-
}
|
|
11
|
+
import type { ServerResponse } from 'http';
|
|
107
12
|
|
|
108
13
|
export { ComponentMeta }
|
|
109
14
|
|
|
110
15
|
export { ComponentRenderData }
|
|
111
16
|
|
|
112
|
-
/**
|
|
113
|
-
* Performs a prepass over Plasmic content, kicking off the necessary
|
|
114
|
-
* data fetches, and populating the fetched data into a cache. This
|
|
115
|
-
* cache can be passed as prefetchedQueryData into PlasmicRootProvider.
|
|
116
|
-
*
|
|
117
|
-
* To limit rendering errors that can occur when you do this, we recommend
|
|
118
|
-
* that you pass in _only_ the PlasmicComponents that you are planning to use
|
|
119
|
-
* as the argument. For example:
|
|
120
|
-
*
|
|
121
|
-
* const cache = await extractPlasmicQueryData(
|
|
122
|
-
* <PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>
|
|
123
|
-
* <PlasmicComponent component="Home" componentProps={{
|
|
124
|
-
* // Specify the component prop overrides you are planning to use
|
|
125
|
-
* // to render the page, as they may change what data is fetched.
|
|
126
|
-
* ...
|
|
127
|
-
* }} />
|
|
128
|
-
* <PlasmicComponent component="NavBar" componentProps={{
|
|
129
|
-
* ...
|
|
130
|
-
* }} />
|
|
131
|
-
* ...
|
|
132
|
-
* </PlasmicRootProvider>
|
|
133
|
-
* );
|
|
134
|
-
*
|
|
135
|
-
* If your PlasmicComponent will be wrapping components that require special
|
|
136
|
-
* context set up, you should also wrap the element above with those context
|
|
137
|
-
* providers.
|
|
138
|
-
*
|
|
139
|
-
* You should avoid passing in elements that are not related to Plasmic, as any
|
|
140
|
-
* rendering errors from those elements during the prepass may result in data
|
|
141
|
-
* not being populated in the cache.
|
|
142
|
-
*
|
|
143
|
-
* @param element a React element containing instances of PlasmicComponent.
|
|
144
|
-
* Will attempt to satisfy all data needs from usePlasmicDataQuery()
|
|
145
|
-
* in this element tree.
|
|
146
|
-
* @returns an object mapping query key to fetched data
|
|
147
|
-
*/
|
|
148
|
-
declare function extractPlasmicQueryData(element: React_3.ReactElement): Promise<Record<string, any>>;
|
|
149
|
-
|
|
150
|
-
declare interface FetchComponentDataOpts extends FetchComponentDataOpts_2 {
|
|
151
|
-
/**
|
|
152
|
-
* Defer loading code chunks to script tags, reducing initial payload size.
|
|
153
|
-
*/
|
|
154
|
-
deferChunks?: boolean;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
17
|
export { InitOptions }
|
|
158
18
|
|
|
159
|
-
export declare function initPlasmicLoader(opts:
|
|
160
|
-
|
|
161
|
-
declare function initPlasmicLoader_2(opts: NextInitOptions): NextJsPlasmicComponentLoader_2;
|
|
162
|
-
|
|
163
|
-
export declare interface NextInitOptions extends InitOptions {
|
|
164
|
-
/**
|
|
165
|
-
* next/navigation doesn't exist prior to Next.js 13, so Plasmic can't assume the dependency exists.
|
|
166
|
-
* If you use the App Router (which depends on next/navigation), you'll need to pass the module here.
|
|
167
|
-
*
|
|
168
|
-
* ```tsx
|
|
169
|
-
* import { initPlasmicLoader } from "@plasmicapp/loader-nextjs/react-server-conditional";
|
|
170
|
-
* import * as NextNavigation from "next/navigation";
|
|
171
|
-
*
|
|
172
|
-
* export const PLASMIC = initPlasmicLoader({
|
|
173
|
-
* nextNavigation: NextNavigation,
|
|
174
|
-
* projects: [
|
|
175
|
-
* // your projects
|
|
176
|
-
* ],
|
|
177
|
-
* });
|
|
178
|
-
* ```
|
|
179
|
-
*/
|
|
180
|
-
nextNavigation?: {
|
|
181
|
-
notFound: unknown;
|
|
182
|
-
redirect: unknown;
|
|
183
|
-
useParams: unknown;
|
|
184
|
-
usePathname: unknown;
|
|
185
|
-
useRouter: unknown;
|
|
186
|
-
useSearchParams: unknown;
|
|
187
|
-
};
|
|
188
|
-
}
|
|
19
|
+
export declare function initPlasmicLoader(opts: InitOptions): NextJsPlasmicComponentLoader;
|
|
189
20
|
|
|
190
21
|
export declare class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {
|
|
191
22
|
constructor(internal: InternalPlasmicComponentLoader);
|
|
@@ -197,38 +28,14 @@ export declare class NextJsPlasmicComponentLoader extends PlasmicComponentLoader
|
|
|
197
28
|
}): Promise<Record<string, string>>;
|
|
198
29
|
}
|
|
199
30
|
|
|
200
|
-
declare class NextJsPlasmicComponentLoader_2 extends PlasmicComponentLoader_2 {
|
|
201
|
-
constructor(internal: InternalPlasmicComponentLoader_2);
|
|
202
|
-
getActiveVariation(opts: {
|
|
203
|
-
req?: ServerRequest_2;
|
|
204
|
-
res?: ServerResponse;
|
|
205
|
-
known?: Record<string, string>;
|
|
206
|
-
traits: Record<string, string | number | boolean>;
|
|
207
|
-
}): Promise<Record<string, string>>;
|
|
208
|
-
maybeFetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData | null>;
|
|
209
|
-
maybeFetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData | null>;
|
|
210
|
-
fetchComponentData(...specs: ComponentLookupSpec[]): Promise<ComponentRenderData>;
|
|
211
|
-
fetchComponentData(specs: ComponentLookupSpec[], opts?: FetchComponentDataOpts): Promise<ComponentRenderData>;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
31
|
export { PageMeta }
|
|
215
32
|
|
|
216
33
|
export { PageMetadata }
|
|
217
34
|
|
|
218
|
-
declare function PlasmicRootProvider(props: Omit<React_3.ComponentProps<typeof PlasmicRootProvider_2>, "Head"> & {
|
|
219
|
-
skipChunks?: boolean;
|
|
220
|
-
}): React_3.JSX.Element;
|
|
221
|
-
|
|
222
35
|
declare type ServerRequest = IncomingMessage & {
|
|
223
36
|
cookies: {
|
|
224
37
|
[key: string]: string;
|
|
225
38
|
};
|
|
226
39
|
};
|
|
227
40
|
|
|
228
|
-
declare type ServerRequest_2 = IncomingMessage & {
|
|
229
|
-
cookies: Partial<{
|
|
230
|
-
[key: string]: string;
|
|
231
|
-
}>;
|
|
232
|
-
};
|
|
233
|
-
|
|
234
41
|
export { }
|
package/dist/react-server.esm.js
CHANGED
|
@@ -17,18 +17,6 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
20
|
var __async = (__this, __arguments, generator) => {
|
|
33
21
|
return new Promise((resolve, reject) => {
|
|
34
22
|
var fulfilled = (value) => {
|
|
@@ -58,6 +46,7 @@ import {
|
|
|
58
46
|
} from "@plasmicapp/loader-react/react-server";
|
|
59
47
|
import NextHead from "next/head.js";
|
|
60
48
|
import NextLink from "next/link.js";
|
|
49
|
+
import NextNavigation from "next/navigation.js";
|
|
61
50
|
import * as NextRouter from "next/router.js";
|
|
62
51
|
|
|
63
52
|
// src/cache.ts
|
|
@@ -168,8 +157,7 @@ function makeCache(opts) {
|
|
|
168
157
|
);
|
|
169
158
|
return new FileCache(cachePath);
|
|
170
159
|
}
|
|
171
|
-
function initPlasmicLoaderWithCache(initFn,
|
|
172
|
-
var _b = _a, { nextNavigation } = _b, opts = __objRest(_b, ["nextNavigation"]);
|
|
160
|
+
function initPlasmicLoaderWithCache(initFn, opts) {
|
|
173
161
|
const isBrowser = typeof window !== "undefined";
|
|
174
162
|
const isProd = process.env.NODE_ENV === "production";
|
|
175
163
|
const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;
|
|
@@ -181,7 +169,8 @@ function initPlasmicLoaderWithCache(initFn, _a) {
|
|
|
181
169
|
platform: "nextjs",
|
|
182
170
|
platformOptions: {
|
|
183
171
|
nextjs: {
|
|
184
|
-
appDir:
|
|
172
|
+
appDir: true
|
|
173
|
+
// always true now that we require next@>=13
|
|
185
174
|
}
|
|
186
175
|
},
|
|
187
176
|
// For Nextjs 12, revalidate may in fact re-use an existing instance
|
|
@@ -245,14 +234,6 @@ function initPlasmicLoaderWithCache(initFn, _a) {
|
|
|
245
234
|
}
|
|
246
235
|
|
|
247
236
|
// src/react-server.tsx
|
|
248
|
-
import { __EXPERMIENTAL__extractPlasmicQueryData as internalExtractPlasmicQueryData } from "@plasmicapp/loader-react/react-server";
|
|
249
|
-
import { ExtractPlasmicQueryData } from "@plasmicapp/nextjs-app-router";
|
|
250
|
-
import {
|
|
251
|
-
fetchExtractedHeadMetadata,
|
|
252
|
-
fetchExtractedQueryData,
|
|
253
|
-
withPlasmicMetadata
|
|
254
|
-
} from "@plasmicapp/nextjs-app-router/react-server";
|
|
255
|
-
import React from "react";
|
|
256
237
|
var NextJsPlasmicComponentLoader = class extends PlasmicComponentLoader {
|
|
257
238
|
constructor(internal) {
|
|
258
239
|
super(internal);
|
|
@@ -305,54 +286,13 @@ function initPlasmicLoader(opts) {
|
|
|
305
286
|
loader.registerModules({
|
|
306
287
|
"next/head": NextHead,
|
|
307
288
|
"next/link": NextLink,
|
|
289
|
+
"next/navigation": NextNavigation,
|
|
308
290
|
"next/router": NextRouter
|
|
309
291
|
});
|
|
310
|
-
if (opts.nextNavigation) {
|
|
311
|
-
loader.registerModules({
|
|
312
|
-
"next/navigation": opts.nextNavigation
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
292
|
return loader;
|
|
316
293
|
}
|
|
317
|
-
var __EXPERMIENTAL__extractPlasmicQueryData = internalExtractPlasmicQueryData;
|
|
318
|
-
function __EXPERMIENTAL__withExtractPlasmicQueryData(_0, _1) {
|
|
319
|
-
return __async(this, arguments, function* (plasmicRootProvider, {
|
|
320
|
-
pathname,
|
|
321
|
-
searchParams
|
|
322
|
-
}) {
|
|
323
|
-
var _a, _b, _c;
|
|
324
|
-
const isPlasmicSsr = !!(searchParams == null ? void 0 : searchParams["plasmicSsr"]) && (searchParams == null ? void 0 : searchParams["plasmicSsr"]) !== "false";
|
|
325
|
-
if (isPlasmicSsr) {
|
|
326
|
-
return /* @__PURE__ */ React.createElement(ExtractPlasmicQueryData, null, plasmicRootProvider);
|
|
327
|
-
}
|
|
328
|
-
const prepassHost = (_c = (_a = process.env.PLASMIC_PREPASS_HOST) != null ? _a : process.env.VERCEL_URL && `https://${process.env.VERCEL_URL}`) != null ? _c : `http://localhost:${(_b = process.env.PORT) != null ? _b : 3e3}`;
|
|
329
|
-
const newSearchParams = new URLSearchParams(
|
|
330
|
-
Object.entries(searchParams != null ? searchParams : {}).flatMap(
|
|
331
|
-
([key, values]) => Array.isArray(values) ? values.map((v) => [key, v]) : [[key, values]]
|
|
332
|
-
)
|
|
333
|
-
);
|
|
334
|
-
newSearchParams.set("plasmicSsr", "true");
|
|
335
|
-
if (process.env.VERCEL_AUTOMATION_BYPASS_SECRET) {
|
|
336
|
-
newSearchParams.set(
|
|
337
|
-
"x-vercel-protection-bypass",
|
|
338
|
-
process.env.VERCEL_AUTOMATION_BYPASS_SECRET
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
const prefetchedQueryData = yield fetchExtractedQueryData(
|
|
342
|
-
`${prepassHost}${pathname}?${newSearchParams.toString()}`
|
|
343
|
-
);
|
|
344
|
-
return React.cloneElement(plasmicRootProvider, {
|
|
345
|
-
prefetchedQueryData
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
294
|
export {
|
|
350
295
|
NextJsPlasmicComponentLoader,
|
|
351
|
-
__EXPERMIENTAL__extractPlasmicQueryData,
|
|
352
|
-
fetchExtractedHeadMetadata as __EXPERMIENTAL__fetchExtractedHeadMetadata,
|
|
353
|
-
fetchExtractedQueryData as __EXPERMIENTAL__fetchExtractedQueryData,
|
|
354
|
-
__EXPERMIENTAL__withExtractPlasmicQueryData,
|
|
355
|
-
withPlasmicMetadata as __EXPERMIENTAL__withPlasmicMetadata,
|
|
356
296
|
initPlasmicLoader
|
|
357
297
|
};
|
|
358
298
|
//# sourceMappingURL=react-server.esm.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/react-server.tsx", "../src/cache.ts", "../src/server-require.ts"],
|
|
4
|
-
"sourcesContent": ["import \"server-only\";\n\nimport {\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n} from \"@plasmicapp/loader-react/react-server\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport * as NextRouter from \"next/router.js\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport type { NextInitOptions } from \"./shared-exports\";\n\nimport { __EXPERMIENTAL__extractPlasmicQueryData as internalExtractPlasmicQueryData } from \"@plasmicapp/loader-react/react-server\";\nimport { ExtractPlasmicQueryData } from \"@plasmicapp/nextjs-app-router\";\nimport {\n fetchExtractedHeadMetadata,\n fetchExtractedQueryData,\n withPlasmicMetadata,\n} from \"@plasmicapp/nextjs-app-router/react-server\";\n\nexport * from \"./shared-exports\";\nexport {\n fetchExtractedQueryData as __EXPERMIENTAL__fetchExtractedQueryData,\n fetchExtractedHeadMetadata as __EXPERMIENTAL__fetchExtractedHeadMetadata,\n withPlasmicMetadata as __EXPERMIENTAL__withPlasmicMetadata,\n};\n\nimport React from \"react\";\nimport type * as ClientExports from \".\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: {\n [key: string]: string;\n };\n};\n\nexport class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {\n constructor(internal: InternalPlasmicComponentLoader) {\n super(internal);\n }\n\n async getActiveVariation(opts: {\n req?: ServerRequest;\n res?: ServerResponse;\n known?: Record<string, string>;\n traits: Record<string, string | number | boolean>;\n }) {\n const extractBuiltinTraits = () => {\n const url = new URL(\n opts.req?.url ?? \"/\",\n `https://${opts.req?.headers.host ?? \"server.side\"}`\n );\n return {\n pageUrl: url.href,\n };\n };\n\n return this._getActiveVariation({\n traits: {\n ...extractBuiltinTraits(),\n ...opts.traits,\n },\n getKnownValue: (key: string) => {\n if (opts.known) {\n return opts.known[key];\n } else {\n return opts.req?.cookies[`plasmic:${key}`] ?? undefined;\n }\n },\n updateKnownValue: (key: string, value: string) => {\n if (opts.res) {\n const cookie = `plasmic:${key}=${value}`;\n const resCookie = opts.res?.getHeader(\"Set-Cookie\") ?? [];\n let newCookies: string[] = [];\n if (Array.isArray(resCookie)) {\n newCookies = [...resCookie, `plasmic:${key}=${value}`];\n } else {\n newCookies = [`${resCookie}`, cookie];\n }\n\n opts.res?.setHeader(\"Set-Cookie\", newCookies);\n }\n },\n });\n }\n}\n\nexport function initPlasmicLoader(opts: NextInitOptions) {\n const loader = initPlasmicLoaderWithCache<NextJsPlasmicComponentLoader>(\n (opts) =>\n new PlasmicComponentLoader(new InternalPlasmicComponentLoader(opts)),\n opts\n );\n loader.registerModules({\n \"next/head\": NextHead,\n \"next/link\": NextLink,\n \"next/router\": NextRouter,\n });\n if (opts.nextNavigation) {\n loader.registerModules({\n \"next/navigation\": opts.nextNavigation,\n });\n }\n return loader;\n}\n\nexport const __EXPERMIENTAL__extractPlasmicQueryData: (\n element: React.ReactElement,\n // We can't use `NextJsPlasmicComponentLoader` or `PlasmicComponentLoader`\n // types because they refer to the react-server version, which Typescript\n // doesn't recognize as compatible with the client version (whose type is\n // also the one exported from `react-server-conditional` imports).\n loader: ClientExports.NextJsPlasmicComponentLoader\n) => Promise<Record<string, any>> = internalExtractPlasmicQueryData as any;\n\n/**\n * Helper function to extract Plasmic data.\n *\n * Given the <PlasmicClientRootProvider> element and current pathname + search\n * params, returns:\n * - The extracted query data, if `plasmicSsr` search param is set\n * - A copy of the root provider element with the extracted query data, otherwise\n */\nexport async function __EXPERMIENTAL__withExtractPlasmicQueryData(\n plasmicRootProvider: React.ReactElement,\n {\n pathname,\n searchParams,\n }: {\n pathname: string;\n searchParams: Record<string, string | string[]> | undefined;\n }\n) {\n const isPlasmicSsr =\n !!searchParams?.[\"plasmicSsr\"] && searchParams?.[\"plasmicSsr\"] !== \"false\";\n\n // If `plasmicSsr` search param is set, just wrap the root provider inside\n // <ExtractPlasmicQueryData>\n if (isPlasmicSsr) {\n return (\n <ExtractPlasmicQueryData>{plasmicRootProvider}</ExtractPlasmicQueryData>\n );\n }\n\n // Otherwise, fetch the same endpoint, but setting `plasmicSsr` to extract the\n // query data.\n const prepassHost =\n process.env.PLASMIC_PREPASS_HOST ??\n (process.env.VERCEL_URL && `https://${process.env.VERCEL_URL}`) ??\n `http://localhost:${process.env.PORT ?? 3000}`;\n\n // Build a copy of the search params\n const newSearchParams = new URLSearchParams(\n Object.entries(searchParams ?? {}).flatMap(([key, values]) =>\n Array.isArray(values) ? values.map((v) => [key, v]) : [[key, values]]\n )\n );\n\n // Set `plasmicSsr` search param to indicate you are using this endpoint\n // to extract query data.\n newSearchParams.set(\"plasmicSsr\", \"true\");\n\n if (process.env.VERCEL_AUTOMATION_BYPASS_SECRET) {\n // If protection bypass is enabled, use it to ensure fetching from\n // the SSR endpoint will not return the authentication page HTML\n newSearchParams.set(\n \"x-vercel-protection-bypass\",\n process.env.VERCEL_AUTOMATION_BYPASS_SECRET\n );\n }\n\n // Fetch the data from the endpoint using the new search params\n const prefetchedQueryData = await fetchExtractedQueryData(\n `${prepassHost}${pathname}?${newSearchParams.toString()}`\n );\n\n // Provide the query data to <PlasmicClientRootProvider>\n return React.cloneElement(plasmicRootProvider, {\n prefetchedQueryData,\n });\n}\n", "import { LoaderBundleOutput } from \"@plasmicapp/loader-core\";\nimport type { InitOptions } from \"@plasmicapp/loader-react/react-server-conditional\";\nimport type * as Watcher from \"@plasmicapp/watcher\";\nimport { PHASE_PRODUCTION_BUILD } from \"next/constants\";\nimport path from \"path\";\nimport { serverRequire, serverRequireFs } from \"./server-require\";\nimport type { NextInitOptions } from \"./shared-exports\";\n\nclass FileCache {\n constructor(private filePath: string) {}\n\n async get() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n const data = (await fs.promises.readFile(this.filePath)).toString();\n return JSON.parse(data);\n } catch {\n return undefined;\n }\n }\n\n async set(data: LoaderBundleOutput) {\n const fs = await serverRequireFs();\n try {\n await fs.promises.writeFile(this.filePath, JSON.stringify(data));\n } catch (err) {\n console.warn(`Error writing to Plasmic cache: ${err}`);\n }\n }\n\n async clear() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction hashString(str: string) {\n let h = 0,\n i = 0;\n for (; i < str.length; h &= h) h = 31 * h + str.charCodeAt(i++);\n return Math.abs(h);\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${hashString(\n [...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")\n )}${opts.preview ? \"-preview\" : \"\"}-cache.json`\n );\n return new FileCache(cachePath);\n}\n\nexport function initPlasmicLoaderWithCache<\n T extends {\n clearCache(): void;\n }\n>(\n initFn: (opts: InitOptions) => T,\n { nextNavigation, ...opts }: NextInitOptions\n): T {\n const isBrowser = typeof window !== \"undefined\";\n const isProd = process.env.NODE_ENV === \"production\";\n const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;\n const cache = isBrowser || isProd ? undefined : makeCache(opts);\n const loader = initFn({\n onClientSideFetch: \"warn\",\n ...opts,\n cache,\n platform: \"nextjs\",\n platformOptions: {\n nextjs: {\n appDir: !!nextNavigation,\n },\n },\n // For Nextjs 12, revalidate may in fact re-use an existing instance\n // of PlasmicComponentLoader that's already in memory, so we need to\n // make sure we don't re-use the data cached in memory.\n // We also enforce this for dev mode, so that we don't have to restart\n // the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader\n // We also enforce that during build phase, we re-use the data cached in memory\n // to avoid re-fetching the data from Plasmic servers.\n alwaysFresh: !isBuildPhase && !isBrowser,\n });\n\n if (!isProd) {\n const stringOpts = JSON.stringify(opts);\n\n if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {\n console.warn(\n `PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.\\n`\n );\n }\n\n process.env.PLASMIC_OPTS = stringOpts;\n }\n\n if (cache) {\n if (!isProd) {\n if (process.env.PLASMIC_WATCHED !== \"true\") {\n (async () => {\n process.env.PLASMIC_WATCHED = \"true\";\n console.log(`Subscribing to Plasmic changes...`);\n\n // Import using serverRequire, so webpack doesn't bundle us into client bundle\n try {\n const PlasmicRemoteChangeWatcher = (\n await serverRequire<typeof Watcher>(\"@plasmicapp/watcher\")\n ).PlasmicRemoteChangeWatcher;\n const watcher = new PlasmicRemoteChangeWatcher({\n projects: opts.projects,\n host: opts.host,\n });\n\n const clearCache = () => {\n cache.clear();\n loader.clearCache();\n };\n\n watcher.subscribe({\n onUpdate: () => {\n if (opts.preview) {\n clearCache();\n }\n },\n onPublish: () => {\n if (!opts.preview) {\n clearCache();\n }\n },\n });\n } catch (e) {\n console.warn(\"Couldn't subscribe to Plasmic changes\", e);\n }\n })();\n }\n } else {\n cache.clear();\n loader.clearCache();\n }\n }\n return loader;\n}\n", "import type * as FS from \"fs\";\n\nlet secretRequire: ((module: string) => any) | undefined;\ntry {\n // Secretly use require/import without webpack knowing\n // eslint-disable-next-line\n secretRequire = eval(\"require\");\n} catch (err) {\n try {\n // eslint-disable-next-line\n secretRequire = eval(\"(module) => import(module)\");\n } catch (err) {\n secretRequire = undefined;\n }\n}\n\nexport async function serverRequire<T>(module: string): Promise<T> {\n if (!secretRequire) {\n throw new Error(\n `Unexpected serverRequire() -- can only do this from a Node server!`\n );\n }\n return secretRequire(module) as Promise<T>;\n}\n\nexport async function tryServerRequire<T>(\n module: string\n): Promise<T | undefined> {\n try {\n const require = await serverRequire<T>(module);\n return require;\n } catch {\n return undefined;\n }\n}\n\nexport async function tryServerRequires<T>(\n modules: string[]\n): Promise<T | undefined> {\n for (const module of modules) {\n const require = await tryServerRequire<T>(module);\n if (require != null) {\n return require;\n }\n }\n return undefined;\n}\n\nexport async function serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import \"server-only\";\n\nimport {\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n} from \"@plasmicapp/loader-react/react-server\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport NextNavigation from \"next/navigation.js\";\nimport * as NextRouter from \"next/router.js\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport type { InitOptions } from \"./shared-exports\";\n\nexport * from \"./shared-exports\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: {\n [key: string]: string;\n };\n};\n\nexport class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {\n constructor(internal: InternalPlasmicComponentLoader) {\n super(internal);\n }\n\n async getActiveVariation(opts: {\n req?: ServerRequest;\n res?: ServerResponse;\n known?: Record<string, string>;\n traits: Record<string, string | number | boolean>;\n }) {\n const extractBuiltinTraits = () => {\n const url = new URL(\n opts.req?.url ?? \"/\",\n `https://${opts.req?.headers.host ?? \"server.side\"}`\n );\n return {\n pageUrl: url.href,\n };\n };\n\n return this._getActiveVariation({\n traits: {\n ...extractBuiltinTraits(),\n ...opts.traits,\n },\n getKnownValue: (key: string) => {\n if (opts.known) {\n return opts.known[key];\n } else {\n return opts.req?.cookies[`plasmic:${key}`] ?? undefined;\n }\n },\n updateKnownValue: (key: string, value: string) => {\n if (opts.res) {\n const cookie = `plasmic:${key}=${value}`;\n const resCookie = opts.res?.getHeader(\"Set-Cookie\") ?? [];\n let newCookies: string[] = [];\n if (Array.isArray(resCookie)) {\n newCookies = [...resCookie, `plasmic:${key}=${value}`];\n } else {\n newCookies = [`${resCookie}`, cookie];\n }\n\n opts.res?.setHeader(\"Set-Cookie\", newCookies);\n }\n },\n });\n }\n}\n\nexport function initPlasmicLoader(\n opts: InitOptions\n): NextJsPlasmicComponentLoader {\n const loader = initPlasmicLoaderWithCache<NextJsPlasmicComponentLoader>(\n (opts) =>\n new PlasmicComponentLoader(new InternalPlasmicComponentLoader(opts)),\n opts\n );\n loader.registerModules({\n \"next/head\": NextHead,\n \"next/link\": NextLink,\n \"next/navigation\": NextNavigation,\n \"next/router\": NextRouter,\n });\n return loader;\n}\n", "import { LoaderBundleOutput } from \"@plasmicapp/loader-core\";\nimport type { InitOptions } from \"@plasmicapp/loader-react/react-server-conditional\";\nimport type * as Watcher from \"@plasmicapp/watcher\";\nimport { PHASE_PRODUCTION_BUILD } from \"next/constants\";\nimport path from \"path\";\nimport { serverRequire, serverRequireFs } from \"./server-require\";\n\nclass FileCache {\n constructor(private filePath: string) {}\n\n async get() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n const data = (await fs.promises.readFile(this.filePath)).toString();\n return JSON.parse(data);\n } catch {\n return undefined;\n }\n }\n\n async set(data: LoaderBundleOutput) {\n const fs = await serverRequireFs();\n try {\n await fs.promises.writeFile(this.filePath, JSON.stringify(data));\n } catch (err) {\n console.warn(`Error writing to Plasmic cache: ${err}`);\n }\n }\n\n async clear() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction hashString(str: string) {\n let h = 0,\n i = 0;\n for (; i < str.length; h &= h) h = 31 * h + str.charCodeAt(i++);\n return Math.abs(h);\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${hashString(\n [...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")\n )}${opts.preview ? \"-preview\" : \"\"}-cache.json`\n );\n return new FileCache(cachePath);\n}\n\nexport function initPlasmicLoaderWithCache<\n T extends {\n clearCache(): void;\n }\n>(initFn: (opts: InitOptions) => T, opts: InitOptions): T {\n const isBrowser = typeof window !== \"undefined\";\n const isProd = process.env.NODE_ENV === \"production\";\n const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;\n const cache = isBrowser || isProd ? undefined : makeCache(opts);\n const loader = initFn({\n onClientSideFetch: \"warn\",\n ...opts,\n cache,\n platform: \"nextjs\",\n platformOptions: {\n nextjs: {\n appDir: true, // always true now that we require next@>=13\n },\n },\n // For Nextjs 12, revalidate may in fact re-use an existing instance\n // of PlasmicComponentLoader that's already in memory, so we need to\n // make sure we don't re-use the data cached in memory.\n // We also enforce this for dev mode, so that we don't have to restart\n // the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader\n // We also enforce that during build phase, we re-use the data cached in memory\n // to avoid re-fetching the data from Plasmic servers.\n alwaysFresh: !isBuildPhase && !isBrowser,\n });\n\n if (!isProd) {\n const stringOpts = JSON.stringify(opts);\n\n if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {\n console.warn(\n `PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.\\n`\n );\n }\n\n process.env.PLASMIC_OPTS = stringOpts;\n }\n\n if (cache) {\n if (!isProd) {\n if (process.env.PLASMIC_WATCHED !== \"true\") {\n (async () => {\n process.env.PLASMIC_WATCHED = \"true\";\n console.log(`Subscribing to Plasmic changes...`);\n\n // Import using serverRequire, so webpack doesn't bundle us into client bundle\n try {\n const PlasmicRemoteChangeWatcher = (\n await serverRequire<typeof Watcher>(\"@plasmicapp/watcher\")\n ).PlasmicRemoteChangeWatcher;\n const watcher = new PlasmicRemoteChangeWatcher({\n projects: opts.projects,\n host: opts.host,\n });\n\n const clearCache = () => {\n cache.clear();\n loader.clearCache();\n };\n\n watcher.subscribe({\n onUpdate: () => {\n if (opts.preview) {\n clearCache();\n }\n },\n onPublish: () => {\n if (!opts.preview) {\n clearCache();\n }\n },\n });\n } catch (e) {\n console.warn(\"Couldn't subscribe to Plasmic changes\", e);\n }\n })();\n }\n } else {\n cache.clear();\n loader.clearCache();\n }\n }\n return loader;\n}\n", "import type * as FS from \"fs\";\n\nlet secretRequire: ((module: string) => any) | undefined;\ntry {\n // Secretly use require/import without webpack knowing\n // eslint-disable-next-line\n secretRequire = eval(\"require\");\n} catch (err) {\n try {\n // eslint-disable-next-line\n secretRequire = eval(\"(module) => import(module)\");\n } catch (err) {\n secretRequire = undefined;\n }\n}\n\nexport async function serverRequire<T>(module: string): Promise<T> {\n if (!secretRequire) {\n throw new Error(\n `Unexpected serverRequire() -- can only do this from a Node server!`\n );\n }\n return secretRequire(module) as Promise<T>;\n}\n\nexport async function tryServerRequire<T>(\n module: string\n): Promise<T | undefined> {\n try {\n const require = await serverRequire<T>(module);\n return require;\n } catch {\n return undefined;\n }\n}\n\nexport async function tryServerRequires<T>(\n modules: string[]\n): Promise<T | undefined> {\n for (const module of modules) {\n const require = await tryServerRequire<T>(module);\n if (require != null) {\n return require;\n }\n }\n return undefined;\n}\n\nexport async function serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO;AAEP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,OAAO,cAAc;AACrB,OAAO,cAAc;AACrB,OAAO,oBAAoB;AAC3B,YAAY,gBAAgB;;;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err", "require", "err", "opts"]
|
|
7
7
|
}
|
package/dist/react-server.js
CHANGED
|
@@ -22,18 +22,6 @@ var __spreadValues = (a, b) => {
|
|
|
22
22
|
return a;
|
|
23
23
|
};
|
|
24
24
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __objRest = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols)
|
|
31
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
25
|
var __export = (target, all) => {
|
|
38
26
|
for (var name in all)
|
|
39
27
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -80,11 +68,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
80
68
|
var react_server_exports = {};
|
|
81
69
|
__export(react_server_exports, {
|
|
82
70
|
NextJsPlasmicComponentLoader: () => NextJsPlasmicComponentLoader,
|
|
83
|
-
__EXPERMIENTAL__extractPlasmicQueryData: () => __EXPERMIENTAL__extractPlasmicQueryData,
|
|
84
|
-
__EXPERMIENTAL__fetchExtractedHeadMetadata: () => import_react_server3.fetchExtractedHeadMetadata,
|
|
85
|
-
__EXPERMIENTAL__fetchExtractedQueryData: () => import_react_server3.fetchExtractedQueryData,
|
|
86
|
-
__EXPERMIENTAL__withExtractPlasmicQueryData: () => __EXPERMIENTAL__withExtractPlasmicQueryData,
|
|
87
|
-
__EXPERMIENTAL__withPlasmicMetadata: () => import_react_server3.withPlasmicMetadata,
|
|
88
71
|
initPlasmicLoader: () => initPlasmicLoader
|
|
89
72
|
});
|
|
90
73
|
module.exports = __toCommonJS(react_server_exports);
|
|
@@ -92,6 +75,7 @@ var import_server_only = require("server-only");
|
|
|
92
75
|
var import_react_server = require("@plasmicapp/loader-react/react-server");
|
|
93
76
|
var import_head = __toESM(require("next/head.js"));
|
|
94
77
|
var import_link = __toESM(require("next/link.js"));
|
|
78
|
+
var import_navigation = __toESM(require("next/navigation.js"));
|
|
95
79
|
var NextRouter = __toESM(require("next/router.js"));
|
|
96
80
|
|
|
97
81
|
// src/cache.ts
|
|
@@ -202,8 +186,7 @@ function makeCache(opts) {
|
|
|
202
186
|
);
|
|
203
187
|
return new FileCache(cachePath);
|
|
204
188
|
}
|
|
205
|
-
function initPlasmicLoaderWithCache(initFn,
|
|
206
|
-
var _b = _a, { nextNavigation } = _b, opts = __objRest(_b, ["nextNavigation"]);
|
|
189
|
+
function initPlasmicLoaderWithCache(initFn, opts) {
|
|
207
190
|
const isBrowser = typeof window !== "undefined";
|
|
208
191
|
const isProd = process.env.NODE_ENV === "production";
|
|
209
192
|
const isBuildPhase = process.env.NEXT_PHASE === import_constants.PHASE_PRODUCTION_BUILD;
|
|
@@ -215,7 +198,8 @@ function initPlasmicLoaderWithCache(initFn, _a) {
|
|
|
215
198
|
platform: "nextjs",
|
|
216
199
|
platformOptions: {
|
|
217
200
|
nextjs: {
|
|
218
|
-
appDir:
|
|
201
|
+
appDir: true
|
|
202
|
+
// always true now that we require next@>=13
|
|
219
203
|
}
|
|
220
204
|
},
|
|
221
205
|
// For Nextjs 12, revalidate may in fact re-use an existing instance
|
|
@@ -279,10 +263,6 @@ function initPlasmicLoaderWithCache(initFn, _a) {
|
|
|
279
263
|
}
|
|
280
264
|
|
|
281
265
|
// src/react-server.tsx
|
|
282
|
-
var import_react_server2 = require("@plasmicapp/loader-react/react-server");
|
|
283
|
-
var import_nextjs_app_router = require("@plasmicapp/nextjs-app-router");
|
|
284
|
-
var import_react_server3 = require("@plasmicapp/nextjs-app-router/react-server");
|
|
285
|
-
var import_react = __toESM(require("react"));
|
|
286
266
|
var NextJsPlasmicComponentLoader = class extends import_react_server.PlasmicComponentLoader {
|
|
287
267
|
constructor(internal) {
|
|
288
268
|
super(internal);
|
|
@@ -335,45 +315,9 @@ function initPlasmicLoader(opts) {
|
|
|
335
315
|
loader.registerModules({
|
|
336
316
|
"next/head": import_head.default,
|
|
337
317
|
"next/link": import_link.default,
|
|
318
|
+
"next/navigation": import_navigation.default,
|
|
338
319
|
"next/router": NextRouter
|
|
339
320
|
});
|
|
340
|
-
if (opts.nextNavigation) {
|
|
341
|
-
loader.registerModules({
|
|
342
|
-
"next/navigation": opts.nextNavigation
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
321
|
return loader;
|
|
346
322
|
}
|
|
347
|
-
var __EXPERMIENTAL__extractPlasmicQueryData = import_react_server2.__EXPERMIENTAL__extractPlasmicQueryData;
|
|
348
|
-
function __EXPERMIENTAL__withExtractPlasmicQueryData(_0, _1) {
|
|
349
|
-
return __async(this, arguments, function* (plasmicRootProvider, {
|
|
350
|
-
pathname,
|
|
351
|
-
searchParams
|
|
352
|
-
}) {
|
|
353
|
-
var _a, _b, _c;
|
|
354
|
-
const isPlasmicSsr = !!(searchParams == null ? void 0 : searchParams["plasmicSsr"]) && (searchParams == null ? void 0 : searchParams["plasmicSsr"]) !== "false";
|
|
355
|
-
if (isPlasmicSsr) {
|
|
356
|
-
return /* @__PURE__ */ import_react.default.createElement(import_nextjs_app_router.ExtractPlasmicQueryData, null, plasmicRootProvider);
|
|
357
|
-
}
|
|
358
|
-
const prepassHost = (_c = (_a = process.env.PLASMIC_PREPASS_HOST) != null ? _a : process.env.VERCEL_URL && `https://${process.env.VERCEL_URL}`) != null ? _c : `http://localhost:${(_b = process.env.PORT) != null ? _b : 3e3}`;
|
|
359
|
-
const newSearchParams = new URLSearchParams(
|
|
360
|
-
Object.entries(searchParams != null ? searchParams : {}).flatMap(
|
|
361
|
-
([key, values]) => Array.isArray(values) ? values.map((v) => [key, v]) : [[key, values]]
|
|
362
|
-
)
|
|
363
|
-
);
|
|
364
|
-
newSearchParams.set("plasmicSsr", "true");
|
|
365
|
-
if (process.env.VERCEL_AUTOMATION_BYPASS_SECRET) {
|
|
366
|
-
newSearchParams.set(
|
|
367
|
-
"x-vercel-protection-bypass",
|
|
368
|
-
process.env.VERCEL_AUTOMATION_BYPASS_SECRET
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
|
-
const prefetchedQueryData = yield (0, import_react_server3.fetchExtractedQueryData)(
|
|
372
|
-
`${prepassHost}${pathname}?${newSearchParams.toString()}`
|
|
373
|
-
);
|
|
374
|
-
return import_react.default.cloneElement(plasmicRootProvider, {
|
|
375
|
-
prefetchedQueryData
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
323
|
//# sourceMappingURL=react-server.js.map
|
package/dist/react-server.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/react-server.tsx", "../src/cache.ts", "../src/server-require.ts"],
|
|
4
|
-
"sourcesContent": ["import \"server-only\";\n\nimport {\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n} from \"@plasmicapp/loader-react/react-server\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport * as NextRouter from \"next/router.js\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport type { NextInitOptions } from \"./shared-exports\";\n\nimport { __EXPERMIENTAL__extractPlasmicQueryData as internalExtractPlasmicQueryData } from \"@plasmicapp/loader-react/react-server\";\nimport { ExtractPlasmicQueryData } from \"@plasmicapp/nextjs-app-router\";\nimport {\n fetchExtractedHeadMetadata,\n fetchExtractedQueryData,\n withPlasmicMetadata,\n} from \"@plasmicapp/nextjs-app-router/react-server\";\n\nexport * from \"./shared-exports\";\nexport {\n fetchExtractedQueryData as __EXPERMIENTAL__fetchExtractedQueryData,\n fetchExtractedHeadMetadata as __EXPERMIENTAL__fetchExtractedHeadMetadata,\n withPlasmicMetadata as __EXPERMIENTAL__withPlasmicMetadata,\n};\n\nimport React from \"react\";\nimport type * as ClientExports from \".\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: {\n [key: string]: string;\n };\n};\n\nexport class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {\n constructor(internal: InternalPlasmicComponentLoader) {\n super(internal);\n }\n\n async getActiveVariation(opts: {\n req?: ServerRequest;\n res?: ServerResponse;\n known?: Record<string, string>;\n traits: Record<string, string | number | boolean>;\n }) {\n const extractBuiltinTraits = () => {\n const url = new URL(\n opts.req?.url ?? \"/\",\n `https://${opts.req?.headers.host ?? \"server.side\"}`\n );\n return {\n pageUrl: url.href,\n };\n };\n\n return this._getActiveVariation({\n traits: {\n ...extractBuiltinTraits(),\n ...opts.traits,\n },\n getKnownValue: (key: string) => {\n if (opts.known) {\n return opts.known[key];\n } else {\n return opts.req?.cookies[`plasmic:${key}`] ?? undefined;\n }\n },\n updateKnownValue: (key: string, value: string) => {\n if (opts.res) {\n const cookie = `plasmic:${key}=${value}`;\n const resCookie = opts.res?.getHeader(\"Set-Cookie\") ?? [];\n let newCookies: string[] = [];\n if (Array.isArray(resCookie)) {\n newCookies = [...resCookie, `plasmic:${key}=${value}`];\n } else {\n newCookies = [`${resCookie}`, cookie];\n }\n\n opts.res?.setHeader(\"Set-Cookie\", newCookies);\n }\n },\n });\n }\n}\n\nexport function initPlasmicLoader(opts: NextInitOptions) {\n const loader = initPlasmicLoaderWithCache<NextJsPlasmicComponentLoader>(\n (opts) =>\n new PlasmicComponentLoader(new InternalPlasmicComponentLoader(opts)),\n opts\n );\n loader.registerModules({\n \"next/head\": NextHead,\n \"next/link\": NextLink,\n \"next/router\": NextRouter,\n });\n if (opts.nextNavigation) {\n loader.registerModules({\n \"next/navigation\": opts.nextNavigation,\n });\n }\n return loader;\n}\n\nexport const __EXPERMIENTAL__extractPlasmicQueryData: (\n element: React.ReactElement,\n // We can't use `NextJsPlasmicComponentLoader` or `PlasmicComponentLoader`\n // types because they refer to the react-server version, which Typescript\n // doesn't recognize as compatible with the client version (whose type is\n // also the one exported from `react-server-conditional` imports).\n loader: ClientExports.NextJsPlasmicComponentLoader\n) => Promise<Record<string, any>> = internalExtractPlasmicQueryData as any;\n\n/**\n * Helper function to extract Plasmic data.\n *\n * Given the <PlasmicClientRootProvider> element and current pathname + search\n * params, returns:\n * - The extracted query data, if `plasmicSsr` search param is set\n * - A copy of the root provider element with the extracted query data, otherwise\n */\nexport async function __EXPERMIENTAL__withExtractPlasmicQueryData(\n plasmicRootProvider: React.ReactElement,\n {\n pathname,\n searchParams,\n }: {\n pathname: string;\n searchParams: Record<string, string | string[]> | undefined;\n }\n) {\n const isPlasmicSsr =\n !!searchParams?.[\"plasmicSsr\"] && searchParams?.[\"plasmicSsr\"] !== \"false\";\n\n // If `plasmicSsr` search param is set, just wrap the root provider inside\n // <ExtractPlasmicQueryData>\n if (isPlasmicSsr) {\n return (\n <ExtractPlasmicQueryData>{plasmicRootProvider}</ExtractPlasmicQueryData>\n );\n }\n\n // Otherwise, fetch the same endpoint, but setting `plasmicSsr` to extract the\n // query data.\n const prepassHost =\n process.env.PLASMIC_PREPASS_HOST ??\n (process.env.VERCEL_URL && `https://${process.env.VERCEL_URL}`) ??\n `http://localhost:${process.env.PORT ?? 3000}`;\n\n // Build a copy of the search params\n const newSearchParams = new URLSearchParams(\n Object.entries(searchParams ?? {}).flatMap(([key, values]) =>\n Array.isArray(values) ? values.map((v) => [key, v]) : [[key, values]]\n )\n );\n\n // Set `plasmicSsr` search param to indicate you are using this endpoint\n // to extract query data.\n newSearchParams.set(\"plasmicSsr\", \"true\");\n\n if (process.env.VERCEL_AUTOMATION_BYPASS_SECRET) {\n // If protection bypass is enabled, use it to ensure fetching from\n // the SSR endpoint will not return the authentication page HTML\n newSearchParams.set(\n \"x-vercel-protection-bypass\",\n process.env.VERCEL_AUTOMATION_BYPASS_SECRET\n );\n }\n\n // Fetch the data from the endpoint using the new search params\n const prefetchedQueryData = await fetchExtractedQueryData(\n `${prepassHost}${pathname}?${newSearchParams.toString()}`\n );\n\n // Provide the query data to <PlasmicClientRootProvider>\n return React.cloneElement(plasmicRootProvider, {\n prefetchedQueryData,\n });\n}\n", "import { LoaderBundleOutput } from \"@plasmicapp/loader-core\";\nimport type { InitOptions } from \"@plasmicapp/loader-react/react-server-conditional\";\nimport type * as Watcher from \"@plasmicapp/watcher\";\nimport { PHASE_PRODUCTION_BUILD } from \"next/constants\";\nimport path from \"path\";\nimport { serverRequire, serverRequireFs } from \"./server-require\";\nimport type { NextInitOptions } from \"./shared-exports\";\n\nclass FileCache {\n constructor(private filePath: string) {}\n\n async get() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n const data = (await fs.promises.readFile(this.filePath)).toString();\n return JSON.parse(data);\n } catch {\n return undefined;\n }\n }\n\n async set(data: LoaderBundleOutput) {\n const fs = await serverRequireFs();\n try {\n await fs.promises.writeFile(this.filePath, JSON.stringify(data));\n } catch (err) {\n console.warn(`Error writing to Plasmic cache: ${err}`);\n }\n }\n\n async clear() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction hashString(str: string) {\n let h = 0,\n i = 0;\n for (; i < str.length; h &= h) h = 31 * h + str.charCodeAt(i++);\n return Math.abs(h);\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${hashString(\n [...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")\n )}${opts.preview ? \"-preview\" : \"\"}-cache.json`\n );\n return new FileCache(cachePath);\n}\n\nexport function initPlasmicLoaderWithCache<\n T extends {\n clearCache(): void;\n }\n>(\n initFn: (opts: InitOptions) => T,\n { nextNavigation, ...opts }: NextInitOptions\n): T {\n const isBrowser = typeof window !== \"undefined\";\n const isProd = process.env.NODE_ENV === \"production\";\n const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;\n const cache = isBrowser || isProd ? undefined : makeCache(opts);\n const loader = initFn({\n onClientSideFetch: \"warn\",\n ...opts,\n cache,\n platform: \"nextjs\",\n platformOptions: {\n nextjs: {\n appDir: !!nextNavigation,\n },\n },\n // For Nextjs 12, revalidate may in fact re-use an existing instance\n // of PlasmicComponentLoader that's already in memory, so we need to\n // make sure we don't re-use the data cached in memory.\n // We also enforce this for dev mode, so that we don't have to restart\n // the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader\n // We also enforce that during build phase, we re-use the data cached in memory\n // to avoid re-fetching the data from Plasmic servers.\n alwaysFresh: !isBuildPhase && !isBrowser,\n });\n\n if (!isProd) {\n const stringOpts = JSON.stringify(opts);\n\n if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {\n console.warn(\n `PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.\\n`\n );\n }\n\n process.env.PLASMIC_OPTS = stringOpts;\n }\n\n if (cache) {\n if (!isProd) {\n if (process.env.PLASMIC_WATCHED !== \"true\") {\n (async () => {\n process.env.PLASMIC_WATCHED = \"true\";\n console.log(`Subscribing to Plasmic changes...`);\n\n // Import using serverRequire, so webpack doesn't bundle us into client bundle\n try {\n const PlasmicRemoteChangeWatcher = (\n await serverRequire<typeof Watcher>(\"@plasmicapp/watcher\")\n ).PlasmicRemoteChangeWatcher;\n const watcher = new PlasmicRemoteChangeWatcher({\n projects: opts.projects,\n host: opts.host,\n });\n\n const clearCache = () => {\n cache.clear();\n loader.clearCache();\n };\n\n watcher.subscribe({\n onUpdate: () => {\n if (opts.preview) {\n clearCache();\n }\n },\n onPublish: () => {\n if (!opts.preview) {\n clearCache();\n }\n },\n });\n } catch (e) {\n console.warn(\"Couldn't subscribe to Plasmic changes\", e);\n }\n })();\n }\n } else {\n cache.clear();\n loader.clearCache();\n }\n }\n return loader;\n}\n", "import type * as FS from \"fs\";\n\nlet secretRequire: ((module: string) => any) | undefined;\ntry {\n // Secretly use require/import without webpack knowing\n // eslint-disable-next-line\n secretRequire = eval(\"require\");\n} catch (err) {\n try {\n // eslint-disable-next-line\n secretRequire = eval(\"(module) => import(module)\");\n } catch (err) {\n secretRequire = undefined;\n }\n}\n\nexport async function serverRequire<T>(module: string): Promise<T> {\n if (!secretRequire) {\n throw new Error(\n `Unexpected serverRequire() -- can only do this from a Node server!`\n );\n }\n return secretRequire(module) as Promise<T>;\n}\n\nexport async function tryServerRequire<T>(\n module: string\n): Promise<T | undefined> {\n try {\n const require = await serverRequire<T>(module);\n return require;\n } catch {\n return undefined;\n }\n}\n\nexport async function tryServerRequires<T>(\n modules: string[]\n): Promise<T | undefined> {\n for (const module of modules) {\n const require = await tryServerRequire<T>(module);\n if (require != null) {\n return require;\n }\n }\n return undefined;\n}\n\nexport async function serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["err", "module", "require", "path", "err", "
|
|
4
|
+
"sourcesContent": ["import \"server-only\";\n\nimport {\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n} from \"@plasmicapp/loader-react/react-server\";\nimport type { IncomingMessage, ServerResponse } from \"http\";\nimport NextHead from \"next/head.js\";\nimport NextLink from \"next/link.js\";\nimport NextNavigation from \"next/navigation.js\";\nimport * as NextRouter from \"next/router.js\";\nimport { initPlasmicLoaderWithCache } from \"./cache\";\nimport type { InitOptions } from \"./shared-exports\";\n\nexport * from \"./shared-exports\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: {\n [key: string]: string;\n };\n};\n\nexport class NextJsPlasmicComponentLoader extends PlasmicComponentLoader {\n constructor(internal: InternalPlasmicComponentLoader) {\n super(internal);\n }\n\n async getActiveVariation(opts: {\n req?: ServerRequest;\n res?: ServerResponse;\n known?: Record<string, string>;\n traits: Record<string, string | number | boolean>;\n }) {\n const extractBuiltinTraits = () => {\n const url = new URL(\n opts.req?.url ?? \"/\",\n `https://${opts.req?.headers.host ?? \"server.side\"}`\n );\n return {\n pageUrl: url.href,\n };\n };\n\n return this._getActiveVariation({\n traits: {\n ...extractBuiltinTraits(),\n ...opts.traits,\n },\n getKnownValue: (key: string) => {\n if (opts.known) {\n return opts.known[key];\n } else {\n return opts.req?.cookies[`plasmic:${key}`] ?? undefined;\n }\n },\n updateKnownValue: (key: string, value: string) => {\n if (opts.res) {\n const cookie = `plasmic:${key}=${value}`;\n const resCookie = opts.res?.getHeader(\"Set-Cookie\") ?? [];\n let newCookies: string[] = [];\n if (Array.isArray(resCookie)) {\n newCookies = [...resCookie, `plasmic:${key}=${value}`];\n } else {\n newCookies = [`${resCookie}`, cookie];\n }\n\n opts.res?.setHeader(\"Set-Cookie\", newCookies);\n }\n },\n });\n }\n}\n\nexport function initPlasmicLoader(\n opts: InitOptions\n): NextJsPlasmicComponentLoader {\n const loader = initPlasmicLoaderWithCache<NextJsPlasmicComponentLoader>(\n (opts) =>\n new PlasmicComponentLoader(new InternalPlasmicComponentLoader(opts)),\n opts\n );\n loader.registerModules({\n \"next/head\": NextHead,\n \"next/link\": NextLink,\n \"next/navigation\": NextNavigation,\n \"next/router\": NextRouter,\n });\n return loader;\n}\n", "import { LoaderBundleOutput } from \"@plasmicapp/loader-core\";\nimport type { InitOptions } from \"@plasmicapp/loader-react/react-server-conditional\";\nimport type * as Watcher from \"@plasmicapp/watcher\";\nimport { PHASE_PRODUCTION_BUILD } from \"next/constants\";\nimport path from \"path\";\nimport { serverRequire, serverRequireFs } from \"./server-require\";\n\nclass FileCache {\n constructor(private filePath: string) {}\n\n async get() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });\n const data = (await fs.promises.readFile(this.filePath)).toString();\n return JSON.parse(data);\n } catch {\n return undefined;\n }\n }\n\n async set(data: LoaderBundleOutput) {\n const fs = await serverRequireFs();\n try {\n await fs.promises.writeFile(this.filePath, JSON.stringify(data));\n } catch (err) {\n console.warn(`Error writing to Plasmic cache: ${err}`);\n }\n }\n\n async clear() {\n const fs = await serverRequireFs();\n try {\n await fs.promises.unlink(this.filePath);\n } catch (err) {\n // noop\n }\n }\n}\n\nfunction hashString(str: string) {\n let h = 0,\n i = 0;\n for (; i < str.length; h &= h) h = 31 * h + str.charCodeAt(i++);\n return Math.abs(h);\n}\n\nfunction makeCache(opts: InitOptions) {\n const cacheDir = path.resolve(process.cwd(), \".next\", \".plasmic\");\n const cachePath = path.join(\n cacheDir,\n `plasmic-${hashString(\n [...opts.projects.map((p) => `${p.id}@${p.version ?? \"\"}`)]\n .sort()\n .join(\"-\")\n )}${opts.preview ? \"-preview\" : \"\"}-cache.json`\n );\n return new FileCache(cachePath);\n}\n\nexport function initPlasmicLoaderWithCache<\n T extends {\n clearCache(): void;\n }\n>(initFn: (opts: InitOptions) => T, opts: InitOptions): T {\n const isBrowser = typeof window !== \"undefined\";\n const isProd = process.env.NODE_ENV === \"production\";\n const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;\n const cache = isBrowser || isProd ? undefined : makeCache(opts);\n const loader = initFn({\n onClientSideFetch: \"warn\",\n ...opts,\n cache,\n platform: \"nextjs\",\n platformOptions: {\n nextjs: {\n appDir: true, // always true now that we require next@>=13\n },\n },\n // For Nextjs 12, revalidate may in fact re-use an existing instance\n // of PlasmicComponentLoader that's already in memory, so we need to\n // make sure we don't re-use the data cached in memory.\n // We also enforce this for dev mode, so that we don't have to restart\n // the dev server, in case getStaticProps() re-uses the same PlasmicComponentLoader\n // We also enforce that during build phase, we re-use the data cached in memory\n // to avoid re-fetching the data from Plasmic servers.\n alwaysFresh: !isBuildPhase && !isBrowser,\n });\n\n if (!isProd) {\n const stringOpts = JSON.stringify(opts);\n\n if (process.env.PLASMIC_OPTS && process.env.PLASMIC_OPTS !== stringOpts) {\n console.warn(\n `PLASMIC: We detected that you created a new PlasmicLoader with different configurations. You may need to restart your dev server.\\n`\n );\n }\n\n process.env.PLASMIC_OPTS = stringOpts;\n }\n\n if (cache) {\n if (!isProd) {\n if (process.env.PLASMIC_WATCHED !== \"true\") {\n (async () => {\n process.env.PLASMIC_WATCHED = \"true\";\n console.log(`Subscribing to Plasmic changes...`);\n\n // Import using serverRequire, so webpack doesn't bundle us into client bundle\n try {\n const PlasmicRemoteChangeWatcher = (\n await serverRequire<typeof Watcher>(\"@plasmicapp/watcher\")\n ).PlasmicRemoteChangeWatcher;\n const watcher = new PlasmicRemoteChangeWatcher({\n projects: opts.projects,\n host: opts.host,\n });\n\n const clearCache = () => {\n cache.clear();\n loader.clearCache();\n };\n\n watcher.subscribe({\n onUpdate: () => {\n if (opts.preview) {\n clearCache();\n }\n },\n onPublish: () => {\n if (!opts.preview) {\n clearCache();\n }\n },\n });\n } catch (e) {\n console.warn(\"Couldn't subscribe to Plasmic changes\", e);\n }\n })();\n }\n } else {\n cache.clear();\n loader.clearCache();\n }\n }\n return loader;\n}\n", "import type * as FS from \"fs\";\n\nlet secretRequire: ((module: string) => any) | undefined;\ntry {\n // Secretly use require/import without webpack knowing\n // eslint-disable-next-line\n secretRequire = eval(\"require\");\n} catch (err) {\n try {\n // eslint-disable-next-line\n secretRequire = eval(\"(module) => import(module)\");\n } catch (err) {\n secretRequire = undefined;\n }\n}\n\nexport async function serverRequire<T>(module: string): Promise<T> {\n if (!secretRequire) {\n throw new Error(\n `Unexpected serverRequire() -- can only do this from a Node server!`\n );\n }\n return secretRequire(module) as Promise<T>;\n}\n\nexport async function tryServerRequire<T>(\n module: string\n): Promise<T | undefined> {\n try {\n const require = await serverRequire<T>(module);\n return require;\n } catch {\n return undefined;\n }\n}\n\nexport async function tryServerRequires<T>(\n modules: string[]\n): Promise<T | undefined> {\n for (const module of modules) {\n const require = await tryServerRequire<T>(module);\n if (require != null) {\n return require;\n }\n }\n return undefined;\n}\n\nexport async function serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n"],
|
|
5
|
+
"mappings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,IACb,CAACE,UACC,IAAI,2CAAuB,IAAI,mDAA+BA,KAAI,CAAC;AAAA,IACrE;AAAA,EACF;AACA,SAAO,gBAAgB;AAAA,IACrB,aAAa,YAAAC;AAAA,IACb,aAAa,YAAAC;AAAA,IACb,mBAAmB,kBAAAC;AAAA,IACnB,eAAe;AAAA,EACjB,CAAC;AACD,SAAO;AACT;",
|
|
6
|
+
"names": ["err", "module", "require", "path", "err", "opts", "NextHead", "NextLink", "NextNavigation"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"name": "@plasmicapp/loader-nextjs",
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
|
+
"description": "Plasmic loader SDK for Next.js",
|
|
3
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/plasmicapp/plasmic.git",
|
|
9
|
+
"directory": "packages/loader-nextjs"
|
|
10
|
+
},
|
|
4
11
|
"types": "./dist/index.d.ts",
|
|
5
12
|
"main": "./dist/index.js",
|
|
6
13
|
"module": "./dist/index.esm.js",
|
|
@@ -57,13 +64,6 @@
|
|
|
57
64
|
"size": "size-limit",
|
|
58
65
|
"analyze": "size-limit --why"
|
|
59
66
|
},
|
|
60
|
-
"peerDependencies": {
|
|
61
|
-
"next": ">=10.1.0",
|
|
62
|
-
"react": ">=16.8.0",
|
|
63
|
-
"react-dom": ">=16.8.0"
|
|
64
|
-
},
|
|
65
|
-
"name": "@plasmicapp/loader-nextjs",
|
|
66
|
-
"author": "Chung Wu",
|
|
67
67
|
"size-limit": [
|
|
68
68
|
{
|
|
69
69
|
"path": "dist/index.js",
|
|
@@ -74,18 +74,25 @@
|
|
|
74
74
|
"limit": "15 KB"
|
|
75
75
|
}
|
|
76
76
|
],
|
|
77
|
-
"devDependencies": {
|
|
78
|
-
"@types/react": "^18.0.27",
|
|
79
|
-
"@types/react-dom": "^18.0.10",
|
|
80
|
-
"next": "^13.2.0"
|
|
81
|
-
},
|
|
82
77
|
"dependencies": {
|
|
83
78
|
"@plasmicapp/loader-core": "1.0.137",
|
|
84
79
|
"@plasmicapp/loader-edge": "1.0.70",
|
|
85
|
-
"@plasmicapp/loader-react": "
|
|
80
|
+
"@plasmicapp/loader-react": "2.0.0-alpha.0",
|
|
86
81
|
"@plasmicapp/nextjs-app-router": "1.0.16",
|
|
87
82
|
"@plasmicapp/watcher": "1.0.84",
|
|
88
83
|
"server-only": "0.0.1"
|
|
89
84
|
},
|
|
90
|
-
"
|
|
85
|
+
"devDependencies": {
|
|
86
|
+
"@types/react": "^18",
|
|
87
|
+
"@types/react-dom": "^18",
|
|
88
|
+
"next": "^14",
|
|
89
|
+
"react": "18.3.1",
|
|
90
|
+
"react-dom": "18.3.1"
|
|
91
|
+
},
|
|
92
|
+
"peerDependencies": {
|
|
93
|
+
"next": ">=14.0.0",
|
|
94
|
+
"react": ">=18.2.0",
|
|
95
|
+
"react-dom": ">=18.2.0"
|
|
96
|
+
},
|
|
97
|
+
"gitHead": "fa53f7d79f0e26d8b061102fda0c06788da6f8a7"
|
|
91
98
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
export * from "./dist/index";
|
|
2
|
+
export * from "./dist/react-server";
|
|
3
|
+
export { initPlasmicLoader, NextJsPlasmicComponentLoader };
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { initPlasmicLoader };
|
|
5
|
+
// Disambiguate `initPlasmicLoader` and `NextJsPlasmicComponentLoader`.
|
|
6
|
+
// Prefer the "default" version since it is more permissive.
|
|
7
|
+
import { initPlasmicLoader, NextJsPlasmicComponentLoader } from "./dist/index";
|