Skip to content

Use devalue with form actions #7488

@CalebBassham

Description

@CalebBassham

Describe the problem

Some objects, like Date, can be persisted on the client using the load() in a +page.server.js. The same is not true of Actions in the same file.

This can be quite confusing. Because they are in the same file, even though load and Actions are not the same, many people consider them to work basically the same because of how similar they are. Not to mention how really similar they were before form actions.

It is also quite inconvenient for the developer. You can easily imagine a situation where in the load function you are sending the client a list of objects. One of the keys in the object is a Date. Let's say lastModified. Now, on the same page you fill out a form that creates a new record. You want to use progressive enhancement, so you create an enhance function where you are going to receive the new record, so you can display it alongside the existing ones. But wait, the returned record is not quite the same as the records you got from the initial load because you did not receive a Date. Instead you got some sort of string representing it. Now you have to deal with parsing it. Or, you go back to the load function and make it also just give a string, so you don't have to worry about the different behavior.

Both solutions make some sense, but now that you have two ways of doing something, both are probably going to be used throughout the code base. Making it harder to maintain overall.

Describe the proposed solution

Use devalue to persist some objects from the server to the client when using Actions in the same way that is already done using load()

Alternatives considered

Leave as is and make devs deal with the poor dx. 🤷🏻

Importance

would make my life easier

Additional Information

Example: https://github.com/CalebBassham/repro-sk-actions-devalue/blob/master/src/routes/%2Bpage.server.js

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions