Skip to content

fix: preflight schemas apply correctly when chained before for#15863

Open
PranavAgarkar07 wants to merge 3 commits into
sveltejs:mainfrom
PranavAgarkar07:fix/preflight-for-ordering
Open

fix: preflight schemas apply correctly when chained before for#15863
PranavAgarkar07 wants to merge 3 commits into
sveltejs:mainfrom
PranavAgarkar07:fix/preflight-for-ordering

Conversation

@PranavAgarkar07
Copy link
Copy Markdown

closes #15746

Root cause

preflight() and for() live in different closure scopes. preflight() is defined inside create_instance() and stores the preflight schema in that closure. for() is defined on the outer instance after create_instance() returns — when called, it creates/reuses a different cached create_instance(key) instance whose closure has preflight_schema = undefined.

This means createPost.preflight(schema).for("some id") silently drops the preflight schema, while createPost.for("some id").preflight(schema) works correctly because both methods operate on the same instance.

Fix

Used a WeakMap in the form() scope to track preflight schemas per instance. Both preflight() (inside create_instance) and for() (on the outer instance) share access to this map:

  • preflight() stores the schema keyed by the current instance
  • for() checks if the calling instance has a preflight schema in the map and propagates it to the new instance via entry.instance.preflight(schema)

Test

Added a new E2E test page at /remote/form/preflight-for that validates preflight().for('id') works end-to-end.

Verification

  • pnpm check — passes (0 errors)
  • pnpm -F @sveltejs/kit test:unit — 537/537 pass
  • pnpm prepublishOnly — types generate cleanly
  • pnpm run lint — linting clean

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 18, 2026

🦋 Changeset detected

Latest commit: 726971e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot
Copy link
Copy Markdown

@teemingc teemingc added the forms Stuff relating to forms and form actions label May 18, 2026
"@sveltejs/kit": patch
---

fix: add `null` to `RemoteFormInput` type to allow nullable schema validators
Copy link
Copy Markdown
Member

@teemingc teemingc May 18, 2026

Choose a reason for hiding this comment

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

I think this PR may accidentally have pulled in changes from #15859 which we should be separate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

forms Stuff relating to forms and form actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

preflight is not used when for is called after preflight

2 participants