Skip to content

refactor(pages): share adapter build-plugin code that must stay in sync - #673

Merged
cpojer merged 1 commit into
voidzero-dev:mainfrom
yangshun:refactor/shared-adapter-build-plugins
Nov 3, 2026
Merged

cpojer merged 1 commit into
voidzero-dev:mainfrom
yangshun:refactor/shared-adapter-build-plugins

Conversation

@yangshun

@yangshun yangshun commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

The React, Vue, Svelte and Solid adapters each kept their own copy of build-plugin logic that is tied to core contracts. This moves those parts into core as plain helpers. Each adapter keeps its own Vite plugin object and its framework rendering and hydration codegen.

void/pages-islands-plugin

  • createIslandManifest(root, extensions): resolves island imports to ids and pre-scans island pages and layouts. It follows the page scan model, so a new layout kind now needs one change instead of four.
  • islandCssFiles(...) and generateIslandClientEntry(...): the islands client entry's CSS strategy (dev skip, server-recorded styles, fallback) and the initIslands runtime. Adapters pass in what is framework-specific: style-block imports for Vue and Svelte, and the hydrateIsland source.
  • islandsBuildConfig(root, pagesDir): the islands-client build input.
  • mdClientScriptIds(resolvedConfig): the void-md plugin API lookup. computePagesNeedingClientJS now uses it too.

void/pages

  • PrefetchConfig (its cacheFor is now CacheForInput) and PagesPluginOptions. Each adapter's plugin-pages.ts re-exports PrefetchConfig, so the name stays the same.
  • resolvePrefetchConfig(prefetch): the 75 ms / '30s' defaults, which were repeated in four codegen strings.

The adapter plugin-islands.ts files shrink by about 130–180 lines each.

Left in the adapters on purpose

