weifuwu 0.17.11 → 0.17.13

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/index.js CHANGED
@@ -578,6 +578,14 @@ import { useSyncExternalStore, createContext } from "react";
578
578
  var fallbackT = (key, _params, fallback) => fallback ?? key;
579
579
  var _ctx = { params: {}, query: {}, parsed: {}, prefs: {}, env: {}, t: fallbackT, user: {} };
580
580
  var _listeners = /* @__PURE__ */ new Set();
581
+ var subscribe = (cb) => {
582
+ _listeners.add(cb);
583
+ return () => {
584
+ _listeners.delete(cb);
585
+ };
586
+ };
587
+ var getSnapshot = () => ({ params: _ctx.params, query: _ctx.query, user: _ctx.user, parsed: _ctx.parsed, prefs: _ctx.prefs, env: _ctx.env });
588
+ var getServerSnapshot = getSnapshot;
581
589
  function setCtx(value) {
582
590
  _ctx = { ..._ctx, ...value };
583
591
  _listeners.forEach((fn) => fn());
@@ -595,18 +603,9 @@ function _buildT() {
595
603
  };
596
604
  }
597
605
  function useCtx() {
598
- useSyncExternalStore(
599
- (cb) => {
600
- _listeners.add(cb);
601
- return () => {
602
- _listeners.delete(cb);
603
- };
604
- },
605
- () => _ctx,
606
- () => _ctx
607
- );
606
+ useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
608
607
  const data = typeof window !== "undefined" ? window.__WEIFUWU_CTX : null;
609
- const t = data?.t ?? (_ctx.t !== fallbackT ? _ctx.t : _buildT());
608
+ const t = _ctx.t !== fallbackT ? _ctx.t : _buildT();
610
609
  return { ..._ctx, ...data, t };
611
610
  }
612
611
  var TsxContext = createContext({ params: {}, query: {}, parsed: {}, prefs: {}, env: {}, t: fallbackT, user: {} });
@@ -919,6 +918,12 @@ var TsxInstance = class {
919
918
  };
920
919
  this.router.all("/*", handler);
921
920
  }
921
+ for (const p of pages) {
922
+ if (p.entryPath) {
923
+ const rootLayouts = resolveLayouts(this.pagesDir, this.pagesDir);
924
+ this.registerClientBundleRoute(p.entryPath, p.layouts.length > 0 ? p.layouts : rootLayouts, this.pagesDir);
925
+ }
926
+ }
922
927
  await this.setupTailwind();
923
928
  if (isDev) {
924
929
  this.router.ws("/__weifuwu/livereload", {
@@ -1022,15 +1027,21 @@ ${src}`;
1022
1027
  }
1023
1028
  }
1024
1029
  async getOrBuildClientBundle(entryPath, layoutPaths, pagesDir) {
1030
+ const key = id(entryPath);
1031
+ const url = `/__wfw/client/${key}.js`;
1032
+ this.clientBuildParams.set(key, { entryPath, layoutPaths, pagesDir });
1033
+ if (!this.clientBundleCache.has(key)) {
1034
+ const buf = await this.buildClientBundle(entryPath, layoutPaths, pagesDir);
1035
+ if (!buf) return null;
1036
+ this.clientBundleCache.set(key, buf);
1037
+ }
1038
+ return { url };
1039
+ }
1040
+ registerClientBundleRoute(entryPath, layoutPaths, pagesDir) {
1025
1041
  const key = id(entryPath);
1026
1042
  const url = `/__wfw/client/${key}.js`;
1027
1043
  this.clientBuildParams.set(key, { entryPath, layoutPaths, pagesDir });
1028
1044
  if (!this.clientRouteLog.has(url)) {
1029
- if (!this.clientBundleCache.has(key)) {
1030
- const buf = await this.buildClientBundle(entryPath, layoutPaths, pagesDir);
1031
- if (!buf) return null;
1032
- this.clientBundleCache.set(key, buf);
1033
- }
1034
1045
  this.router.get(url, async () => {
1035
1046
  let buf = this.clientBundleCache.get(key);
1036
1047
  if (!buf) {
@@ -1049,7 +1060,6 @@ ${src}`;
1049
1060
  });
1050
1061
  this.clientRouteLog.add(url);
1051
1062
  }
1052
- return { url };
1053
1063
  }
1054
1064
  // ── SSR handler ───────────────────────────────────────────────────────────
1055
1065
  makeSsrHandler(entryPath, layoutPaths, loadPath) {
package/dist/react.js CHANGED
@@ -146,6 +146,14 @@ import { useSyncExternalStore, createContext } from "react";
146
146
  var fallbackT = (key, _params, fallback) => fallback ?? key;
147
147
  var _ctx = { params: {}, query: {}, parsed: {}, prefs: {}, env: {}, t: fallbackT, user: {} };
148
148
  var _listeners = /* @__PURE__ */ new Set();
149
+ var subscribe = (cb) => {
150
+ _listeners.add(cb);
151
+ return () => {
152
+ _listeners.delete(cb);
153
+ };
154
+ };
155
+ var getSnapshot = () => ({ params: _ctx.params, query: _ctx.query, user: _ctx.user, parsed: _ctx.parsed, prefs: _ctx.prefs, env: _ctx.env });
156
+ var getServerSnapshot = getSnapshot;
149
157
  function setCtx(value) {
150
158
  _ctx = { ..._ctx, ...value };
151
159
  _listeners.forEach((fn) => fn());
@@ -163,18 +171,9 @@ function _buildT() {
163
171
  };
164
172
  }
165
173
  function useCtx() {
166
- useSyncExternalStore(
167
- (cb) => {
168
- _listeners.add(cb);
169
- return () => {
170
- _listeners.delete(cb);
171
- };
172
- },
173
- () => _ctx,
174
- () => _ctx
175
- );
174
+ useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
176
175
  const data = typeof window !== "undefined" ? window.__WEIFUWU_CTX : null;
177
- const t = data?.t ?? (_ctx.t !== fallbackT ? _ctx.t : _buildT());
176
+ const t = _ctx.t !== fallbackT ? _ctx.t : _buildT();
178
177
  return { ..._ctx, ...data, t };
179
178
  }
180
179
  var TsxContext = createContext({ params: {}, query: {}, parsed: {}, prefs: {}, env: {}, t: fallbackT, user: {} });
@@ -396,19 +395,19 @@ function createStore(initial) {
396
395
  state = { ...state, ...next };
397
396
  listeners.forEach((fn) => fn());
398
397
  };
399
- const subscribe = (listener) => {
398
+ const subscribe2 = (listener) => {
400
399
  listeners.add(listener);
401
400
  return () => {
402
401
  listeners.delete(listener);
403
402
  };
404
403
  };
405
404
  const useStore = ((selector) => useSyncExternalStore2(
406
- subscribe,
405
+ subscribe2,
407
406
  () => selector ? selector(state) : state
408
407
  ));
409
408
  useStore.getState = getState;
410
409
  useStore.setState = setState;
411
- useStore.subscribe = subscribe;
410
+ useStore.subscribe = subscribe2;
412
411
  return useStore;
413
412
  }
414
413
  var dataCache = /* @__PURE__ */ new Map();
@@ -488,7 +487,7 @@ function notifyQueryListeners() {
488
487
  window.dispatchEvent(new PopStateEvent("popstate"));
489
488
  }
490
489
  function useQueryState(key, defaultValue = "") {
491
- function getSnapshot() {
490
+ function getSnapshot2() {
492
491
  if (typeof window === "undefined") return defaultValue;
493
492
  const params = new URLSearchParams(window.location.search);
494
493
  return params.get(key) ?? defaultValue;
@@ -500,12 +499,12 @@ function useQueryState(key, defaultValue = "") {
500
499
  window.addEventListener("popstate", cb);
501
500
  return () => window.removeEventListener("popstate", cb);
502
501
  },
503
- getSnapshot,
502
+ getSnapshot2,
504
503
  () => defaultValue
505
504
  );
506
505
  const setValue = useCallback4((val) => {
507
506
  if (typeof window === "undefined") return;
508
- const resolved = typeof val === "function" ? val(getSnapshot()) : val;
507
+ const resolved = typeof val === "function" ? val(getSnapshot2()) : val;
509
508
  const url = new URL(window.location.href);
510
509
  if (resolved === defaultValue || resolved === "") {
511
510
  url.searchParams.delete(key);
@@ -25,6 +25,7 @@ export declare class TsxInstance {
25
25
  private setupTailwind;
26
26
  private buildClientBundle;
27
27
  private getOrBuildClientBundle;
28
+ private registerClientBundleRoute;
28
29
  private makeSsrHandler;
29
30
  private startFileWatcher;
30
31
  private recompileAndSwap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weifuwu",
3
- "version": "0.17.11",
3
+ "version": "0.17.13",
4
4
  "description": "Web-standard HTTP framework for Node.js — (req, ctx) => Response",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",