Repository: sveltejs/kit (js)

Issue:
Form Actions throw error if one if the form field name is also `action`
### Describe the bug

When we have one of the form field name as `action` it is conflicting with the form's action and throw following error 

<img width="605" alt="image" src="https://user-images.githubusercontent.com/627951/201166934-0aa4461c-f266-44e3-a732-ce59616bc969.png">


### Reproduction

create a form with one of the field  name as `action`
```html
<form class="space-y-6" method="POST" action="?/save" use:enhance>
      <input type="text" name="action"  id="action"    value={policy.action} />
      <button>Save</button>
</form>
```

### Logs

```Shell
forms.js?v=360cc9a6:50 Uncaught (in promise) TypeError: Failed to construct 'URL': Invalid URL
    at HTMLFormElement.handle_submit (forms.js?v=360cc9a6:50:18)
    at HTMLFormElement.sentryWrapped (helpers.ts:98:1)
```


### System Info

```Shell
System:
    OS: macOS 13.0
    CPU: (10) arm64 Apple M1 Max
    Memory: 30.77 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.11.0 - /opt/homebrew/bin/node
    npm: 8.19.2 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 107.0.5304.110
    Safari: 16.1
  npmPackages:
    @sveltejs/adapter-auto: 1.0.0-next.87 => 1.0.0-next.87 
    @sveltejs/adapter-node: 1.0.0-next.100 => 1.0.0-next.100 
    @sveltejs/adapter-static: 1.0.0-next.48 => 1.0.0-next.48 
    @sveltejs/kit: 1.0.0-next.538 => 1.0.0-next.538 
    svelte: 3.52.0 => 3.52.0 
    vite: 3.2.3 => 3.2.3
```


### Severity

annoyance

### Additional Information

I have this form before migrating to the new `Form Actions` to create/update my form data. I was using `svelte-forms-lib` and using fetch to post data before and was working. now when I am trying Form Actions, I noticed this bug


```ts
export const actions: Actions = {
	save: async ({ request }) => {
		const formData = await request.formData();
		console.log('save action formData:', formData);
		return {
			success: true
		};
	}
};
```

Pull request description:
Workaround for the DOM clobbering for use:enhance
Fixes #7593

### Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] 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
- [x] This message body should clearly illustrate what problems it solves.
- [x] Ideally, include a test that fails without this PR but passes with it.

### Tests
- [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` and `pnpm check`

### Changesets
- [x] 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. All changesets should be `patch` until SvelteKit 1.0


Patch:
diff --git a/.changeset/cyan-beds-smoke.md b/.changeset/cyan-beds-smoke.md
new file mode 100644
index 000000000..4d10340ca
--- /dev/null
+++ b/.changeset/cyan-beds-smoke.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+Don't print search params error when prerendering fallback page
diff --git a/.changeset/real-onions-pull.md b/.changeset/real-onions-pull.md
new file mode 100644
index 000000000..4b1873697
--- /dev/null
+++ b/.changeset/real-onions-pull.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+Workaround for the DOM clobbering for use:enhance
diff --git a/packages/kit/src/runtime/app/forms.js b/packages/kit/src/runtime/app/forms.js
index 9359f146b..513f153cb 100644
--- a/packages/kit/src/runtime/app/forms.js
+++ b/packages/kit/src/runtime/app/forms.js
@@ -27,7 +27,8 @@ export function enhance(form, submit = () => {}) {
 	const fallback_callback = async ({ action, result, reset }) => {
 		if (result.type === 'success') {
 			if (reset !== false) {
-				form.reset();
+				// We call reset from the prototype to avoid DOM clobbering
+				HTMLFormElement.prototype.reset.call(form);
 			}
 			await invalidateAll();
 		}
@@ -49,9 +50,10 @@ export function enhance(form, submit = () => {}) {
 
 		const action = new URL(
 			// We can't do submitter.formAction directly because that property is always set
+			// We do cloneNode for avoid DOM clobbering - https://github.com/sveltejs/kit/issues/7593
 			event.submitter?.hasAttribute('formaction')
 				? /** @type {HTMLButtonElement | HTMLInputElement} */ (event.submitter).formAction
-				: form.action
+				: /** @type {HTMLFormElement} */ (HTMLFormElement.prototype.cloneNode.call(form)).action
 		);
 
 		const data = new FormData(form);
@@ -117,11 +119,13 @@ export function enhance(form, submit = () => {}) {
 		});
 	}
 
-	form.addEventListener('submit', handle_submit);
+	// @ts-expect-error
+	HTMLFormElement.prototype.addEventListener.call(form, 'submit', handle_submit);
 
 	return {
 		destroy() {
-			form.removeEventListener('submit', handle_submit);
+			// @ts-expect-error
+			HTMLFormElement.prototype.removeEventListener.call(form, 'submit', handle_submit);
 		}
 	};
 }
diff --git a/packages/kit/src/runtime/server/index.js b/packages/kit/src/runtime/server/index.js
index 572b02f32..e88f2a30f 100644
--- a/packages/kit/src/runtime/server/index.js
+++ b/packages/kit/src/runtime/server/index.js
@@ -102,7 +102,7 @@ export async function respond(request, options, state) {
 
 	const { cookies, new_cookies, get_cookie_header } = get_cookies(request, url, options);
 
-	if (state.prerendering) disable_search(url);
+	if (state.prerendering && !state.prerendering.fallback) disable_search(url);
 
 	/** @type {import('types').RequestEvent} */
 	const event = {


Test patch:
diff --git a/packages/kit/test/apps/basics/src/routes/actions/enhance/+page.svelte b/packages/kit/test/apps/basics/src/routes/actions/enhance/+page.svelte
index 032b7ca9c..5ee9f544e 100644
--- a/packages/kit/test/apps/basics/src/routes/actions/enhance/+page.svelte
+++ b/packages/kit/test/apps/basics/src/routes/actions/enhance/+page.svelte
@@ -14,6 +14,8 @@
 <pre class="formdata2">{JSON.stringify($page.form)}</pre>
 
 <form method="post" action="?/login" use:enhance>
+	<input type=hidden name="action" value="DOM clobbering" />
+	<input type=hidden name="reset" value="DOM clobbering" />
 	<input name="username" type="text" />
 	<button class="form1">Submit</button>
 	<button class="form1-register" formAction="?/register">Submit</button>