hd-garden 0.5.18 → 0.6.0

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/vite.config.ts CHANGED
@@ -5,7 +5,6 @@ import vinext from "vinext";
5
5
  import { defineConfig } from "vite";
6
6
  import hostingConfig from "./.openai/hosting.json";
7
7
  import { sites } from "./build/sites-vite-plugin";
8
- import staticRscPath from "./build/static-rsc-path-plugin.mjs";
9
8
  import { gardenPackageRoot, gardenSiteRoot } from "./scripts/garden-paths.mjs";
10
9
 
11
10
  const SITE_CREATOR_PLACEHOLDER_DATABASE_ID =
@@ -122,7 +121,6 @@ export default defineConfig(async () => {
122
121
  plugins: [
123
122
  gardenContent(),
124
123
  vinext(),
125
- staticRscPath(),
126
124
  sites(),
127
125
  cloudflare({
128
126
  viteEnvironment: { name: "rsc", childEnvironments: ["ssr"] },
@@ -1,78 +0,0 @@
1
- // Static export: request the home page's RSC payload where the export writes it.
2
- //
3
- // vinext's client builds every RSC address as `<pathname>.rsc` (trailing slash
4
- // dropped), so the home page becomes `/.rsc`. The static export writes that
5
- // payload to `index.rsc` (vinext's getRscOutputPath maps "/" there). A static
6
- // host has no server to bridge the two, so every <Link href="/"> prefetch, and
7
- // any client navigation home, hit a 404. With output: "export" this plugin
8
- // changes the address builder (toRscRequestPath) so "/" asks for `/index.rsc`.
9
- // Every other path already matches the exported file. Prefetching stays on.
10
- //
11
- // Static hosts do not know the .rsc extension either: GitHub Pages serves it as
12
- // application/octet-stream, and vinext only accepts text/x-component, so every
13
- // client navigation fell back to a full page load, aimed at the payload URL
14
- // minus ".rsc" (for home that is "/index"). In the browser navigation code the
15
- // export also accepts application/octet-stream, and a fallback to "/index"
16
- // goes to "/". Only a 2xx response with a body counts: vinext's own
17
- // `!navResponse.ok` check stays in front, and the build stops if it is gone.
18
- //
19
- // Rewrites vinext 0.0.50. Remove this plugin once vinext fixes it upstream
20
- // (draft issue: /workspace/dev/vinext-issue.md); a vinext whose code no longer
21
- // matches stops the build.
22
-
23
- const TARGET = /[\\/]vinext[\\/]dist[\\/]server[\\/]app-rsc-cache-busting\.js$/u;
24
- const NAVIGATION = /[\\/]vinext[\\/]dist[\\/]server[\\/]app-browser-entry\.js$/u;
25
- const RSC_CHECK = 'const isRscResponse = (navResponse.headers.get("content-type") ?? "").startsWith("text/x-component");';
26
- const RSC_CHECK_EXPORTED = 'const isRscResponse = /^(text\\/x-component|application\\/octet-stream)/.test(navResponse.headers.get("content-type") ?? "");';
27
- const FALLBACK = "let pathname = stripRscSuffix(parsed.pathname);";
28
- // Must stay: any non-2xx response is a failure whatever its content-type.
29
- const FAILURE = "if (!navResponse.ok || !isRscResponse || !navResponse.body) {";
30
- const FALLBACK_EXPORTED = 'let pathname = stripRscSuffix(parsed.pathname); if (pathname === "/index") pathname = "/";';
31
- const ADDRESS = "return `${pathname.length > 1 && pathname.endsWith(\"/\") ? pathname.slice(0, -1) : pathname}.rsc${query}`;";
32
- const EXPORTED = "return `${pathname === \"/\" ? \"/index\" : pathname.length > 1 && pathname.endsWith(\"/\") ? pathname.slice(0, -1) : pathname}.rsc${query}`;";
33
-
34
- /** Rewrite vinext's RSC address builder; throws if vinext changed shape. */
35
- export function exportRscAddress(code, id = "app-rsc-cache-busting.js") {
36
- if (!code.includes("function toRscRequestPath(") || !code.includes(ADDRESS)) {
37
- throw new Error(`garden static RSC path: could not find vinext's RSC address builder in ${id}. vinext changed; update build/static-rsc-path-plugin.mjs so the home page asks for /index.rsc.`);
38
- }
39
- return code.replace(ADDRESS, EXPORTED);
40
- }
41
-
42
- /** Rewrite vinext's client navigation for static hosts; throws if vinext changed shape. */
43
- export function exportNavigation(code, id = "app-browser-entry.js") {
44
- for (const needle of [RSC_CHECK, FALLBACK, FAILURE]) {
45
- if (code.split(needle).length !== 2) {
46
- throw new Error(`garden static RSC path: could not find \`${needle}\` exactly once in ${id}. vinext changed; update build/static-rsc-path-plugin.mjs (or remove it if vinext fixed static hosting).`);
47
- }
48
- }
49
- return code.replace(RSC_CHECK, RSC_CHECK_EXPORTED).replace(FALLBACK, FALLBACK_EXPORTED);
50
- }
51
-
52
- export default function staticRscPath({ enabled = process.env.STATIC_EXPORT === "1" } = {}) {
53
- const seen = new Set();
54
- return {
55
- name: "garden-static-rsc-path",
56
- apply: "build",
57
- transform(code, id) {
58
- // Browser bundle only: the prerender server still answers "/.rsc" itself.
59
- if (!enabled || this.environment?.name !== "client") return null;
60
- const file = id.split("?")[0];
61
- if (TARGET.test(file)) {
62
- seen.add("address");
63
- return { code: exportRscAddress(code, id), map: null };
64
- }
65
- if (NAVIGATION.test(file)) {
66
- seen.add("navigation");
67
- return { code: exportNavigation(code, id), map: null };
68
- }
69
- return null;
70
- },
71
- buildEnd(error) {
72
- // The client build always pulls the address builder in; not seeing it means vinext moved it.
73
- if (enabled && !error && this.environment?.name === "client" && seen.size < 2) {
74
- this.error("garden static RSC path: vinext's app-rsc-cache-busting.js or app-browser-entry.js was not part of the client build; update build/static-rsc-path-plugin.mjs.");
75
- }
76
- },
77
- };
78
- }
@@ -1,37 +0,0 @@
1
- /**
2
- * In-page `#` links without a page refetch.
3
- *
4
- * Following a plain `<a href="#section">` is a fragment navigation: the
5
- * browser scrolls, adds a history entry with no state and fires `popstate`.
6
- * The router (vinext 0.0.50) treats every `popstate` as a history traversal
7
- * and fetches the page's RSC payload again, although only the hash changed.
8
- * Next.js itself ignores a popstate without state.
9
- *
10
- * The guard notes a click on a same-page hash link that nothing else handled,
11
- * and swallows the stateless `popstate` that follows it before the router
12
- * sees it. On `window`, listeners run in the order they were added, capture
13
- * or not, so this has to be added before the router's: it ships as a small
14
- * inline script in <head>, which runs before the deferred module scripts.
15
- * The click listener sits on `window`, after React's handlers on the
16
- * document, so a link that the TOC or a Link already handled is left alone.
17
- * Back and forward between real history entries still reach the router.
18
- */
19
-
20
- /** How long after the click the fragment's popstate may arrive. */
21
- export const HASH_JUMP_WINDOW_MS = 1000;
22
-
23
- export const HASH_JUMP_SCRIPT = `(function(w){var armed=-Infinity;\
24
- w.addEventListener("click",function(e){\
25
- if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;\
26
- var a=e.target&&e.target.closest&&e.target.closest("a[href]");\
27
- if(!a||a.hasAttribute("download"))return;\
28
- var t=a.getAttribute("target");if(t&&t!=="_self")return;\
29
- var h=a.getAttribute("href")||"";if(h.indexOf("#")<0)return;\
30
- var u,l=w.location;try{u=new URL(h,l.href)}catch(x){return}\
31
- if(u.origin===l.origin&&u.pathname===l.pathname&&u.search===l.search&&u.hash.length>1)armed=Date.now();\
32
- });\
33
- w.addEventListener("popstate",function(e){\
34
- var on=Date.now()-armed<=${HASH_JUMP_WINDOW_MS};armed=-Infinity;\
35
- if(on&&e.state==null)e.stopImmediatePropagation();\
36
- },true);\
37
- })(window);`;