@void/react 1.6.2 → 1.7.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/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AnchorHTMLAttributes, ButtonHTMLAttributes, Context, FormHTMLAttributes, JSX, ReactElement, ReactNode } from "react";
2
2
  import { ActionClient, BaseLinkProps, FormMethod, FormModel, FormState, IslandFormState, NavigationState, VoidActionError, VoidActionError as VoidActionError$1, VoidRouter, isCallSiteActionError, isVoidActionError } from "void/pages-client";
3
+ import { ActionFormOptions, ActionUrl, PageParams, PagePath, ResolveActionBody } from "void/routes";
3
4
  import { CloudContextVariables, InferProps } from "void";
4
- import { ActionFormOptions, ActionUrl, ResolveActionBody } from "void/routes";
5
5
  type FormProps = Omit<FormHTMLAttributes<HTMLFormElement>, "action" | "onSubmit" | "method" | "onError"> & {
6
6
  form: FormModel<[FormData]>;
7
7
  method?: FormMethod;
@@ -11,7 +11,16 @@ export declare function Form({ form, method, renderError, children, ...props }:
11
11
  type LinkProps = BaseLinkProps & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof BaseLinkProps> & Omit<ButtonHTMLAttributes<HTMLButtonElement>, keyof BaseLinkProps>;
12
12
  export declare function Link({ href, method, data, preserveScroll, preserveState, replace, reloadDocument, viewTransition, prefetch, cacheFor, activeMatch, onNavigate, children, style, onClick: onClickProp, onMouseEnter: onMouseEnterProp, onMouseLeave: onMouseLeaveProp, onFocus: onFocusProp, onMouseDown: onMouseDownProp, onTouchStart: onTouchStartProp, ...rest }: LinkProps): JSX.Element;
13
13
  export declare function useRouter(): VoidRouter;
14
+ /**
15
+ * Read the dynamic route params of the page being rendered.
16
+ *
17
+ * Pass the page's URL pattern as the type argument to type the result:
18
+ * `useParams<'/users/:id'>()` returns `{ id: string }`. This is a type-only
19
+ * check; the params are returned as they are.
20
+ */
14
21
  export declare function useParams<T extends Record<string, string> = Record<string, string>>(): T;
22
+ export declare function useParams<P extends PagePath>(): PageParams<P>;
23
+ export declare function useParams(): Record<string, string>;
15
24
  export declare function useShared<T = CloudContextVariables["shared"]>(): T;
16
25
  type FormReturn<TData> = FormState<TData, "setters"> & Readonly<{
17
26
  setData: <K extends keyof TData & string>(field: K, value: TData[K]) => void;
package/dist/index.mjs CHANGED
@@ -1,22 +1,20 @@
1
1
  import { a as RouterContext, i as ParamsContext, n as FrontmatterContext, o as SharedContext, r as NavigationContext, t as ErrorsContext } from "./context-BQpawTZc.mjs";
2
2
  import { n as setActionRouter, t as action } from "./action-CyCVdW12.mjs";
3
3
  import { useActionState, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
4
- import { cloneFormValue, formErrorMessage, formRetryMessage, formSubmissionBlocked, getValidationErrors, handleLinkClick, interpolateRouteParams, isAbortError, isCallSiteActionError, isEqualFormValue, isVoidActionError, linkActiveAttributes, linkPendingAttributes, linkPrefetchStrategies, observeLinkVisible, parseFormResetArgs, prefetchLink, resolveLink, scheduleFormRetry, ssrProxy, submitAction, submitIslandAction } from "void/pages-client";
4
+ import { cloneFormValue, formErrorMessage, formRetryMessage, formSubmissionBlocked, getValidationErrors, handleLinkClick, interpolateRouteParams, isAbortError, isCallSiteActionError, isEqualFormValue, isVoidActionError, linkActiveAttributes, linkPendingAttributes, linkPrefetchStrategies, observeLinkVisible, parseFormResetArgs, prefetchLink, resolveLink, ssrProxy, submitAction, submitIslandAction } from "void/pages-client";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
6
  // src/runtime/form.tsx
7
7
  function Form({ form, method = "post", renderError, children, ...props }) {
8
- const [now, setNow] = useState(Date.now);
9
- useEffect(() => scheduleFormRetry(form.error, () => setNow(Date.now())), [form.error]);
10
8
  const message = formErrorMessage(form);
11
9
  const retry = formRetryMessage(form.error);
12
- const blocked = formSubmissionBlocked(form, now);
10
+ const onSubmit = useCallback((event) => {
11
+ if (formSubmissionBlocked(form)) event.preventDefault();
12
+ }, [form]);
13
13
  return /* @__PURE__ */ jsxs("form", {
14
14
  ...props,
15
15
  action: form[method],
16
16
  "aria-busy": form.pending,
17
- onSubmit: (event) => {
18
- if (blocked) event.preventDefault();
19
- },
17
+ onSubmit,
20
18
  children: [message && /* @__PURE__ */ jsxs("div", {
21
19
  role: "alert",
22
20
  "data-void-form-error": true,
@@ -209,37 +207,105 @@ function useShared() {
209
207
  return shared;
210
208
  }
211
209
  // src/runtime/use-form.ts
210
+ const EMPTY_ERRORS$1 = {};
211
+ function resolveOutcomeErrors(outcome, edits) {
212
+ if (edits?.source === outcome && edits.errors !== void 0) return edits.errors;
213
+ return outcome.status === "validation" ? outcome.errors : EMPTY_ERRORS$1;
214
+ }
212
215
  function useForm(url, defaults, options) {
213
216
  const router = useContext(RouterContext);
214
217
  const [data, setDataState] = useState(() => cloneFormValue(defaults));
215
- const [defaultsState, setDefaultsState] = useState(() => cloneFormValue(defaults));
216
- const [errors, setErrors] = useState({});
217
- const [error, setActionError] = useState(null);
218
- const [wasSuccessful, setWasSuccessful] = useState(false);
219
- const [recentlySuccessful, setRecentlySuccessful] = useState(false);
220
- const defaultsRef = useRef(defaultsState);
221
- const initialRef = useRef(defaultsState);
218
+ const [initialDefaults] = useState(() => cloneFormValue(defaults));
219
+ const [errorEdits, setErrorEdits] = useState(null);
220
+ const [expiredOutcome, setExpiredOutcome] = useState(null);
222
221
  const dataRef = useRef(data);
223
- const successTimeoutRef = useRef(null);
222
+ const callbackOutcomeRef = useRef(null);
223
+ const runErrorCallback = async (nextOutcome, errorArg) => {
224
+ callbackOutcomeRef.current = nextOutcome;
225
+ try {
226
+ await options?.onError?.(errorArg);
227
+ } finally {
228
+ if (callbackOutcomeRef.current === nextOutcome) callbackOutcomeRef.current = null;
229
+ }
230
+ return nextOutcome;
231
+ };
232
+ const [outcome, dispatchAction, pending] = useActionState(async (previousOutcome, payload) => {
233
+ if (!router) throw new Error("useForm(): requires the Void Router.");
234
+ let result;
235
+ try {
236
+ result = await submitAction(router, interpolateRouteParams(url, options?.params), {
237
+ method: payload.method,
238
+ data: payload.snapshot,
239
+ preserveScroll: options?.preserveScroll,
240
+ _resolveOnShell: true
241
+ });
242
+ } catch (submitError) {
243
+ if (isAbortError(submitError)) return {
244
+ status: "idle",
245
+ defaults: previousOutcome.defaults
246
+ };
247
+ throw submitError;
248
+ }
249
+ if (!result.ok) {
250
+ const validationErrors = getValidationErrors(result.error.body);
251
+ if (validationErrors) return runErrorCallback({
252
+ status: "validation",
253
+ defaults: previousOutcome.defaults,
254
+ errors: validationErrors
255
+ }, validationErrors);
256
+ return runErrorCallback({
257
+ status: "error",
258
+ defaults: previousOutcome.defaults,
259
+ error: result.error
260
+ }, result.error);
261
+ }
262
+ const nextOutcome = {
263
+ status: "success",
264
+ defaults: options?.resetOnSuccess ? cloneFormValue(initialDefaults) : cloneFormValue(payload.snapshot)
265
+ };
266
+ callbackOutcomeRef.current = nextOutcome;
267
+ try {
268
+ await options?.onSuccess?.();
269
+ } finally {
270
+ if (callbackOutcomeRef.current === nextOutcome) callbackOutcomeRef.current = null;
271
+ }
272
+ if (options?.resetOnSuccess && dataRef.current === payload.dispatchData) {
273
+ dataRef.current = cloneFormValue(initialDefaults);
274
+ setDataState(dataRef.current);
275
+ }
276
+ return nextOutcome;
277
+ }, {
278
+ status: "idle",
279
+ defaults: initialDefaults
280
+ });
281
+ const defaultsState = outcome.defaults;
224
282
  const hasChanges = useMemo(() => {
225
283
  return Object.keys(defaultsState).some((key) => !isEqualFormValue(data[key], defaultsState[key]));
226
284
  }, [data, defaultsState]);
227
285
  const setData = useCallback((field, value) => {
286
+ const previousValue = dataRef.current[field];
228
287
  dataRef.current = {
229
288
  ...dataRef.current,
230
289
  [field]: value
231
290
  };
232
291
  setDataState(dataRef.current);
233
- setErrors((prev) => {
234
- if (!(field in prev)) return prev;
235
- const next = { ...prev };
292
+ if (isEqualFormValue(previousValue, value)) return;
293
+ const target = callbackOutcomeRef.current ?? outcome;
294
+ setErrorEdits((prev) => {
295
+ const current = resolveOutcomeErrors(target, prev);
296
+ if (!(field in current)) return prev;
297
+ const next = { ...current };
236
298
  delete next[field];
237
- return next;
299
+ return {
300
+ ...prev?.source === target ? prev : { source: target },
301
+ errors: next
302
+ };
238
303
  });
239
- }, []);
304
+ }, [outcome]);
240
305
  const reset = useCallback((...args) => {
241
306
  const { initial, fields } = parseFormResetArgs(args);
242
- const source = initial ? initialRef.current : defaultsRef.current;
307
+ const target = callbackOutcomeRef.current ?? outcome;
308
+ const source = initial ? initialDefaults : target.defaults;
243
309
  if (fields.length === 0) dataRef.current = cloneFormValue(source);
244
310
  else {
245
311
  const next = { ...dataRef.current };
@@ -247,84 +313,57 @@ function useForm(url, defaults, options) {
247
313
  dataRef.current = next;
248
314
  }
249
315
  setDataState(dataRef.current);
250
- }, []);
316
+ }, [initialDefaults, outcome]);
251
317
  const clearErrors = useCallback((...fields) => {
252
- if (fields.length === 0) setErrors({});
253
- else setErrors((prev) => {
254
- const next = { ...prev };
318
+ const target = callbackOutcomeRef.current ?? outcome;
319
+ setErrorEdits((prev) => {
320
+ const base = prev?.source === target ? prev : { source: target };
321
+ if (fields.length === 0) return {
322
+ ...base,
323
+ errors: EMPTY_ERRORS$1
324
+ };
325
+ const next = { ...resolveOutcomeErrors(target, prev) };
255
326
  for (const field of fields) delete next[field];
256
- return next;
327
+ return {
328
+ ...base,
329
+ errors: next
330
+ };
257
331
  });
258
- }, []);
332
+ }, [outcome]);
259
333
  const setError = useCallback((field, message) => {
260
- setErrors((prev) => ({
261
- ...prev,
262
- [field]: message
334
+ const target = callbackOutcomeRef.current ?? outcome;
335
+ setErrorEdits((prev) => ({
336
+ ...prev?.source === target ? prev : { source: target },
337
+ errors: {
338
+ ...resolveOutcomeErrors(target, prev),
339
+ [field]: message
340
+ }
263
341
  }));
264
- }, []);
342
+ }, [outcome]);
265
343
  const clearError = useCallback(() => {
266
- setActionError(null);
267
- }, []);
268
- const [, dispatchAction, pending] = useActionState(async (previousSuccessVersion, payload) => {
269
- if (!router) throw new Error("useForm(): requires the Void Router.");
270
- const method = payload instanceof FormData ? "POST" : payload.method;
271
- setWasSuccessful(false);
272
- setRecentlySuccessful(false);
273
- if (successTimeoutRef.current) {
274
- clearTimeout(successTimeoutRef.current);
275
- successTimeoutRef.current = null;
276
- }
277
- setErrors({});
278
- setActionError(null);
279
- let result;
280
- try {
281
- result = await submitAction(router, interpolateRouteParams(url, options?.params), {
282
- method,
283
- data: { ...dataRef.current },
284
- preserveScroll: options?.preserveScroll,
285
- _resolveOnShell: true
286
- });
287
- } catch (submitError) {
288
- if (isAbortError(submitError)) return previousSuccessVersion;
289
- throw submitError;
290
- }
291
- if (!result.ok) {
292
- const validationErrors = getValidationErrors(result.error.body);
293
- if (validationErrors) {
294
- setErrors(validationErrors);
295
- await options?.onError?.(validationErrors);
296
- } else {
297
- setActionError(result.error);
298
- await options?.onError?.(result.error);
299
- }
300
- return previousSuccessVersion;
301
- }
302
- if (options?.resetOnSuccess) {
303
- dataRef.current = cloneFormValue(initialRef.current);
304
- setDataState(dataRef.current);
305
- }
306
- const nextDefaults = cloneFormValue(dataRef.current);
307
- defaultsRef.current = nextDefaults;
308
- setDefaultsState(nextDefaults);
309
- setWasSuccessful(true);
310
- setRecentlySuccessful(true);
311
- successTimeoutRef.current = setTimeout(() => {
312
- setRecentlySuccessful(false);
313
- successTimeoutRef.current = null;
314
- }, 2e3);
315
- await options?.onSuccess?.();
316
- return previousSuccessVersion + 1;
317
- }, 0);
344
+ const target = callbackOutcomeRef.current ?? outcome;
345
+ setErrorEdits((prev) => ({
346
+ ...prev?.source === target ? prev : { source: target },
347
+ dismissActionError: true
348
+ }));
349
+ }, [outcome]);
350
+ const errors = pending ? EMPTY_ERRORS$1 : resolveOutcomeErrors(outcome, errorEdits);
351
+ const error = pending || outcome.status !== "error" || errorEdits?.source === outcome && errorEdits.dismissActionError ? null : outcome.error;
352
+ const wasSuccessful = !pending && outcome.status === "success";
353
+ const recentlySuccessful = wasSuccessful && expiredOutcome !== outcome;
318
354
  useEffect(() => {
319
- return () => {
320
- if (successTimeoutRef.current) {
321
- clearTimeout(successTimeoutRef.current);
322
- successTimeoutRef.current = null;
323
- }
324
- };
325
- }, []);
355
+ if (outcome.status !== "success") return;
356
+ const timer = setTimeout(() => {
357
+ setExpiredOutcome(outcome);
358
+ }, 2e3);
359
+ return () => clearTimeout(timer);
360
+ }, [outcome]);
326
361
  const dispatchMethodAction = useCallback((method) => (_formData) => {
327
- dispatchAction({ method });
362
+ dispatchAction({
363
+ method,
364
+ snapshot: cloneFormValue(dataRef.current),
365
+ dispatchData: dataRef.current
366
+ });
328
367
  }, [dispatchAction]);
329
368
  return {
330
369
  data,
@@ -335,7 +374,7 @@ function useForm(url, defaults, options) {
335
374
  hasChanges,
336
375
  wasSuccessful,
337
376
  recentlySuccessful,
338
- post: dispatchAction,
377
+ post: useMemo(() => dispatchMethodAction("POST"), [dispatchMethodAction]),
339
378
  put: useMemo(() => dispatchMethodAction("PUT"), [dispatchMethodAction]),
340
379
  patch: useMemo(() => dispatchMethodAction("PATCH"), [dispatchMethodAction]),
341
380
  delete: useMemo(() => dispatchMethodAction("DELETE"), [dispatchMethodAction]),
@@ -350,75 +389,127 @@ function useNavigation() {
350
389
  return useContext(NavigationContext);
351
390
  }
352
391
  // src/runtime/use-island-form.ts
392
+ const EMPTY_ERRORS = {};
353
393
  /**
354
394
  * Form hook for island pages. Uses fetch + page reload instead of the
355
395
  * Void Router (which is not available in island mode).
356
396
  */
357
397
  function useIslandForm(defaults) {
358
- const [data, setDataState] = useState(() => ({ ...defaults }));
359
- const [defaultsState, setDefaultsState] = useState(() => ({ ...defaults }));
360
- const [errors, setErrors] = useState({});
361
- const [error, setError] = useState(null);
362
- const [pending, setPending] = useState(false);
363
- const [wasSuccessful, setWasSuccessful] = useState(false);
364
- const [recentlySuccessful, setRecentlySuccessful] = useState(false);
365
- const defaultsRef = useRef(defaultsState);
366
- const successTimeoutRef = useRef(null);
398
+ const [data, setDataState] = useState(() => cloneFormValue(defaults));
399
+ const [outcome, setOutcome] = useState(() => ({
400
+ status: "idle",
401
+ defaults: cloneFormValue(defaults)
402
+ }));
403
+ const [expiredOutcome, setExpiredOutcome] = useState(null);
404
+ const dataRef = useRef(data);
405
+ const latestRequestIdRef = useRef(0);
406
+ const defaultsState = outcome.defaults;
407
+ const pending = outcome.status === "pending";
408
+ const errors = outcome.status === "validation" ? outcome.errors : EMPTY_ERRORS;
409
+ const error = outcome.status === "error" ? outcome.error : null;
410
+ const wasSuccessful = outcome.status === "success";
411
+ const recentlySuccessful = wasSuccessful && expiredOutcome !== outcome;
367
412
  const hasChanges = useMemo(() => {
368
413
  return Object.keys(defaultsState).some((key) => !isEqualFormValue(data[key], defaultsState[key]));
369
414
  }, [data, defaultsState]);
415
+ useEffect(() => {
416
+ if (outcome.status !== "success") return;
417
+ const timer = setTimeout(() => setExpiredOutcome(outcome), 2e3);
418
+ return () => clearTimeout(timer);
419
+ }, [outcome]);
370
420
  const setData = useCallback((field, value) => {
371
- setDataState((prev) => ({
372
- ...prev,
421
+ const previousValue = dataRef.current[field];
422
+ dataRef.current = {
423
+ ...dataRef.current,
373
424
  [field]: value
374
- }));
375
- }, []);
376
- const reset = useCallback((...fields) => {
377
- if (fields.length === 0) setDataState({ ...defaultsRef.current });
378
- else setDataState((prev) => {
379
- const next = { ...prev };
380
- for (const field of fields) next[field] = defaultsRef.current[field];
381
- return next;
425
+ };
426
+ setDataState(dataRef.current);
427
+ if (isEqualFormValue(previousValue, value)) return;
428
+ setOutcome((prev) => {
429
+ if (prev.status !== "validation" || !(field in prev.errors)) return prev;
430
+ const next = { ...prev.errors };
431
+ delete next[field];
432
+ return {
433
+ status: "validation",
434
+ defaults: prev.defaults,
435
+ errors: next
436
+ };
382
437
  });
383
438
  }, []);
439
+ const reset = useCallback((...fields) => {
440
+ if (fields.length === 0) dataRef.current = cloneFormValue(defaultsState);
441
+ else {
442
+ const next = { ...dataRef.current };
443
+ for (const field of fields) next[field] = cloneFormValue(defaultsState[field]);
444
+ dataRef.current = next;
445
+ }
446
+ setDataState(dataRef.current);
447
+ }, [defaultsState]);
384
448
  const clearErrors = useCallback((...fields) => {
385
- if (fields.length === 0) setErrors({});
386
- else setErrors((prev) => {
387
- const next = { ...prev };
449
+ setOutcome((prev) => {
450
+ if (prev.status !== "validation") return prev;
451
+ if (fields.length === 0) return {
452
+ status: "idle",
453
+ defaults: prev.defaults
454
+ };
455
+ const next = { ...prev.errors };
388
456
  for (const field of fields) delete next[field];
389
- return next;
457
+ return {
458
+ status: "validation",
459
+ defaults: prev.defaults,
460
+ errors: next
461
+ };
390
462
  });
391
463
  }, []);
392
464
  const clearError = useCallback(() => {
393
- setError(null);
465
+ setOutcome((prev) => prev.status === "error" ? {
466
+ status: "idle",
467
+ defaults: prev.defaults
468
+ } : prev);
394
469
  }, []);
395
470
  const submit = useCallback(async (url, method) => {
396
- setPending(true);
397
- setWasSuccessful(false);
398
- setRecentlySuccessful(false);
399
- if (successTimeoutRef.current) clearTimeout(successTimeoutRef.current);
400
- setErrors({});
401
- setError(null);
471
+ const requestId = ++latestRequestIdRef.current;
472
+ const submittedData = cloneFormValue(dataRef.current);
473
+ setOutcome((prev) => ({
474
+ status: "pending",
475
+ defaults: prev.defaults,
476
+ requestId
477
+ }));
402
478
  try {
403
- const result = await submitIslandAction(url, method, data);
479
+ const result = await submitIslandAction(url, method, submittedData);
480
+ if (requestId !== latestRequestIdRef.current) return;
404
481
  if (result.kind === "redirect") {
482
+ setOutcome((prev) => ({
483
+ status: "idle",
484
+ defaults: prev.defaults
485
+ }));
405
486
  window.location.href = result.url;
406
487
  return;
407
488
  }
408
489
  if (result.kind === "success") {
409
- setWasSuccessful(true);
410
- setRecentlySuccessful(true);
411
- const nextDefaults = { ...data };
412
- defaultsRef.current = nextDefaults;
413
- setDefaultsState(nextDefaults);
414
- successTimeoutRef.current = setTimeout(() => setRecentlySuccessful(false), 2e3);
490
+ setOutcome({
491
+ status: "success",
492
+ defaults: submittedData
493
+ });
415
494
  window.location.reload();
416
- } else if (result.kind === "validation") setErrors(result.errors);
417
- else setError(result.error);
418
- } finally {
419
- setPending(false);
495
+ } else if (result.kind === "validation") setOutcome((prev) => ({
496
+ status: "validation",
497
+ defaults: prev.defaults,
498
+ errors: result.errors
499
+ }));
500
+ else setOutcome((prev) => ({
501
+ status: "error",
502
+ defaults: prev.defaults,
503
+ error: result.error
504
+ }));
505
+ } catch (submitError) {
506
+ if (requestId === latestRequestIdRef.current) setOutcome((prev) => prev.status === "pending" && prev.requestId === requestId ? {
507
+ status: "idle",
508
+ defaults: prev.defaults
509
+ } : prev);
510
+ throw submitError;
420
511
  }
421
- }, [data]);
512
+ }, []);
422
513
  return {
423
514
  data,
424
515
  setData,
package/dist/plugin.mjs CHANGED
@@ -3,6 +3,7 @@ import { createPagesPlugin, generateComponentManifest, resolveEffectiveLayoutCha
3
3
  import { existsSync, readFileSync } from "node:fs";
4
4
  import nodePath from "node:path";
5
5
  import { ISLANDS_CLIENT_ENTRY_ID, ISLANDS_RENDERER_ID, computePagesNeedingClientJS, createIslandManifest, editIslandSource, findIslandImports, generateIslandClientEntry, islandCssFiles, islandStylesPlugin, islandsBuildConfig, mdClientScriptIds, recordIslandStyles, recordedIslandStyles, resolveSpecifier, watchPagesForRescan } from "void/pages-islands-plugin";
6
+ import { fileURLToPath } from "node:url";
6
7
  // ../../node_modules/.pnpm/pathslash@0.1.0/node_modules/pathslash/dist/index.mjs
7
8
  const BACKSLASH_RE = /\\/g;
8
9
  const isWindows = process.platform === "win32";
@@ -52,11 +53,8 @@ const REACT_OPTIMIZE_DEPS = [
52
53
  "react-dom"
53
54
  ];
54
55
  const CLIENT_OPTIMIZE_DEPS = [...REACT_OPTIMIZE_DEPS, "react-dom/client"];
55
- const WORKER_OPTIMIZE_DEPS = [
56
- ...REACT_OPTIMIZE_DEPS,
57
- "react-dom/server",
58
- "void/live/client"
59
- ];
56
+ const WORKER_OPTIMIZE_DEPS = [...REACT_OPTIMIZE_DEPS, "react-dom/server"];
57
+ const NODE_MODULES_SEGMENT = /[\\/]node_modules[\\/]/;
60
58
  const REACT_REFRESH_PREAMBLE = `
61
59
  <script type="module">
62
60
  import RefreshRuntime from "/@react-refresh"
@@ -83,17 +81,13 @@ function pagesPlugin(pagesDir, options) {
83
81
  optimizeDeps: {
84
82
  exclude: ["@void/react"],
85
83
  entries: clientOptimizeEntries(await scan(), pagesDir, root),
86
- include: [
87
- ...CLIENT_OPTIMIZE_DEPS,
88
- "void/pages-client",
89
- "void/pages-prefetch"
90
- ]
84
+ include: [...CLIENT_OPTIMIZE_DEPS, ...installedDependencies(["void/pages-client", "void/pages-prefetch"])]
91
85
  },
92
86
  ssr: { optimizeDeps: { include: [...CLIENT_OPTIMIZE_DEPS, "react-dom/server"] } },
93
87
  environments: { [WORKER_ENVIRONMENT_NAME]: { optimizeDeps: {
94
88
  exclude: ["@void/react"],
95
89
  entries: [pagesOptimizeEntries],
96
- include: WORKER_OPTIMIZE_DEPS
90
+ include: [...WORKER_OPTIMIZE_DEPS, ...installedDependencies(["void/live/client"])]
97
91
  } } }
98
92
  };
99
93
  if (!(await scan())?.pages.some((page) => !page.island)) return;
@@ -107,6 +101,17 @@ function pagesPlugin(pagesDir, options) {
107
101
  }
108
102
  });
109
103
  }
104
+ /**
105
+ * Keeps the specifiers that resolve into `node_modules`. Vite serves a linked
106
+ * package, such as `void` in a workspace, as source unless
107
+ * `optimizeDeps.include` lists it. A listed linked package is pre-bundled into
108
+ * a cache keyed by the lockfile and config rather than the package's files, so
109
+ * dev would keep serving that copy after the package is rebuilt. A client built
110
+ * against the new exports then fails to load and never hydrates.
111
+ */
112
+ function installedDependencies(specifiers, resolveFile = (specifier) => fileURLToPath(import.meta.resolve(specifier))) {
113
+ return specifiers.filter((specifier) => NODE_MODULES_SEGMENT.test(resolveFile(specifier)));
114
+ }
110
115
  function clientOptimizeEntries(scan, pagesDir, root) {
111
116
  if (!scan) return [];
112
117
  const browserFiles = /* @__PURE__ */ new Set();
@@ -285,10 +290,10 @@ function islandsPlugin(pagesDir, options) {
285
290
  end: islandImport.end,
286
291
  text: replacement
287
292
  });
288
- wrappers.push(`var ${name} = function ${name}(props) { return _React_island.createElement("div", { "data-island": ${JSON.stringify(islandId)}, "data-props": JSON.stringify(props), "data-hydrate": ${JSON.stringify(strategy)} }, _React_island.createElement(${rawName}, props)); };`);
293
+ wrappers.push(`var ${name} = function ${name}(props) { return _React_island.createElement("div", { "data-island": ${JSON.stringify(islandId)}, "data-props": _serializeIslandProps(props), "data-hydrate": ${JSON.stringify(strategy)} }, _React_island.createElement(${rawName}, props)); };`);
289
294
  }
290
295
  if (wrappers.length > 0) return editIslandSource(code, edits, {
291
- prepend: "import _React_island from \"react\";\n",
296
+ prepend: "import _React_island from \"react\";\nimport { serializePageData as _serializeIslandProps } from \"void/pages-server\";\n",
292
297
  append: "\n" + wrappers.join("\n")
293
298
  });
294
299
  }
@@ -1,5 +1,5 @@
1
- import { a as RouterContext, i as ParamsContext, o as SharedContext, r as NavigationContext, t as ErrorsContext } from "../context-BQpawTZc.mjs";
2
1
  import { n as setActionRouter } from "../action-CyCVdW12.mjs";
2
+ import { a as RouterContext, i as ParamsContext, o as SharedContext, r as NavigationContext, t as ErrorsContext } from "../context-BQpawTZc.mjs";
3
3
  import { n as DEFERRED_SHELL_END_ID } from "../deferred-shell-D5T32zXz.mjs";
4
4
  import React, { Suspense, startTransition, use, useCallback, useEffect, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useState, useTransition } from "react";
5
5
  import { createPageNavigationEngine, createRouterFacade, idleNavigationState, isAbortError, isCallSiteActionError, refreshPage, toUrlString } from "void/pages-client";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@void/react",
3
- "version": "1.6.2",
3
+ "version": "1.7.0",
4
4
  "description": "React pages, server rendering, forms, and navigation for Void.",
5
5
  "homepage": "https://void.cloud",
6
6
  "bugs": {
@@ -38,7 +38,7 @@
38
38
  "access": "public"
39
39
  },
40
40
  "dependencies": {
41
- "@vitejs/plugin-react": "^6.1.2"
41
+ "@vitejs/plugin-react": "^6.2.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^26.6.6",
@@ -48,15 +48,15 @@
48
48
  "pathslash": "^0.1.0",
49
49
  "react": "^19.3.1",
50
50
  "react-dom": "^19.3.1",
51
- "vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
52
- "vite-plus": "1.4.0",
53
- "void": "1.6.2"
51
+ "vite": "npm:@voidzero-dev/vite-plus-core@1.5.0",
52
+ "vite-plus": "1.5.0",
53
+ "void": "1.7.0"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "react": "^19.0.0",
57
57
  "react-dom": "^19.0.0",
58
58
  "vite": "^8.0.0",
59
- "void": "1.6.2"
59
+ "void": "1.7.0"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "vp pack",