Some code is repeated but differs by framework, or isn't tied to a core contract, so it stays where it is:

  • the island renderer and page renderer/client codegen
  • the island-import transforms and wrapper modules (Svelte's query-encoded wrapper ids, Solid's wrapper metadata, Vue's <script setup> injection)
  • Svelte's style compile plugin and Vue's cssScopeTo handling
  • the useForm warning
  • Vue and Svelte's filename-based hasNonIslandPages (React and Solid use the scan). pages-plugin-adapters.test.ts pins this difference, so unifying it would be a separate behavior change.

Behavior changes

  • In the no-server-build fallback, the list of island CSS files is now recomputed on each buildStart instead of accumulating across buildStart calls. In vite build --watch, a deleted island page's styles stop being imported. A single build is unchanged.
  • Solid's generated islands client entry names its hydrate function hydrateIsland instead of mountIsland. This only changes generated code.
  • resolveSpecifier now accepts a ReadonlyArray of extensions (type widening only).

Generated client and renderer output is otherwise unchanged.

Verification

  • vp run --filter './packages/**' typecheck: all 12 packages pass. A full vp run check also typechecks playgrounds, which need vp run build:all first; I didn't run that locally.
  • Unit tests for every adapter's plugin-islands and plugin-pages, plus pages-plugin-adapters, pages-islands-rescan and island-css-rewrite: 11 files, 175 tests pass.
  • Every islands and pages integration test in the adapter packages and @void/md: 18 files, 259 tests pass.
  • Full vp test run: 732 files pass and 31 fail. None of the failures come from this change:
    • 26 platform suites fail to load because this fresh worktree has no generated platform/packages/dashboard/.void/tsconfig.json.
    • astro dev, vinext-pages dev and cf-build-output timed out under full-suite load. All 3 files pass on their own (54 tests).
    • The health-script failure has the same tsconfig cause.

🤖 Generated with Claude Code

The React, Vue, Svelte and Solid islands and pages plugins each kept their
own copy of logic that is tied to core contracts. Move those parts into
`void/pages-islands-plugin` and `void/pages` as plain helpers; each adapter
keeps its Vite plugin object and its framework rendering and hydration code.

- `createIslandManifest`: island id resolution and the island page/layout
  pre-scan, which follow the page scan model.
- `islandCssFiles`, `generateIslandClientEntry`: the islands client entry's
  CSS strategy and `initIslands` runtime; adapters pass their style-block
  imports and `hydrateIsland` source.
- `islandsBuildConfig`: the `islands-client` build input.
- `mdClientScriptIds`: the `void-md` plugin API lookup.
- `PrefetchConfig`, `PagesPluginOptions`, `resolvePrefetchConfig`: the
  public adapter options and their defaults. Adapters re-export
  `PrefetchConfig`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yangshun
yangshun marked this pull request as draft November 2, 2026 12:48
@yangshun
yangshun marked this pull request as ready for review November 2, 2026 13:13

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay less code.

@cpojer
cpojer merged commit f284a82 into voidzero-dev:main Nov 3, 2026
2 checks passed
cpojer pushed a commit that referenced this pull request Nov 3, 2026
## Summary

Moves the form contracts that every adapter promises into core
(`packages/void/src/pages/form-presentation.ts`, next to
`FormModel`/`FormMethod`). Only contracts that must not drift between
adapters are shared. Framework idioms stay in the adapters.

**Shared in core** (`FormState`, `IslandFormState` and
`FormSubmitOptions` are exported from `void/pages-client`)

| Type | Members | Used by |
| --- | --- | --- |
| `FormStatus` | `error`, `pending`, `hasChanges`, `wasSuccessful`,
`recentlySuccessful` | `useForm` and `useIslandForm` in all four
adapters; `FormModel` takes `pending` and `error` from it |
| `FormState<TData, TEditing>` | `FormStatus` + `data`, `errors`
(field-keyed), `reset` (with the `{ initial }` overload that core's
`parseFormResetArgs` parses), `setError`, `clearErrors`, `clearError` |
`useForm`, all four adapters |
| `IslandFormState<TData, TEditing>` | `FormStatus` + `data`, `errors`
(keyed by any name the action returns), `reset` (field-typed),
`clearErrors`, `clearError`, `post/put/patch/delete(url)` |
`useIslandForm`, all four adapters |
| `FormSubmitOptions` | `Omit<VisitOptions, 'method' \| 'data'> & {
data? }`, previously byte-identical in Vue, Svelte and Solid | `useForm`
in Vue, Svelte and Solid |

Core defines the `data` and `errors` types once, including the rule for
error keys. Each adapter must pick an editing mode, and there is no
default:
- `'in-place'` for Vue and Svelte: apps edit `data` and `errors`
directly.
- `'setters'` for React and Solid: `data` and `errors` are `Readonly`
and change through `setData`, `setError` and `clearErrors`.

**Kept in adapters** (agreed API decisions; no behavior change)
- React's `post/put/patch/delete(formData: FormData)` stay native `<form
action>` callbacks. Vue, Svelte and Solid keep `post(opts?:
FormSubmitOptions)`.
- `setData` stays in React and Solid only. Vue and Svelte bind to
`form.data` directly.
- Island `submit(url, method)` stays in Vue and Svelte only, and island
`setData` stays in React and Solid only.

Each adapter has a local `FormReturn<TData>` alias. The typed overload
and the implementation signature both use it, so they can no longer
drift. It replaces each adapter's `UntypedForm` and its duplicated typed
return object. Vue's `useIslandForm` now uses the same overload pattern.
Its returned object is checked against the island contract; before, it
was cast to it. Svelte's `useIslandForm` is now generic like the other
three adapters, so `form.data` and `reset()` field names are typed from
the defaults instead of `Record<string, unknown>`.

## TypeScript compatibility (release note)

Form types now follow each framework's idiom. Runtime behavior is
unchanged.

- **Top-level form fields are read-only in every adapter**, for both
`useForm()` and `useIslandForm()`: `data`, `errors`, `error`, `pending`,
`hasChanges`, `wasSuccessful` and `recentlySuccessful`. Writing
`form.pending = true` or replacing `form.data = { … }` no longer
compiles, because a replaced `data` or `errors` object is no longer the
one the form submits and updates. Form methods are read-only too. This
is new for `useForm()` in `@void/react`, `@void/vue` and `@void/solid`;
Svelte and island forms already had read-only fields.
- **React and Solid: the contents of `data` and `errors` are read-only**
(both hooks). `form.data.email = …` and `form.errors.email = …` no
longer compile; use `setData()`, `setError()` and `clearErrors()`. In
React these writes changed the submitted data without re-rendering.
Solid stores ignore them. In Solid, a write into `form.errors` also
changed the server errors that every form shares.
- **Vue and Svelte: `data` and `errors` stay editable in place**
(`v-model`, `bind:value`, `form.errors.title = …`). No setters are
required.
- **Island `errors` values are `string | undefined`** in every adapter,
matching `useForm()`. `form.errors.title.length` now needs a guard;
before, it compiled and then crashed when the field had no error.
- **Svelte `useIslandForm()` infers its data type from `defaults`**,
like the other adapters. These now fail to compile: reading a field that
is not in `defaults`, passing an unknown field to `reset()`, and
assigning a value of a different type. A `null` default needs its full
type, for example `{ photo: null as File | null }`, as React, Vue and
Solid already require.

## Risk

- Type-only change, apart from Vue's `useIslandForm` dropping an `as`
cast. The emitted JavaScript is unchanged.
- TypeScript ignores `readonly` when checking assignability, so `<Form
form={form}>` and other consumers are unaffected. The typecheck tests
now assert this.
- No user docs change. `void/pages-client` is adapter-facing, and the
documented form API is unchanged.

## Verification

- `vp run check:sdk`: 12/12 packages pass. Each adapter's
`form-errors.typecheck.ts` and `island-form.typecheck.ts` pin:
  - read-only top-level fields and methods;
- that `data` and `errors` are editable in Vue and Svelte and read-only
in React and Solid;
  - that `useForm()` is accepted by `<Form form>` (`FormModel`);
  - which adapters have `setData` or `submit()`;
  - each adapter's submit signature;
  - that island errors may be `undefined` and accept any key;
  - typed island `data` and `reset` fields.
- The four `*-pages` playgrounds typecheck against the rebuilt adapters.
- Focused form unit tests: 1295 tests pass.
- Earlier on this branch: `vp run test` passed 515 tests with 1 skipped.
The 27 platform-unit failures came from a missing generated
`platform/packages/dashboard/.void/tsconfig.json` in a fresh worktree;
after generating it, all 27 pass. `vp test run` passed 759 of 764 files
with 1 skipped. Four failed only under full-suite load and all pass when
rerun on their own: the astro dev server start timeout, and timeouts in
`db-template`, `deploy-direct-r2` and `zero-trust-service`.
- `vp lint` and `vp fmt --check` are clean on the changed files.
- After merging `main` (including #672 and #673, which share Link and
build-plugin code through the same `void/pages-client` entry), there
were no conflicts. `vp run check:sdk` passes 12/12, the four `*-pages`
playgrounds typecheck, and `vp test run form island` passes 357 files
(7349 tests, 22 skipped).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants