@barefootjs/vite 0.33.1 → 0.33.3

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.
@@ -30,14 +30,40 @@ export interface DiscoveredComponent {
30
30
  content: string;
31
31
  /** Whether the file's content starts with a `'use client'` directive. */
32
32
  isClient: boolean;
33
+ /**
34
+ * `isClient`, OR this file transitively instantiates a component that
35
+ * needs one — the property `computeClientEntryPaths` computes over the
36
+ * whole discovered corpus. This, not `isClient`, is the signal for
37
+ * "does this file need its own client bundle and a `<script>` on the
38
+ * page": a plain server component that merely renders a `'use client'`
39
+ * descendant still needs an `initChild(...)` call to run in the
40
+ * browser, and that call lives in ITS OWN compiled init, not the
41
+ * child's (issue #2767 — `hydrateElementScope` in
42
+ * `@barefootjs/client`'s `runtime/hydrate.ts` explicitly skips any
43
+ * element carrying the child marker, deferring to the parent's
44
+ * `initChild`; if the parent's own bundle never ships, that call never
45
+ * happens and the child never hydrates, silently).
46
+ */
47
+ needsClientEntry: boolean;
33
48
  /**
34
49
  * Every component this file exports, from `@barefootjs/jsx`'s TS-AST
35
50
  * walk (`listExportedComponents`) — never a regex, and never the
36
51
  * basename standing in for the name. A file exporting more than one
37
52
  * component (`icon/index.tsx` → `CopyIcon` + `CheckIcon`) is why this
38
- * exists; see `buildChildNameIndex`.
53
+ * exists; see `buildChildNameIndex`. Populated for EVERY file, not just
54
+ * client ones — `computeClientEntryPaths` resolves JSX tag references
55
+ * by name across the whole corpus, so a server file must be indexable
56
+ * too (it may itself be someone else's `referencedComponents` target).
39
57
  */
40
58
  exportedComponents: string[];
59
+ /**
60
+ * PascalCase JSX tag identifiers this file's JSX instantiates (its
61
+ * component-instantiation out-edges), from `@barefootjs/jsx`'s
62
+ * `scanComponentFile`. Feeds `computeClientEntryPaths` — never used for
63
+ * anything import-resolution-shaped, so an unresolved or aliased tag
64
+ * name is simply not an edge (see that function's docstring).
65
+ */
66
+ referencedComponents: string[];
41
67
  /**
42
68
  * `CompileOptions.cssLayerPrefix` this file should compile with, carried
43
69
  * over unchanged from whichever `components` entry's `dir` this file was
@@ -80,6 +106,46 @@ export interface ResolvedComponentDirEntry {
80
106
  * `@bf-child:` name collisions.
81
107
  */
82
108
  export declare function discoverComponents(entries: readonly (string | ResolvedComponentDirEntry)[], readFile: (absPath: string) => Promise<string>): Promise<DiscoveredComponent[]>;
109
+ /**
110
+ * Which discovered files need their OWN client bundle and `<script>` tag on
111
+ * the page: every `'use client'` file (the seed set), plus every file that
112
+ * transitively instantiates one — a plain server component nested between
113
+ * the SSR root and a `'use client'` descendant still needs its own compiled
114
+ * `init` to run in the browser, because that's the ONLY place the
115
+ * `initChild(...)` call reaching the client descendant is emitted (issue
116
+ * #2767; see `DiscoveredComponent.needsClientEntry`'s docstring). A nested
117
+ * component can't self-hydrate to make up for a missing parent bundle: its
118
+ * SSR root carries the child marker (`bf-h`), which `hydrateElementScope`
119
+ * (`@barefootjs/client`'s `runtime/hydrate.ts`) unconditionally skips,
120
+ * deferring to a parent's `initChild` call that only exists if the parent's
121
+ * own bundle shipped.
122
+ *
123
+ * Deliberately NOT `analyzeClientNeeds(ir).needsInit` (the compiler's
124
+ * per-file "does this file's compiled init do anything nontrivial" signal)
125
+ * — that's true for almost any server component with dynamic content at
126
+ * all (a prop interpolation, a conditional, a `.map()`, a plain
127
+ * `onClick`...), not just ones that own a client descendant. Gating Vite
128
+ * entries on it would bundle huge swaths of purely-server trees that have
129
+ * nothing to hydrate. The property this function computes — "is there a
130
+ * `'use client'` file reachable via component-instantiation edges" — is
131
+ * inherently cross-file, so it can only be answered here, with the whole
132
+ * discovered corpus in hand, not by any single-file compiler analysis.
133
+ *
134
+ * Pure structural closure over JSX tag references — no compile. Resolves
135
+ * each file's `referencedComponents` (JSX tag names) to the file that
136
+ * exports that name via the shared `nameIndexOver` index, then walks the
137
+ * REVERSE edges breadth-first from the `isClient` seed set. Cycle-safe (a
138
+ * visited-set) and runs in O(files + edges); on this repo's real
139
+ * `ui`/`site` component corpus (~260 files) the whole discovery pass
140
+ * (parse + this closure) costs low-single-digit milliseconds.
141
+ *
142
+ * The closure only ever needs to walk upward from a `'use client'` seed:
143
+ * a client file cannot legally import a server component in the first
144
+ * place (`analyzer.ts`'s `validateClientImports` raises BF003, a hard
145
+ * compile error), so there is no "server child of a client parent needing
146
+ * its own entry" shape to account for.
147
+ */
148
+ export declare function computeClientEntryPaths(rows: readonly Pick<DiscoveredComponent, 'absPath' | 'isClient' | 'exportedComponents' | 'referencedComponents'>[]): Set<string>;
83
149
  /**
84
150
  * Component-name → absolute-path index used to resolve `@bf-child:<Name>`
85
151
  * markers (see `child-marker.ts`) to a real file: a bare-marker child
@@ -88,10 +154,16 @@ export declare function discoverComponents(entries: readonly (string | ResolvedC
88
154
  * `resolveId` needs a name→file lookup built from a full discovery pass.
89
155
  *
90
156
  * Keyed by each exported component NAME, which is what the marker
91
- * carries. Server-only files are excluded: a `@bf-child:` marker only
92
- * ever names another component this one instantiates at runtime
93
- * (`initChild`/`createComponent`), which requires an `init` function only
94
- * a `'use client'` file has.
157
+ * carries. Files that don't need their own client entry are excluded: a
158
+ * `@bf-child:` marker only ever names another component this one
159
+ * instantiates at runtime (`initChild`/`createComponent`), which requires
160
+ * a REAL `init` — and a file with `needsClientEntry: false` compiles to a
161
+ * no-op template-only mount (`generateTemplateOnlyMount` in
162
+ * `@barefootjs/jsx`'s `ir-to-client-js`), nothing to jump to. This is
163
+ * `needsClientEntry`, not `isClient` — a plain server file that owns a
164
+ * `'use client'` descendant is a legitimate marker target too (issue
165
+ * #2767: it's the file whose compiled init actually contains the
166
+ * `initChild(...)` call reaching that descendant).
95
167
  *
96
168
  * This used to key on the file's basename, which worked only because the
97
169
  * one-component-per-file convention makes the two coincide
@@ -113,5 +185,5 @@ export declare function discoverComponents(entries: readonly (string | ResolvedC
113
185
  * `components` option's order — so an earlier directory shadows a later
114
186
  * one, the same precedence the option list already implies.
115
187
  */
116
- export declare function buildChildNameIndex(discovered: readonly Pick<DiscoveredComponent, 'absPath' | 'isClient' | 'exportedComponents'>[]): Map<string, string>;
188
+ export declare function buildChildNameIndex(discovered: readonly Pick<DiscoveredComponent, 'absPath' | 'needsClientEntry' | 'exportedComponents'>[]): Map<string, string>;
117
189
  //# sourceMappingURL=discover.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../src/discover.ts"],"names":[],"mappings":"AAeA;mDACmD;AACnD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAe9D;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAO3D;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAChC,OAAO,CAAC,MAAM,EAAE,CAAC,CAwBnB;AAED,MAAM,WAAW,mBAAmB;IAClC,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAA;IACf;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,CAAA;IACf,yEAAyE;IACzE,QAAQ,EAAE,OAAO,CAAA;IACjB;;;;;;OAMG;IACH,kBAAkB,EAAE,MAAM,EAAE,CAAA;IAC5B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,yBAAyB;IACxC,qDAAqD;IACrD,GAAG,EAAE,MAAM,CAAA;IACX;+CAC2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;8CAC0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,SAAS,CAAC,MAAM,GAAG,yBAAyB,CAAC,EAAE,EACxD,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM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