@plasmicapp/loader-nextjs 1.0.386 → 1.0.388
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 +37 -2
- package/dist/index.esm.js +84 -22
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +77 -22
- package/dist/index.js.map +4 -4
- package/dist/react-server.d.ts +39 -2
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { ComponentMeta } from '@plasmicapp/loader-react/react-server-conditional
|
|
|
7
7
|
import { ComponentRenderData } from '@plasmicapp/loader-react/react-server-conditional';
|
|
8
8
|
import { DataCtxReader } from '@plasmicapp/loader-react';
|
|
9
9
|
import { DataProvider } from '@plasmicapp/loader-react';
|
|
10
|
-
import { extractPlasmicQueryData } from '@plasmicapp/loader-react';
|
|
11
10
|
import { FetchComponentDataOpts as FetchComponentDataOpts_2 } from '@plasmicapp/loader-react';
|
|
12
11
|
import { GlobalActionsContext } from '@plasmicapp/loader-react';
|
|
13
12
|
import { GlobalActionsProvider } from '@plasmicapp/loader-react';
|
|
@@ -48,7 +47,43 @@ export { DataCtxReader }
|
|
|
48
47
|
|
|
49
48
|
export { DataProvider }
|
|
50
49
|
|
|
51
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Performs a prepass over Plasmic content, kicking off the necessary
|
|
52
|
+
* data fetches, and populating the fetched data into a cache. This
|
|
53
|
+
* cache can be passed as prefetchedQueryData into PlasmicRootProvider.
|
|
54
|
+
*
|
|
55
|
+
* To limit rendering errors that can occur when you do this, we recommend
|
|
56
|
+
* that you pass in _only_ the PlasmicComponents that you are planning to use
|
|
57
|
+
* as the argument. For example:
|
|
58
|
+
*
|
|
59
|
+
* const cache = await extractPlasmicQueryData(
|
|
60
|
+
* <PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>
|
|
61
|
+
* <PlasmicComponent component="Home" componentProps={{
|
|
62
|
+
* // Specify the component prop overrides you are planning to use
|
|
63
|
+
* // to render the page, as they may change what data is fetched.
|
|
64
|
+
* ...
|
|
65
|
+
* }} />
|
|
66
|
+
* <PlasmicComponent component="NavBar" componentProps={{
|
|
67
|
+
* ...
|
|
68
|
+
* }} />
|
|
69
|
+
* ...
|
|
70
|
+
* </PlasmicRootProvider>
|
|
71
|
+
* );
|
|
72
|
+
*
|
|
73
|
+
* If your PlasmicComponent will be wrapping components that require special
|
|
74
|
+
* context set up, you should also wrap the element above with those context
|
|
75
|
+
* providers.
|
|
76
|
+
*
|
|
77
|
+
* You should avoid passing in elements that are not related to Plasmic, as any
|
|
78
|
+
* rendering errors from those elements during the prepass may result in data
|
|
79
|
+
* not being populated in the cache.
|
|
80
|
+
*
|
|
81
|
+
* @param element a React element containing instances of PlasmicComponent.
|
|
82
|
+
* Will attempt to satisfy all data needs from usePlasmicDataQuery()
|
|
83
|
+
* in this element tree.
|
|
84
|
+
* @returns an object mapping query key to fetched data
|
|
85
|
+
*/
|
|
86
|
+
export declare function extractPlasmicQueryData(element: React_2.ReactElement): Promise<Record<string, any>>;
|
|
52
87
|
|
|
53
88
|
export declare interface FetchComponentDataOpts extends FetchComponentDataOpts_2 {
|
|
54
89
|
/**
|
package/dist/index.esm.js
CHANGED
|
@@ -20,6 +20,13 @@ var __spreadValues = (a, b) => {
|
|
|
20
20
|
return a;
|
|
21
21
|
};
|
|
22
22
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
24
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
25
|
+
}) : x)(function(x) {
|
|
26
|
+
if (typeof require !== "undefined")
|
|
27
|
+
return require.apply(this, arguments);
|
|
28
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
29
|
+
});
|
|
23
30
|
var __objRest = (source, exclude) => {
|
|
24
31
|
var target = {};
|
|
25
32
|
for (var prop in source)
|
|
@@ -56,6 +63,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
56
63
|
|
|
57
64
|
// src/index.tsx
|
|
58
65
|
import {
|
|
66
|
+
extractPlasmicQueryData as internalExtractPlasmicQueryData,
|
|
59
67
|
InternalPlasmicComponentLoader,
|
|
60
68
|
PlasmicComponentLoader,
|
|
61
69
|
PlasmicRootProvider as CommonPlasmicRootProvider
|
|
@@ -63,7 +71,6 @@ import {
|
|
|
63
71
|
import {
|
|
64
72
|
DataCtxReader,
|
|
65
73
|
DataProvider,
|
|
66
|
-
extractPlasmicQueryData,
|
|
67
74
|
GlobalActionsContext,
|
|
68
75
|
GlobalActionsProvider,
|
|
69
76
|
PageParamsProvider,
|
|
@@ -84,7 +91,7 @@ import NextHead from "next/head.js";
|
|
|
84
91
|
import NextLink from "next/link.js";
|
|
85
92
|
import * as NextRouter from "next/router.js";
|
|
86
93
|
import Script from "next/script";
|
|
87
|
-
import * as
|
|
94
|
+
import * as React2 from "react";
|
|
88
95
|
|
|
89
96
|
// src/cache.ts
|
|
90
97
|
import { PHASE_PRODUCTION_BUILD } from "next/constants";
|
|
@@ -166,15 +173,15 @@ function makeCache(opts) {
|
|
|
166
173
|
cacheDir,
|
|
167
174
|
`plasmic-${hashString(
|
|
168
175
|
[...opts.projects.map((p) => {
|
|
169
|
-
var
|
|
170
|
-
return `${p.id}@${(
|
|
176
|
+
var _a2;
|
|
177
|
+
return `${p.id}@${(_a2 = p.version) != null ? _a2 : ""}`;
|
|
171
178
|
})].sort().join("-")
|
|
172
179
|
)}${opts.preview ? "-preview" : ""}-cache.json`
|
|
173
180
|
);
|
|
174
181
|
return new FileCache(cachePath);
|
|
175
182
|
}
|
|
176
|
-
function initPlasmicLoaderWithCache(initFn,
|
|
177
|
-
var _b =
|
|
183
|
+
function initPlasmicLoaderWithCache(initFn, _a2) {
|
|
184
|
+
var _b = _a2, { nextNavigation } = _b, opts = __objRest(_b, ["nextNavigation"]);
|
|
178
185
|
const isBrowser = typeof window !== "undefined";
|
|
179
186
|
const isProd = process.env.NODE_ENV === "production";
|
|
180
187
|
const isBuildPhase = process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;
|
|
@@ -249,8 +256,60 @@ function initPlasmicLoaderWithCache(initFn, _a) {
|
|
|
249
256
|
return loader;
|
|
250
257
|
}
|
|
251
258
|
|
|
259
|
+
// src/mocks.tsx
|
|
260
|
+
import * as React from "react";
|
|
261
|
+
function tryRequire(module) {
|
|
262
|
+
try {
|
|
263
|
+
return __require(module);
|
|
264
|
+
} catch (e) {
|
|
265
|
+
return void 0;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
var _a;
|
|
269
|
+
var RouterImport = (_a = tryRequire("next/dist/shared/lib/router-context.shared-runtime")) != null ? _a : tryRequire("next/dist/shared/lib/router-context");
|
|
270
|
+
var fakeRouter = {
|
|
271
|
+
push: () => __async(void 0, null, function* () {
|
|
272
|
+
return true;
|
|
273
|
+
}),
|
|
274
|
+
replace: () => __async(void 0, null, function* () {
|
|
275
|
+
return true;
|
|
276
|
+
}),
|
|
277
|
+
reload: () => {
|
|
278
|
+
},
|
|
279
|
+
back: () => {
|
|
280
|
+
},
|
|
281
|
+
forward: () => {
|
|
282
|
+
},
|
|
283
|
+
prefetch: () => __async(void 0, null, function* () {
|
|
284
|
+
return;
|
|
285
|
+
}),
|
|
286
|
+
beforePopState: () => {
|
|
287
|
+
},
|
|
288
|
+
events: {
|
|
289
|
+
on: () => {
|
|
290
|
+
},
|
|
291
|
+
off: () => {
|
|
292
|
+
},
|
|
293
|
+
emit: () => {
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
route: "/",
|
|
297
|
+
asPath: "/",
|
|
298
|
+
basePath: "/",
|
|
299
|
+
pathname: "/",
|
|
300
|
+
query: {},
|
|
301
|
+
isFallback: false,
|
|
302
|
+
isLocaleDomain: false,
|
|
303
|
+
isReady: true,
|
|
304
|
+
isPreview: false
|
|
305
|
+
};
|
|
306
|
+
function wrapRouterContext(element) {
|
|
307
|
+
var _a2;
|
|
308
|
+
return !!((_a2 = RouterImport.RouterContext) == null ? void 0 : _a2.Provider) ? /* @__PURE__ */ React.createElement(RouterImport.RouterContext.Provider, { value: fakeRouter }, element) : element;
|
|
309
|
+
}
|
|
310
|
+
|
|
252
311
|
// src/index.tsx
|
|
253
|
-
var reactMajorVersion = +
|
|
312
|
+
var reactMajorVersion = +React2.version.split(".")[0];
|
|
254
313
|
function filterCodeFromRenderData(data) {
|
|
255
314
|
if (reactMajorVersion >= 18 && !!data.bundle.bundleKey) {
|
|
256
315
|
const entrypoints = /* @__PURE__ */ new Set([
|
|
@@ -275,9 +334,9 @@ var NextJsPlasmicComponentLoader = class extends PlasmicComponentLoader {
|
|
|
275
334
|
getActiveVariation(opts) {
|
|
276
335
|
return __async(this, null, function* () {
|
|
277
336
|
const extractBuiltinTraits = () => {
|
|
278
|
-
var
|
|
337
|
+
var _a2, _b, _c, _d;
|
|
279
338
|
const url = new URL(
|
|
280
|
-
(_b = (
|
|
339
|
+
(_b = (_a2 = opts.req) == null ? void 0 : _a2.url) != null ? _b : "/",
|
|
281
340
|
`https://${(_d = (_c = opts.req) == null ? void 0 : _c.headers.host) != null ? _d : "server.side"}`
|
|
282
341
|
);
|
|
283
342
|
return {
|
|
@@ -287,18 +346,18 @@ var NextJsPlasmicComponentLoader = class extends PlasmicComponentLoader {
|
|
|
287
346
|
return this._getActiveVariation({
|
|
288
347
|
traits: __spreadValues(__spreadValues({}, extractBuiltinTraits()), opts.traits),
|
|
289
348
|
getKnownValue: (key) => {
|
|
290
|
-
var
|
|
349
|
+
var _a2, _b;
|
|
291
350
|
if (opts.known) {
|
|
292
351
|
return opts.known[key];
|
|
293
352
|
} else {
|
|
294
|
-
return (_b = (
|
|
353
|
+
return (_b = (_a2 = opts.req) == null ? void 0 : _a2.cookies[`plasmic:${key}`]) != null ? _b : void 0;
|
|
295
354
|
}
|
|
296
355
|
},
|
|
297
356
|
updateKnownValue: (key, value) => {
|
|
298
|
-
var
|
|
357
|
+
var _a2, _b, _c;
|
|
299
358
|
if (opts.res) {
|
|
300
359
|
const cookie = `plasmic:${key}=${value}`;
|
|
301
|
-
const resCookie = (_b = (
|
|
360
|
+
const resCookie = (_b = (_a2 = opts.res) == null ? void 0 : _a2.getHeader("Set-Cookie")) != null ? _b : [];
|
|
302
361
|
let newCookies = [];
|
|
303
362
|
if (Array.isArray(resCookie)) {
|
|
304
363
|
newCookies = [...resCookie, `plasmic:${key}=${value}`];
|
|
@@ -363,9 +422,12 @@ function initPlasmicLoader(opts) {
|
|
|
363
422
|
}
|
|
364
423
|
return loader;
|
|
365
424
|
}
|
|
366
|
-
|
|
425
|
+
function extractPlasmicQueryData(element) {
|
|
426
|
+
return internalExtractPlasmicQueryData(wrapRouterContext(element));
|
|
427
|
+
}
|
|
428
|
+
var PlasmicNextLink = React2.forwardRef(function PlasmicNextLink2(props, ref) {
|
|
367
429
|
if (props.href) {
|
|
368
|
-
const
|
|
430
|
+
const _a2 = props, {
|
|
369
431
|
href,
|
|
370
432
|
replace,
|
|
371
433
|
scroll,
|
|
@@ -373,7 +435,7 @@ var PlasmicNextLink = React.forwardRef(function PlasmicNextLink2(props, ref) {
|
|
|
373
435
|
passHref,
|
|
374
436
|
prefetch,
|
|
375
437
|
locale
|
|
376
|
-
} =
|
|
438
|
+
} = _a2, rest = __objRest(_a2, [
|
|
377
439
|
"href",
|
|
378
440
|
"replace",
|
|
379
441
|
"scroll",
|
|
@@ -383,7 +445,7 @@ var PlasmicNextLink = React.forwardRef(function PlasmicNextLink2(props, ref) {
|
|
|
383
445
|
"locale"
|
|
384
446
|
]);
|
|
385
447
|
const isFragment = typeof href === "string" && href.startsWith("#");
|
|
386
|
-
return /* @__PURE__ */
|
|
448
|
+
return /* @__PURE__ */ React2.createElement(
|
|
387
449
|
NextLink,
|
|
388
450
|
__spreadValues({
|
|
389
451
|
href,
|
|
@@ -394,14 +456,14 @@ var PlasmicNextLink = React.forwardRef(function PlasmicNextLink2(props, ref) {
|
|
|
394
456
|
prefetch,
|
|
395
457
|
locale
|
|
396
458
|
}, { legacyBehavior: true }),
|
|
397
|
-
/* @__PURE__ */
|
|
459
|
+
/* @__PURE__ */ React2.createElement("a", __spreadProps(__spreadValues({}, rest), { ref }))
|
|
398
460
|
);
|
|
399
461
|
} else {
|
|
400
|
-
return /* @__PURE__ */
|
|
462
|
+
return /* @__PURE__ */ React2.createElement("a", __spreadProps(__spreadValues({}, props), { href: void 0, ref }));
|
|
401
463
|
}
|
|
402
464
|
});
|
|
403
465
|
function PlasmicRootProvider(props) {
|
|
404
|
-
return /* @__PURE__ */
|
|
466
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, !props.skipChunks && renderDynamicPayloadScripts(props.loader, props.prefetchedData), /* @__PURE__ */ React2.createElement(
|
|
405
467
|
CommonPlasmicRootProvider,
|
|
406
468
|
__spreadValues({
|
|
407
469
|
Head: NextHead,
|
|
@@ -431,7 +493,7 @@ function renderDynamicPayloadScripts(loader, prefetchedData) {
|
|
|
431
493
|
}
|
|
432
494
|
}
|
|
433
495
|
}
|
|
434
|
-
return /* @__PURE__ */
|
|
496
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
|
|
435
497
|
Script,
|
|
436
498
|
{
|
|
437
499
|
strategy: "beforeInteractive",
|
|
@@ -458,7 +520,7 @@ function renderDynamicPayloadScripts(loader, prefetchedData) {
|
|
|
458
520
|
).join("\n")}`.trim()
|
|
459
521
|
}
|
|
460
522
|
}
|
|
461
|
-
), /* @__PURE__ */
|
|
523
|
+
), /* @__PURE__ */ React2.createElement(
|
|
462
524
|
Script,
|
|
463
525
|
{
|
|
464
526
|
strategy: "beforeInteractive",
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.tsx", "../src/cache.ts", "../src/server-require.ts"],
|
|
4
|
-
"sourcesContent": ["import type { CodeModule } from \"@plasmicapp/loader-core\";\nimport {\n ComponentLookupSpec,\n FetchComponentDataOpts as InternalFetchComponentDataOpts,\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n PlasmicRootProvider as CommonPlasmicRootProvider,\n} from \"@plasmicapp/loader-react\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nexport {\n DataCtxReader,\n DataProvider,\n extractPlasmicQueryData,\n GlobalActionsContext,\n GlobalActionsProvider,\n PageParamsProvider,\n PlasmicCanvasContext,\n PlasmicCanvasHost,\n PlasmicComponent,\n plasmicPrepass,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\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 type { ComponentRenderData, NextInitOptions } from \"./shared-exports\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: {\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 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\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 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 serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["err", "err", "opts", "PlasmicNextLink"]
|
|
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 ComponentLookupSpec,\n extractPlasmicQueryData as internalExtractPlasmicQueryData,\n FetchComponentDataOpts as InternalFetchComponentDataOpts,\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n PlasmicRootProvider as CommonPlasmicRootProvider,\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 plasmicPrepass,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\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: {\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 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 function extractPlasmicQueryData(element: React.ReactElement) {\n return internalExtractPlasmicQueryData(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 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 serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n", "import type { NextRouter } from \"next/router\";\nimport * as React from \"react\";\n\nfunction tryRequire(module: string) {\n try {\n return require(module);\n } catch {\n return undefined;\n }\n}\n\nconst RouterImport: any =\n tryRequire(\"next/dist/shared/lib/router-context.shared-runtime\") ??\n tryRequire(\"next/dist/shared/lib/router-context\");\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 function wrapRouterContext(element: React.ReactElement) {\n return !!RouterImport.RouterContext?.Provider ? (\n <RouterImport.RouterContext.Provider value={fakeRouter}>\n {element}\n </RouterImport.RouterContext.Provider>\n ) : (\n element\n );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA,EAEE,2BAA2B;AAAA,EAE3B;AAAA,EACA;AAAA,EACA,uBAAuB;AAAA,OAClB;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAOP,SAAoC,+BAA+C;AAWnF,OAAO,cAAc;AACrB,OAAO,cAAc;AACrB,YAAY,gBAAgB;AAC5B,OAAO,YAAY;AACnB,YAAYA,YAAW;;;AC9CvB,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;AAAA,EAClB;AACF;AAEA,SAAsB,cAAiB,QAA4B;AAAA;AACjE,QAAI,CAAC,eAAe;AAClB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,WAAO,cAAc,MAAM;AAAA,EAC7B;AAAA;AAEA,SAAsB,kBAAkB;AAAA;AACtC,WAAO,cAAyB,IAAI;AAAA,EACtC;AAAA;;;ADnBA,IAAM,YAAN,MAAgB;AAAA,EACd,YAAoB,UAAkB;AAAlB;AAAA,EAAmB;AAAA,EAEjC,MAAM;AA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,QAAQ;AAAA;AAAA;AAAA;AAAA,cAIJ,mBACC;AAAA,UACC,CACE,WACG,2CAA2C,KAAK;AAAA,YACnD,OAAO;AAAA,UACT;AAAA,uDACuC,KAAK;AAAA,YACxC,OAAO;AAAA,UACT;AAAA,yDACuC,KAAK;AAAA,YACxC,uBAAuB,OAAO;AAAA,UAChC;AAAA;AAAA;AAAA;AAAA,QAIN,EACC,KAAK,IAAI,IAAI,KAAK;AAAA,MACzB;AAAA;AAAA,EACD,GACD;AAAA,IAAC;AAAA;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", "err", "_a", "_a", "_a", "opts", "PlasmicNextLink"]
|
|
7
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -93,7 +93,7 @@ __export(src_exports, {
|
|
|
93
93
|
PlasmicComponent: () => import_loader_react2.PlasmicComponent,
|
|
94
94
|
PlasmicRootProvider: () => PlasmicRootProvider,
|
|
95
95
|
__EXPERMIENTAL__ExtractPlasmicQueryData: () => import_nextjs_app_router.ExtractPlasmicQueryData,
|
|
96
|
-
extractPlasmicQueryData: () =>
|
|
96
|
+
extractPlasmicQueryData: () => extractPlasmicQueryData,
|
|
97
97
|
initPlasmicLoader: () => initPlasmicLoader,
|
|
98
98
|
plasmicPrepass: () => import_loader_react2.plasmicPrepass,
|
|
99
99
|
repeatedElement: () => import_loader_react2.repeatedElement,
|
|
@@ -112,7 +112,7 @@ var import_head = __toESM(require("next/head.js"));
|
|
|
112
112
|
var import_link = __toESM(require("next/link.js"));
|
|
113
113
|
var NextRouter = __toESM(require("next/router.js"));
|
|
114
114
|
var import_script = __toESM(require("next/script"));
|
|
115
|
-
var
|
|
115
|
+
var React2 = __toESM(require("react"));
|
|
116
116
|
|
|
117
117
|
// src/cache.ts
|
|
118
118
|
var import_constants = require("next/constants");
|
|
@@ -194,15 +194,15 @@ function makeCache(opts) {
|
|
|
194
194
|
cacheDir,
|
|
195
195
|
`plasmic-${hashString(
|
|
196
196
|
[...opts.projects.map((p) => {
|
|
197
|
-
var
|
|
198
|
-
return `${p.id}@${(
|
|
197
|
+
var _a2;
|
|
198
|
+
return `${p.id}@${(_a2 = p.version) != null ? _a2 : ""}`;
|
|
199
199
|
})].sort().join("-")
|
|
200
200
|
)}${opts.preview ? "-preview" : ""}-cache.json`
|
|
201
201
|
);
|
|
202
202
|
return new FileCache(cachePath);
|
|
203
203
|
}
|
|
204
|
-
function initPlasmicLoaderWithCache(initFn,
|
|
205
|
-
var _b =
|
|
204
|
+
function initPlasmicLoaderWithCache(initFn, _a2) {
|
|
205
|
+
var _b = _a2, { nextNavigation } = _b, opts = __objRest(_b, ["nextNavigation"]);
|
|
206
206
|
const isBrowser = typeof window !== "undefined";
|
|
207
207
|
const isProd = process.env.NODE_ENV === "production";
|
|
208
208
|
const isBuildPhase = process.env.NEXT_PHASE === import_constants.PHASE_PRODUCTION_BUILD;
|
|
@@ -277,8 +277,60 @@ function initPlasmicLoaderWithCache(initFn, _a) {
|
|
|
277
277
|
return loader;
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
+
// src/mocks.tsx
|
|
281
|
+
var React = __toESM(require("react"));
|
|
282
|
+
function tryRequire(module2) {
|
|
283
|
+
try {
|
|
284
|
+
return require(module2);
|
|
285
|
+
} catch (e) {
|
|
286
|
+
return void 0;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
var _a;
|
|
290
|
+
var RouterImport = (_a = tryRequire("next/dist/shared/lib/router-context.shared-runtime")) != null ? _a : tryRequire("next/dist/shared/lib/router-context");
|
|
291
|
+
var fakeRouter = {
|
|
292
|
+
push: () => __async(void 0, null, function* () {
|
|
293
|
+
return true;
|
|
294
|
+
}),
|
|
295
|
+
replace: () => __async(void 0, null, function* () {
|
|
296
|
+
return true;
|
|
297
|
+
}),
|
|
298
|
+
reload: () => {
|
|
299
|
+
},
|
|
300
|
+
back: () => {
|
|
301
|
+
},
|
|
302
|
+
forward: () => {
|
|
303
|
+
},
|
|
304
|
+
prefetch: () => __async(void 0, null, function* () {
|
|
305
|
+
return;
|
|
306
|
+
}),
|
|
307
|
+
beforePopState: () => {
|
|
308
|
+
},
|
|
309
|
+
events: {
|
|
310
|
+
on: () => {
|
|
311
|
+
},
|
|
312
|
+
off: () => {
|
|
313
|
+
},
|
|
314
|
+
emit: () => {
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
route: "/",
|
|
318
|
+
asPath: "/",
|
|
319
|
+
basePath: "/",
|
|
320
|
+
pathname: "/",
|
|
321
|
+
query: {},
|
|
322
|
+
isFallback: false,
|
|
323
|
+
isLocaleDomain: false,
|
|
324
|
+
isReady: true,
|
|
325
|
+
isPreview: false
|
|
326
|
+
};
|
|
327
|
+
function wrapRouterContext(element) {
|
|
328
|
+
var _a2;
|
|
329
|
+
return !!((_a2 = RouterImport.RouterContext) == null ? void 0 : _a2.Provider) ? /* @__PURE__ */ React.createElement(RouterImport.RouterContext.Provider, { value: fakeRouter }, element) : element;
|
|
330
|
+
}
|
|
331
|
+
|
|
280
332
|
// src/index.tsx
|
|
281
|
-
var reactMajorVersion = +
|
|
333
|
+
var reactMajorVersion = +React2.version.split(".")[0];
|
|
282
334
|
function filterCodeFromRenderData(data) {
|
|
283
335
|
if (reactMajorVersion >= 18 && !!data.bundle.bundleKey) {
|
|
284
336
|
const entrypoints = /* @__PURE__ */ new Set([
|
|
@@ -303,9 +355,9 @@ var NextJsPlasmicComponentLoader = class extends import_loader_react.PlasmicComp
|
|
|
303
355
|
getActiveVariation(opts) {
|
|
304
356
|
return __async(this, null, function* () {
|
|
305
357
|
const extractBuiltinTraits = () => {
|
|
306
|
-
var
|
|
358
|
+
var _a2, _b, _c, _d;
|
|
307
359
|
const url = new URL(
|
|
308
|
-
(_b = (
|
|
360
|
+
(_b = (_a2 = opts.req) == null ? void 0 : _a2.url) != null ? _b : "/",
|
|
309
361
|
`https://${(_d = (_c = opts.req) == null ? void 0 : _c.headers.host) != null ? _d : "server.side"}`
|
|
310
362
|
);
|
|
311
363
|
return {
|
|
@@ -315,18 +367,18 @@ var NextJsPlasmicComponentLoader = class extends import_loader_react.PlasmicComp
|
|
|
315
367
|
return this._getActiveVariation({
|
|
316
368
|
traits: __spreadValues(__spreadValues({}, extractBuiltinTraits()), opts.traits),
|
|
317
369
|
getKnownValue: (key) => {
|
|
318
|
-
var
|
|
370
|
+
var _a2, _b;
|
|
319
371
|
if (opts.known) {
|
|
320
372
|
return opts.known[key];
|
|
321
373
|
} else {
|
|
322
|
-
return (_b = (
|
|
374
|
+
return (_b = (_a2 = opts.req) == null ? void 0 : _a2.cookies[`plasmic:${key}`]) != null ? _b : void 0;
|
|
323
375
|
}
|
|
324
376
|
},
|
|
325
377
|
updateKnownValue: (key, value) => {
|
|
326
|
-
var
|
|
378
|
+
var _a2, _b, _c;
|
|
327
379
|
if (opts.res) {
|
|
328
380
|
const cookie = `plasmic:${key}=${value}`;
|
|
329
|
-
const resCookie = (_b = (
|
|
381
|
+
const resCookie = (_b = (_a2 = opts.res) == null ? void 0 : _a2.getHeader("Set-Cookie")) != null ? _b : [];
|
|
330
382
|
let newCookies = [];
|
|
331
383
|
if (Array.isArray(resCookie)) {
|
|
332
384
|
newCookies = [...resCookie, `plasmic:${key}=${value}`];
|
|
@@ -391,9 +443,12 @@ function initPlasmicLoader(opts) {
|
|
|
391
443
|
}
|
|
392
444
|
return loader;
|
|
393
445
|
}
|
|
394
|
-
|
|
446
|
+
function extractPlasmicQueryData(element) {
|
|
447
|
+
return (0, import_loader_react.extractPlasmicQueryData)(wrapRouterContext(element));
|
|
448
|
+
}
|
|
449
|
+
var PlasmicNextLink = React2.forwardRef(function PlasmicNextLink2(props, ref) {
|
|
395
450
|
if (props.href) {
|
|
396
|
-
const
|
|
451
|
+
const _a2 = props, {
|
|
397
452
|
href,
|
|
398
453
|
replace,
|
|
399
454
|
scroll,
|
|
@@ -401,7 +456,7 @@ var PlasmicNextLink = React.forwardRef(function PlasmicNextLink2(props, ref) {
|
|
|
401
456
|
passHref,
|
|
402
457
|
prefetch,
|
|
403
458
|
locale
|
|
404
|
-
} =
|
|
459
|
+
} = _a2, rest = __objRest(_a2, [
|
|
405
460
|
"href",
|
|
406
461
|
"replace",
|
|
407
462
|
"scroll",
|
|
@@ -411,7 +466,7 @@ var PlasmicNextLink = React.forwardRef(function PlasmicNextLink2(props, ref) {
|
|
|
411
466
|
"locale"
|
|
412
467
|
]);
|
|
413
468
|
const isFragment = typeof href === "string" && href.startsWith("#");
|
|
414
|
-
return /* @__PURE__ */
|
|
469
|
+
return /* @__PURE__ */ React2.createElement(
|
|
415
470
|
import_link.default,
|
|
416
471
|
__spreadValues({
|
|
417
472
|
href,
|
|
@@ -422,14 +477,14 @@ var PlasmicNextLink = React.forwardRef(function PlasmicNextLink2(props, ref) {
|
|
|
422
477
|
prefetch,
|
|
423
478
|
locale
|
|
424
479
|
}, { legacyBehavior: true }),
|
|
425
|
-
/* @__PURE__ */
|
|
480
|
+
/* @__PURE__ */ React2.createElement("a", __spreadProps(__spreadValues({}, rest), { ref }))
|
|
426
481
|
);
|
|
427
482
|
} else {
|
|
428
|
-
return /* @__PURE__ */
|
|
483
|
+
return /* @__PURE__ */ React2.createElement("a", __spreadProps(__spreadValues({}, props), { href: void 0, ref }));
|
|
429
484
|
}
|
|
430
485
|
});
|
|
431
486
|
function PlasmicRootProvider(props) {
|
|
432
|
-
return /* @__PURE__ */
|
|
487
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, !props.skipChunks && renderDynamicPayloadScripts(props.loader, props.prefetchedData), /* @__PURE__ */ React2.createElement(
|
|
433
488
|
import_loader_react.PlasmicRootProvider,
|
|
434
489
|
__spreadValues({
|
|
435
490
|
Head: import_head.default,
|
|
@@ -459,7 +514,7 @@ function renderDynamicPayloadScripts(loader, prefetchedData) {
|
|
|
459
514
|
}
|
|
460
515
|
}
|
|
461
516
|
}
|
|
462
|
-
return /* @__PURE__ */
|
|
517
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
|
|
463
518
|
import_script.default,
|
|
464
519
|
{
|
|
465
520
|
strategy: "beforeInteractive",
|
|
@@ -486,7 +541,7 @@ function renderDynamicPayloadScripts(loader, prefetchedData) {
|
|
|
486
541
|
).join("\n")}`.trim()
|
|
487
542
|
}
|
|
488
543
|
}
|
|
489
|
-
), /* @__PURE__ */
|
|
544
|
+
), /* @__PURE__ */ React2.createElement(
|
|
490
545
|
import_script.default,
|
|
491
546
|
{
|
|
492
547
|
strategy: "beforeInteractive",
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.tsx", "../src/cache.ts", "../src/server-require.ts"],
|
|
4
|
-
"sourcesContent": ["import type { CodeModule } from \"@plasmicapp/loader-core\";\nimport {\n ComponentLookupSpec,\n FetchComponentDataOpts as InternalFetchComponentDataOpts,\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n PlasmicRootProvider as CommonPlasmicRootProvider,\n} from \"@plasmicapp/loader-react\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nexport {\n DataCtxReader,\n DataProvider,\n extractPlasmicQueryData,\n GlobalActionsContext,\n GlobalActionsProvider,\n PageParamsProvider,\n PlasmicCanvasContext,\n PlasmicCanvasHost,\n PlasmicComponent,\n plasmicPrepass,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\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 type { ComponentRenderData, NextInitOptions } from \"./shared-exports\";\n\ntype ServerRequest = IncomingMessage & {\n cookies: {\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 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\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 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 serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\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;AACA,
|
|
6
|
-
"names": ["import_loader_react", "err", "module", "path", "err", "module", "opts", "NextHead", "NextLink", "PlasmicNextLink", "CommonPlasmicRootProvider", "Script"]
|
|
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 ComponentLookupSpec,\n extractPlasmicQueryData as internalExtractPlasmicQueryData,\n FetchComponentDataOpts as InternalFetchComponentDataOpts,\n InternalPlasmicComponentLoader,\n PlasmicComponentLoader,\n PlasmicRootProvider as CommonPlasmicRootProvider,\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 plasmicPrepass,\n repeatedElement,\n useDataEnv,\n usePlasmicCanvasContext,\n usePlasmicComponent,\n usePlasmicQueryData,\n useSelector,\n useSelectors,\n} from \"@plasmicapp/loader-react\";\nexport type {\n CodeComponentMeta,\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: {\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 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 function extractPlasmicQueryData(element: React.ReactElement) {\n return internalExtractPlasmicQueryData(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 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 serverRequireFs() {\n return serverRequire<typeof FS>(\"fs\");\n}\n", "import type { NextRouter } from \"next/router\";\nimport * as React from \"react\";\n\nfunction tryRequire(module: string) {\n try {\n return require(module);\n } catch {\n return undefined;\n }\n}\n\nconst RouterImport: any =\n tryRequire(\"next/dist/shared/lib/router-context.shared-runtime\") ??\n tryRequire(\"next/dist/shared/lib/router-context\");\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 function wrapRouterContext(element: React.ReactElement) {\n return !!RouterImport.RouterContext?.Provider ? (\n <RouterImport.RouterContext.Provider value={fakeRouter}>\n {element}\n </RouterImport.RouterContext.Prov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uBAAuBA,QAAO;AAAA,UAChC;AAAA;AAAA;AAAA;AAAA,QAIN,EACC,KAAK,IAAI,IAAI,KAAK;AAAA,MACzB;AAAA;AAAA,EACD,GACD;AAAA,IAAC,cAAAQ;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": ["import_loader_react", "React", "err", "module", "path", "err", "_a", "module", "_a", "module", "_a", "opts", "NextHead", "NextLink", "internalExtractPlasmicQueryData", "PlasmicNextLink", "CommonPlasmicRootProvider", "Script"]
|
|
7
7
|
}
|
package/dist/react-server.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ import { ComponentRenderData } from '@plasmicapp/loader-react/react-server-condi
|
|
|
10
10
|
import { DataCtxReader } from '@plasmicapp/loader-react';
|
|
11
11
|
import { DataProvider } from '@plasmicapp/loader-react';
|
|
12
12
|
import { ExtractPlasmicQueryData } from '@plasmicapp/nextjs-app-router';
|
|
13
|
-
import { extractPlasmicQueryData } from '@plasmicapp/loader-react';
|
|
14
13
|
import { FetchComponentDataOpts as FetchComponentDataOpts_2 } from '@plasmicapp/loader-react';
|
|
15
14
|
import { GlobalActionsContext } from '@plasmicapp/loader-react';
|
|
16
15
|
import { GlobalActionsProvider } from '@plasmicapp/loader-react';
|
|
@@ -66,10 +65,10 @@ export { __EXPERMIENTAL__withPlasmicMetadata }
|
|
|
66
65
|
declare namespace ClientExports {
|
|
67
66
|
export {
|
|
68
67
|
initPlasmicLoader_2 as initPlasmicLoader,
|
|
68
|
+
extractPlasmicQueryData,
|
|
69
69
|
PlasmicRootProvider,
|
|
70
70
|
DataCtxReader,
|
|
71
71
|
DataProvider,
|
|
72
|
-
extractPlasmicQueryData,
|
|
73
72
|
GlobalActionsContext,
|
|
74
73
|
GlobalActionsProvider,
|
|
75
74
|
PageParamsProvider,
|
|
@@ -104,6 +103,44 @@ export { ComponentMeta }
|
|
|
104
103
|
|
|
105
104
|
export { ComponentRenderData }
|
|
106
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Performs a prepass over Plasmic content, kicking off the necessary
|
|
108
|
+
* data fetches, and populating the fetched data into a cache. This
|
|
109
|
+
* cache can be passed as prefetchedQueryData into PlasmicRootProvider.
|
|
110
|
+
*
|
|
111
|
+
* To limit rendering errors that can occur when you do this, we recommend
|
|
112
|
+
* that you pass in _only_ the PlasmicComponents that you are planning to use
|
|
113
|
+
* as the argument. For example:
|
|
114
|
+
*
|
|
115
|
+
* const cache = await extractPlasmicQueryData(
|
|
116
|
+
* <PlasmicRootProvider loader={PLASMIC} prefetchedData={plasmicData}>
|
|
117
|
+
* <PlasmicComponent component="Home" componentProps={{
|
|
118
|
+
* // Specify the component prop overrides you are planning to use
|
|
119
|
+
* // to render the page, as they may change what data is fetched.
|
|
120
|
+
* ...
|
|
121
|
+
* }} />
|
|
122
|
+
* <PlasmicComponent component="NavBar" componentProps={{
|
|
123
|
+
* ...
|
|
124
|
+
* }} />
|
|
125
|
+
* ...
|
|
126
|
+
* </PlasmicRootProvider>
|
|
127
|
+
* );
|
|
128
|
+
*
|
|
129
|
+
* If your PlasmicComponent will be wrapping components that require special
|
|
130
|
+
* context set up, you should also wrap the element above with those context
|
|
131
|
+
* providers.
|
|
132
|
+
*
|
|
133
|
+
* You should avoid passing in elements that are not related to Plasmic, as any
|
|
134
|
+
* rendering errors from those elements during the prepass may result in data
|
|
135
|
+
* not being populated in the cache.
|
|
136
|
+
*
|
|
137
|
+
* @param element a React element containing instances of PlasmicComponent.
|
|
138
|
+
* Will attempt to satisfy all data needs from usePlasmicDataQuery()
|
|
139
|
+
* in this element tree.
|
|
140
|
+
* @returns an object mapping query key to fetched data
|
|
141
|
+
*/
|
|
142
|
+
declare function extractPlasmicQueryData(element: React_3.ReactElement): Promise<Record<string, any>>;
|
|
143
|
+
|
|
107
144
|
declare interface FetchComponentDataOpts extends FetchComponentDataOpts_2 {
|
|
108
145
|
/**
|
|
109
146
|
* Defer loading code chunks to script tags, reducing initial payload size.
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.388",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"types": "./dist/index.d.ts",
|
|
5
5
|
"main": "./dist/index.js",
|
|
@@ -82,10 +82,10 @@
|
|
|
82
82
|
"dependencies": {
|
|
83
83
|
"@plasmicapp/loader-core": "1.0.132",
|
|
84
84
|
"@plasmicapp/loader-edge": "1.0.65",
|
|
85
|
-
"@plasmicapp/loader-react": "1.0.
|
|
85
|
+
"@plasmicapp/loader-react": "1.0.353",
|
|
86
86
|
"@plasmicapp/nextjs-app-router": "1.0.11",
|
|
87
87
|
"@plasmicapp/watcher": "1.0.83",
|
|
88
88
|
"server-only": "0.0.1"
|
|
89
89
|
},
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "5b29fc6c30a7acaff496a0b2bfd43cbc71ed51b5"
|
|
91
91
|
}
|