fix: don't throw from remote form validate() if the form unmounts - #16720
fix: don't throw from remote form validate() if the form unmounts#16720kdelay wants to merge 2 commits into
Conversation
The element null check in validate() ran before 'await tick()', but the attachment cleanup sets element to null on unmount. If the <form> was removed while validate() was waiting for the tick, the resumed call threw 'Cannot read properties of null (reading querySelector)'. Re-check element after the tick and bail out if the form is gone.
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/ad409342628607eb1466a1c2213e3d099ba447e0Open in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: ad40934 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
A note on the red This branch is based on The diff here is limited to |
closes #16696
validate()checkselementbeforeawait tick(), but the attachment cleanup setselement = nullwhen the<form>unmounts. If the form is removed whilevalidate()is waiting for that tick — e.g. an{#if}flips right after a fast submission — the resumed call throws:The fix re-checks
elementafter the tick and bails out if the form is gone, which matches what the pre-tick check already intends.Tests
Added a case to the
asynctest app's existing/remote/form/validateroute: a form inside an{#if}block, and a button that startsvalidate()and unmounts the form in the same handler, catching whatever the promise rejects with. The new test fails onversion-3(TypeError: Cannot read properties of null (reading 'querySelector')) and passes with this change.Rebased onto
version-3at a115a7b and re-verified locally on Node 24.18.0:pnpm lint: 0 errors (one pre-existing warning insrc/runtime/server/page/index.js, untouched here).pnpm test:unit: 895 passed, 11 failed. The 11 failures are inkit-prerendering-paths-baseandkit-prerendering-optionsand reproduce identically on unpatchedversion-3, so they are not from this change.asynctest app,pnpm test:dev: 193 passed, 103 skipped, 0 failed. The new test also passes inchromium-buildandchromium-build-no-js.pnpm checkfails on unpatchedversion-3as well, with 24TS2300: Duplicate identifiererrors fromsrc/types/ambient.d.ts. This branch changes no types, so I could not get a clean baseline for that step.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits