nukejs 0.0.24 → 0.0.26

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.
@@ -12,6 +12,7 @@ import {
12
12
  findPageLayouts,
13
13
  buildPerPageRegistry,
14
14
  makePageAdapterSource,
15
+ buildClientComponentTagImports,
15
16
  buildCombinedBundle,
16
17
  copyPublicFiles
17
18
  } from "./build-common.js";
@@ -572,6 +573,7 @@ if (serverPages.length > 0 || ["_404.tsx", "_500.tsx"].some((f) => fs.existsSync
572
573
  pageImport: JSON.stringify("./" + path.basename(page.absPath)),
573
574
  layoutImports,
574
575
  clientComponentNames,
576
+ clientComponentTagImports: buildClientComponentTagImports(registry, adapterDir),
575
577
  allClientIds: [...registry.keys()],
576
578
  layoutArrayItems: layoutPaths.map((_, i) => `__layout_${i}__`).join(", "),
577
579
  prerenderedHtml: prerenderedRecord,
@@ -609,6 +611,7 @@ if (serverPages.length > 0 || ["_404.tsx", "_500.tsx"].some((f) => fs.existsSync
609
611
  pageImport: JSON.stringify("./" + path.basename(src)),
610
612
  layoutImports,
611
613
  clientComponentNames,
614
+ clientComponentTagImports: buildClientComponentTagImports(registry, adapterDir),
612
615
  allClientIds: [...registry.keys()],
613
616
  layoutArrayItems: layoutPaths.map((_, i) => `__layout_${i}__`).join(", "),
614
617
  prerenderedHtml: prerenderedRecord,
@@ -209,8 +209,8 @@ async function buildPages(pagesDir, staticDir, outPagesDir) {
209
209
  const bundleText = await bundlePageHandler({
210
210
  absPath: page.absPath,
211
211
  pagesDir,
212
+ registry,
212
213
  clientComponentNames,
213
- allClientIds: [...registry.keys()],
214
214
  layoutPaths,
215
215
  prerenderedHtml: prerenderedRecord,
216
216
  routeParamNames: page.paramNames,
@@ -292,11 +292,20 @@ export default async function handler(req: IncomingMessage, res: ServerResponse)
292
292
  }
293
293
  `;
294
294
  }
295
+ function buildClientComponentTagImports(registry, adapterDir) {
296
+ return [...registry.entries()].map(([id, absPath], i) => {
297
+ const rel = path.relative(adapterDir, absPath).replace(/\\/g, "/");
298
+ const spec = JSON.stringify(rel.startsWith(".") ? rel : "./" + rel);
299
+ return `import __cc_tag_${i}__ from ${spec};
300
+ if (typeof __cc_tag_${i}__ === 'function') (__cc_tag_${i}__ as any).__nukeClientId = ${JSON.stringify(id)};`;
301
+ }).join("\n");
302
+ }
295
303
  function makePageAdapterSource(opts) {
296
304
  const {
297
305
  pageImport,
298
306
  layoutImports,
299
307
  clientComponentNames,
308
+ clientComponentTagImports,
300
309
  allClientIds,
301
310
  layoutArrayItems,
302
311
  prerenderedHtml,
@@ -309,6 +318,7 @@ import { createElement as __createElement__ } from 'react';
309
318
  import { renderToString as __renderToString__ } from 'react-dom/server';
310
319
  import * as __page__ from ${pageImport};
311
320
  ${layoutImports}
321
+ ${clientComponentTagImports}
312
322
 
313
323
  const CLIENT_COMPONENTS: Record<string, string> = ${JSON.stringify(clientComponentNames)};
314
324
  const ALL_CLIENT_IDS: string[] = ${JSON.stringify(allClientIds)};
@@ -431,8 +441,8 @@ function minifyHtml(h: string): string {
431
441
  });
432
442
  const minified = withoutPres
433
443
  .replace(/<!--(?!(n-head|\\/n-head|n-body-scripts|\\/n-body-scripts|n-pre-))[\\s\\S]*?-->/g, '')
434
- .replace(/>\\s+</g, '> <')
435
- .replace(/\\s*\\n\\s*/g, '')
444
+ .replace(/\\s*\\n\\s*/g, ' ')
445
+ .replace(/>\\s+</g, '><')
436
446
  .trim();
437
447
  return pres.length === 0
438
448
  ? minified
@@ -493,7 +503,7 @@ function serializeProps(value: any): any {
493
503
  const { type, props: p } = value as any;
494
504
  if (typeof type === 'string') return { __re: 'html', tag: type, props: serializeProps(p) };
495
505
  if (typeof type === 'function') {
496
- const cid = CLIENT_COMPONENTS[type.name];
506
+ const cid = (type as any).__nukeClientId ?? CLIENT_COMPONENTS[type.name];
497
507
  if (cid) return { __re: 'client', componentId: cid, props: serializeProps(p) };
498
508
  }
499
509
  return undefined;
@@ -542,7 +552,7 @@ async function renderNode(node: any, hydrated: Set<string>): Promise<string> {
542
552
  }
543
553
 
544
554
  if (typeof type === 'function') {
545
- const clientId = CLIENT_COMPONENTS[type.name];
555
+ const clientId = (type as any).__nukeClientId ?? CLIENT_COMPONENTS[type.name];
546
556
  if (clientId) {
547
557
  hydrated.add(clientId);
548
558
  const { wrapperAttrs, componentProps } = splitWrapperAttrs(props);
@@ -715,8 +725,8 @@ async function bundleApiHandler(absPath) {
715
725
  async function bundlePageHandler(opts) {
716
726
  const {
717
727
  absPath,
728
+ registry,
718
729
  clientComponentNames,
719
- allClientIds,
720
730
  layoutPaths,
721
731
  prerenderedHtml,
722
732
  routeParamNames,
@@ -733,7 +743,8 @@ async function bundlePageHandler(opts) {
733
743
  pageImport: JSON.stringify("./" + path.basename(absPath)),
734
744
  layoutImports,
735
745
  clientComponentNames,
736
- allClientIds,
746
+ clientComponentTagImports: buildClientComponentTagImports(registry, adapterDir),
747
+ allClientIds: [...registry.keys()],
737
748
  layoutArrayItems: layoutPaths.map((_, i) => `__layout_${i}__`).join(", "),
738
749
  prerenderedHtml,
739
750
  routeParamNames,
@@ -835,8 +846,8 @@ async function buildErrorPages(pagesDir, outPagesDir, prerenderedHtml) {
835
846
  const bundleText = await bundlePageHandler({
836
847
  absPath: src,
837
848
  pagesDir,
849
+ registry,
838
850
  clientComponentNames,
839
- allClientIds: [...registry.keys()],
840
851
  layoutPaths,
841
852
  prerenderedHtml,
842
853
  routeParamNames: [],
@@ -922,6 +933,7 @@ function copyPublicFiles(publicDir, destDir) {
922
933
  }
923
934
  export {
924
935
  analyzeFile,
936
+ buildClientComponentTagImports,
925
937
  buildCombinedBundle,
926
938
  buildErrorPages,
927
939
  buildPages,
@@ -12,6 +12,7 @@ import {
12
12
  findPageLayouts,
13
13
  buildPerPageRegistry,
14
14
  makePageAdapterSource,
15
+ buildClientComponentTagImports,
15
16
  buildCombinedBundle,
16
17
  copyPublicFiles
17
18
  } from "./build-common.js";
@@ -294,6 +295,7 @@ if (serverPages.length > 0 || hasErrorPages) {
294
295
  pageImport: JSON.stringify("./" + path.basename(page.absPath)),
295
296
  layoutImports,
296
297
  clientComponentNames,
298
+ clientComponentTagImports: buildClientComponentTagImports(registry, adapterDir),
297
299
  allClientIds: [...registry.keys()],
298
300
  layoutArrayItems: layoutPaths.map((_, i) => `__layout_${i}__`).join(", "),
299
301
  prerenderedHtml: prerenderedRecord,
@@ -328,6 +330,7 @@ if (serverPages.length > 0 || hasErrorPages) {
328
330
  pageImport: JSON.stringify("./" + path.basename(src)),
329
331
  layoutImports,
330
332
  clientComponentNames,
333
+ clientComponentTagImports: buildClientComponentTagImports(registry, adapterDir),
331
334
  allClientIds: [...registry.keys()],
332
335
  layoutArrayItems: layoutPaths.map((_, i) => `__layout_${i}__`).join(", "),
333
336
  prerenderedHtml: prerenderedRecord,
package/dist/renderer.js CHANGED
@@ -81,7 +81,11 @@ async function renderFunctionComponent(type, props, ctx) {
81
81
  for (const [id, filePath] of ctx.registry.entries()) {
82
82
  const info = componentCache.get(filePath);
83
83
  if (!info?.isClientComponent) continue;
84
- if (!info.exportedName || type.name !== info.exportedName) continue;
84
+ if (type.__nukeClientId === id) {
85
+ } else {
86
+ if (!info.exportedName || type.name !== info.exportedName) continue;
87
+ type.__nukeClientId = id;
88
+ }
85
89
  try {
86
90
  ctx.hydrated.add(id);
87
91
  const { wrapperAttrs, componentProps } = splitWrapperAttrs(props);
@@ -135,7 +139,8 @@ function serializeReactElement(element, registry) {
135
139
  for (const [id, filePath] of registry.entries()) {
136
140
  const info = componentCache.get(filePath);
137
141
  if (!info?.isClientComponent) continue;
138
- if (info.exportedName && type.name === info.exportedName) {
142
+ if (type.__nukeClientId === id || info.exportedName && type.name === info.exportedName) {
143
+ type.__nukeClientId = id;
139
144
  return {
140
145
  __re: "client",
141
146
  componentId: id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nukejs",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "description": "A minimal, opinionated full-stack React framework on Node.js that server-renders everything and hydrates only interactive parts.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",