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] load data through regular json request #7177

Merged
merged 4 commits into from
Oct 10, 2022
Merged

[fix] load data through regular json request #7177

merged 4 commits into from
Oct 10, 2022

Conversation

dummdidumm
Copy link
Member

using devalue's stringify/parse methods
Part of #7125 and #6477

Not sure exactly what's left for the above issues to get closed besides allowing setting cache headers again.

If we change to this we could use the same methods for interacting with form actions, allowing them to also return Date objects for example.

Marked as draft, @Rich-Harris feel free to take over/close.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • 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

using devalue's stringify/parse methods
Part of #7125 and #6477
@changeset-bot
Copy link

changeset-bot bot commented Oct 7, 2022

🦋 Changeset detected

Latest commit: aa6535f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@sveltejs/adapter-netlify Patch
@sveltejs/adapter-vercel Patch
@sveltejs/kit Patch
@sveltejs/adapter-auto Patch

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

@Rich-Harris
Copy link
Member

If we change to this we could use the same methods for interacting with form actions, allowing them to also return Date objects for example.

The wrinkle here is that if someone posts to an action manually, they'll get devalue-encoded data in return. We could handle it in SSR and use:enhance but would presumably need to expose something like

import { decode } from '$app/forms';

or, more directly,

import { decode } from 'devalue'; // doesn't currently exist, but decode(obj) would === parse(JSON.stringify(obj))

I think it's fine to merge this as-is then handle headers in a separate PR, so I'm marking this ready

@Rich-Harris Rich-Harris marked this pull request as ready for review October 10, 2022 16:55
Copy link
Member Author

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't approve because it's my own PR, but consider this an approval in case the answer to my question in the code-comment is "yes".
Edit: Oh and this needs a changeset.

@@ -10,6 +16,7 @@ import { HttpError, Redirect } from '../control.js';
import { stores } from './singletons.js';
import { DATA_SUFFIX } from '../../constants.js';
import { unwrap_promises } from '../../utils/promises.js';
import * as devalue from 'devalue';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will tree shaking remove the other stuff correctly if we write the import like this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, Rollup doesn't care either way

@0gust1
Copy link
Contributor

0gust1 commented Oct 11, 2022

Thanks, I'll check if it fixes #7203 !

@Tal500
Copy link
Contributor

Tal500 commented Oct 19, 2022

I'm glad to see this PR fixes a theoretical consideration on a closed issue of mine:
fixes #6466

Worth to mark this issue as "fixed" in the main description of this PR, for automatic referencing to the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants