Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sverdle form reset #7241

Merged
merged 3 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/yellow-kids-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

fix sverdle guesses incorrectly cleared by form `enhance`
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts">
import { confetti } from '@neoconfetti/svelte';
import { enhance } from '$app/forms';
import { applyAction, enhance } from '$app/forms';
import type { PageData, ActionData } from './$types';
import { invalidateAll } from '$app/navigation';

/** @type {import('./$types').PageData} */
export let data: PageData;
Expand Down Expand Up @@ -78,7 +79,19 @@

<svelte:window on:keydown={keydown} />

<form method="POST" action="?/enter" use:enhance>
<form
method="POST"
action="?/enter"
use:enhance={() => {
// prevent default callback from resetting the form
return async ({ result }) => {
if (result.type === 'success') {
await invalidateAll();
}
await applyAction(result);
};
}}
>
<a class="how-to-play" href="/sverdle/how-to-play">How to play</a>

<div class="grid" class:playing={!won} class:bad-guess={form?.badGuess}>
Expand Down