@uniflowed/vite 0.0.0-alpha.31 → 0.0.0-alpha.32

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.
Files changed (2) hide show
  1. package/internal/rsc.js +20 -10
  2. package/package.json +5 -5
package/internal/rsc.js CHANGED
@@ -145,6 +145,7 @@ export function clientRouteFilter(manifest, root, boundaries = {}) {
145
145
 
146
146
  const notFound = boundaries.notFound ?? [];
147
147
  const errors = boundaries.errors ?? [];
148
+ const needsSlot = slotPredicate(needed);
148
149
 
149
150
  return (route) => {
150
151
  if (needed(route.page)) return true;
@@ -156,7 +157,7 @@ export function clientRouteFilter(manifest, root, boundaries = {}) {
156
157
  // interactive part is in a slot would be dropped from the client bundle
157
158
  // and served as a document — rendered correctly and never hydrated, which
158
159
  // is the quietest way a feature can be half-implemented.
159
- if (slotNeeds(route.slots ?? [], needed)) return true;
160
+ if ((route.slots ?? []).some(needsSlot)) return true;
160
161
  // A boundary with no module of its own is the record the scan synthesises
161
162
  // at the router root, and what renders there is the framework's own page —
162
163
  // already in `@uniflowed/router`, reaching nothing this project wrote. It
@@ -187,19 +188,28 @@ export function clientRouteFilter(manifest, root, boundaries = {}) {
187
188
  * @param {ReadonlyArray<{
188
189
  * defaultPage: ?string,
189
190
  * routes: ReadonlyArray<{page: string, layouts: ReadonlyArray<string>, slots: ReadonlyArray<*>}>,
190
- * }>} slots
191
191
  * @param {(file: ?string) => boolean} needed
192
+ * @returns {(slot: *) => boolean}
192
193
  */
193
- function slotNeeds(slots, needed) {
194
- for (const slot of slots) {
195
- if (slot.defaultPage != null && needed(slot.defaultPage)) return true;
194
+ function slotPredicate(needed) {
195
+ const cache = new WeakMap();
196
+ const needsSlot = (slot) => {
197
+ const cached = cache.get(slot);
198
+ if (cached !== undefined) return cached;
199
+ let answer = false;
200
+ if (slot.defaultPage != null && needed(slot.defaultPage)) {
201
+ answer = true;
202
+ }
196
203
  for (const route of slot.routes) {
197
- if (needed(route.page)) return true;
198
- if (route.layouts.some(needed)) return true;
199
- if (slotNeeds(route.slots, needed)) return true;
204
+ if (answer) break;
205
+ if (needed(route.page) || route.layouts.some(needed) || route.slots.some(needsSlot)) {
206
+ answer = true;
207
+ }
200
208
  }
201
- }
202
- return false;
209
+ cache.set(slot, answer);
210
+ return answer;
211
+ };
212
+ return needsSlot;
203
213
  }
204
214
 
205
215
  // ---------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniflowed/vite",
3
- "version": "0.0.0-alpha.31",
3
+ "version": "0.0.0-alpha.32",
4
4
  "description": "Vite, driven by uf.config.js: every Flow module through `uf transform`, MDX, the file-system router and static rendering as Vite plugins.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,10 +34,10 @@
34
34
  "dependencies": {
35
35
  "@mdx-js/rollup": "^3.1.1",
36
36
  "@shikijs/rehype": "^3.23.0",
37
- "@uniflowed/host": "0.0.0-alpha.31",
38
- "@uniflowed/router": "0.0.0-alpha.31",
39
- "@uniflowed/server": "0.0.0-alpha.31",
40
- "@uniflowed/validator": "0.0.0-alpha.31",
37
+ "@uniflowed/host": "0.0.0-alpha.32",
38
+ "@uniflowed/router": "0.0.0-alpha.32",
39
+ "@uniflowed/server": "0.0.0-alpha.32",
40
+ "@uniflowed/validator": "0.0.0-alpha.32",
41
41
  "rehype-slug": "^6.0.0",
42
42
  "remark-frontmatter": "^5.0.0",
43
43
  "remark-gfm": "^4.0.1",