@rsc-kit/core 0.30.36 → 0.30.38

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/vite.d.ts CHANGED
@@ -545,6 +545,23 @@ export declare const DEV_WORKER = "self.addEventListener('install', () => self.s
545
545
  * process.env.PUBLIC_* is untouched: that is an ordinary server variable.
546
546
  */
547
547
  export declare function publicPrefixReads(code: string): string[];
548
+ /**
549
+ * A section whose section() name is not its file's.
550
+ *
551
+ * A section is found by its file: `orders.section.tsx` is the one
552
+ * revalidate('orders') re-renders, on this page or beside its layouts. Its
553
+ * boundary in the browser waits under the name section() was given. Two names
554
+ * for one region, and both ways round it failed: revalidate('admin-table') on
555
+ * a table.section.tsx typechecked - the route types read section() - and was
556
+ * refused at the renderer, while revalidate('table') re-rendered it and the
557
+ * browser filed the answer under a name no boundary was waiting for, so nothing
558
+ * on screen changed and nothing said so.
559
+ *
560
+ * One name, then, and the file's is the one the rest already keys on. Only a
561
+ * literal is read; a name computed at runtime is not seen here, as it is not
562
+ * seen by the route types.
563
+ */
564
+ export declare function sectionNameMismatch(file: string, code: string): string | null;
548
565
  export declare function serverRendererInRsc(): Plugin;
549
566
  /**
550
567
  * The project's typecheck, as part of the build.
package/dist/vite.js CHANGED
@@ -6870,6 +6870,45 @@ function publicPrefixRefused() {
6870
6870
  },
6871
6871
  };
6872
6872
  }
6873
+ /**
6874
+ * A section whose section() name is not its file's.
6875
+ *
6876
+ * A section is found by its file: `orders.section.tsx` is the one
6877
+ * revalidate('orders') re-renders, on this page or beside its layouts. Its
6878
+ * boundary in the browser waits under the name section() was given. Two names
6879
+ * for one region, and both ways round it failed: revalidate('admin-table') on
6880
+ * a table.section.tsx typechecked - the route types read section() - and was
6881
+ * refused at the renderer, while revalidate('table') re-rendered it and the
6882
+ * browser filed the answer under a name no boundary was waiting for, so nothing
6883
+ * on screen changed and nothing said so.
6884
+ *
6885
+ * One name, then, and the file's is the one the rest already keys on. Only a
6886
+ * literal is read; a name computed at runtime is not seen here, as it is not
6887
+ * seen by the route types.
6888
+ */
6889
+ export function sectionNameMismatch(file, code) {
6890
+ const stem = (file.split("?")[0].split("/").pop() ?? "").replace(SECTION_FILE, "");
6891
+ const named = [...code.matchAll(/\bsection\(\s*['"`]([^'"`]+)['"`]/g)].map((m) => m[1]);
6892
+ const wrong = named.filter((name) => name !== stem);
6893
+ if (wrong.length === 0)
6894
+ return null;
6895
+ return (`${file.split("?")[0]} calls section(${wrong.map((name) => JSON.stringify(name)).join(", ")}), and its file names it ${JSON.stringify(stem)}. ` +
6896
+ `A section is found by its file, so revalidate() and the boundary on screen would disagree. ` +
6897
+ `Rename the file to ${wrong[0]}.section.tsx, or pass ${JSON.stringify(stem)} to section().`);
6898
+ }
6899
+ function sectionNameRefused() {
6900
+ return {
6901
+ name: "rsc-kit:section-name",
6902
+ enforce: "pre",
6903
+ transform(code, id) {
6904
+ if (id.includes("/node_modules/") || !SECTION_FILE.test(id.split("?")[0]))
6905
+ return;
6906
+ const message = sectionNameMismatch(id, code);
6907
+ if (message)
6908
+ this.error(message);
6909
+ },
6910
+ };
6911
+ }
6873
6912
  /**
6874
6913
  * Named imports from a barrel package, unrolled on the server environments.
6875
6914
  *
@@ -8455,6 +8494,7 @@ export function rscKit(options = {}) {
8455
8494
  ...actionEncryptionKey(),
8456
8495
  }),
8457
8496
  publicPrefixRefused(),
8497
+ sectionNameRefused(),
8458
8498
  barrelImportsPlugin(),
8459
8499
  useSsrModules(),
8460
8500
  serverRendererInRsc(),