Repository navigation
Conversation
🦋 Changeset detectedLatest commit: f28519d 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 |
| if (input_value !== undefined) { | ||
| defaults[key] = input_value; | ||
| } |
There was a problem hiding this comment.
I think this could lead to out of sync values if the value changes in an event, and then it's read synchronously the line after
There was a problem hiding this comment.
Also this would not work if the code in the repro changes to this
<form {...test_form}>
// not displaying 'default text'
<p>{test_form.fields.name.value()}</p>
// displays 'default text'
<input {...test_form.fields.name.as('text', 'default text')} />
</form>There was a problem hiding this comment.
I tried puting the display before the input and it still works
There was a problem hiding this comment.
I will put it like this in the test to be sure
There was a problem hiding this comment.
I think this only works by chance and the fact that default is not stateful makes it even more weird. What should happen in this case for example?
<form {...test_form}>
// not displaying 'default text'
<p>{test_form.fields.name.value()}</p>
// displays 'default text'
{#if show}
<input {...test_form.fields.name.as('text', 'default text')} />
{/if}
</form>when show become true? What about when it become false?
I'll check with the rest of the team but I think we should probably just document this behaviour considering how weird it is.
There was a problem hiding this comment.
Works for me, I’ll let you take it from here. I don't want to mess this up :)
placing value display before input
….com:DrUse1/kit into fix/remote-form-value-undefined-with-default
CAREFUL : I needed to change a pre-existing test that was failing
<form {...test_form}>
// not displaying 'default text'
<p>{test_form.fields.name.value()}</p>
// displays 'default text'
<input {...test_form.fields.name.as('text', 'default text')} />
</form>The fundamental problem with this is that it's impossible to render correctly during SSR. When rendering on the server, the Svelte component is run top to bottom, so the renderer will always hit |
I feel like the remote form factory PR is onto something with setting initial data. Also somewhat reminiscent of how Superforms did it. |
|
I think we should be able to configure a form instance on the server and set the initial data there, then import it ready-to-use. I put together an example using available tools where I return the form instance with pre-populated data in a remote query: A new remote function for this maybe? |
|
@elliott-with-the-longest-name-on-github Is this still being looked at or assigned to a milestone? It's a major... I wouldn't say problem, but nuisance, definitely. I realize that this is probably very complicated, as you said, but I wonder if there's an issue or PR on the svelte repo I could follow, just so I can see when my pain will end. |
|
What's wrong with this? #15707 (comment) |
It forces me to write code inside the script template when it shouldn't be at all necessary. It also feels unintuitive If I have something like this: (stupid example I know, just for demo purposes) Submit your age <input {...fields.age.as('number', 18)}/>
{#if fields.age.value() < 25}
Eligible for discount!!!
{/if}
The discount banner wouldn't show. It feels like it should. To make it work I basically have to manually set a default in the script, which basically defeats the entire purpose of having a default value in the first place. It would just be a strictly inferior way to assign a default, since you couldn't even use the default value later in the template. Useful only in the scenario where you just want to submit a form and not do anything reactive with the data (which I guess is most scenarios, but it's still annoying) |
|
The bottom line is we can't merge this PR because of #15690 (comment). So the question becomes how to solve those cases. And as shown, they're already solvable with
Of course it's necessary — any time you need to initialize anything in a component you're going to have to put some code in the
These are two different things that you can use separately or together. It feels to me like we're already in good shape here |
|
Apologies, I was just going off of vibes, like how it "feels" it should work. I was unaware of just how unsolvable it is, and since the issue wasn't closed I just assumed that unsolvable meant "difficult and/or low prio". Tone is very difficult to convey via text.
I mean yeah, if that's the way it works, setting it in the script manually is the way to go. There's nothing wrong with it. This is basically just a doc entry that would need to mention this semantic disconnect between a "default" value and an "initial" value. |
|
Opened #16145 with a suggested update to the docs |
Fixes #15707 :
When calling
fields.name.as('text', 'default'), theinput_valuewas used as a display fallback in the returned props but was never accessible tofields.name.value(), which returnedundefineduntil the user interacted with the input.When
.as()is called with an input_value, it now writes it to the cache viaset_input, soget_value()can immediately return it.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