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

feat: warn if page endpoint body is not serializable #5635

Closed
wants to merge 5 commits into from

Conversation

gtm-nayan
Copy link
Contributor

#4944 #5358 #5545

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

@changeset-bot
Copy link

changeset-bot bot commented Jul 20, 2022

🦋 Changeset detected

Latest commit: 6780d98

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit 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

import { coalesce_to_error } from '../../../utils/error.js';
import { domain_matches, path_matches } from './cookie.js';
import { is_pojo, warn_if_not_serdeable } from './utils.js';
Copy link
Member

Choose a reason for hiding this comment

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

TIL that serdeable is an actual word 😄

Copy link
Contributor Author

@gtm-nayan gtm-nayan Jul 20, 2022

Choose a reason for hiding this comment

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

Serde is common in the rust circles. Guess it hasn't carried over much outside, will change if it's not clear although need suggestions cause I'm horrible at it.

/**
* @param {any} v
*/
export function is_pojo(v) {
Copy link
Member

Choose a reason for hiding this comment

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

It irks me a little that there's another function with the same name which does something different, and both have no short description so you have to jump into the code and usage locations to know what's this about.
Also: What's the TODO about?

Copy link
Contributor Author

@gtm-nayan gtm-nayan Jul 20, 2022

Choose a reason for hiding this comment

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

Yeah, the other one does a lot of other stuff specific to Response body types that's not actually checking if it's a plain object. I did want to rename it but likely in a separate PR that touches that part of the code.

The TODO is lodash's implementations making me paranoid about some weird JavaScript behaviors that I'm unaware of.

Copy link
Member

Choose a reason for hiding this comment

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

Should we add a comment about this with a link to lodash's implementation and something like "if people ever run into weird edge cases where this doesn't behave as expected, look into lodash's implementation more closely"?


/** @param {any} v */
export function is_serializable_primitive(v) {
// TODO: javascript-isms
Copy link
Member

Choose a reason for hiding this comment

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

What's the TODO about?

@gtm-nayan
Copy link
Contributor Author

Gmail told me to look at the CI, and jesus christ that's scary, going to look at it tomorrow

@gtm-nayan
Copy link
Contributor Author

gtm-nayan commented Jul 21, 2022

Ughh, __SVELTEKIT_DEV__ is throwing a reference error. baaf46e sounds like it's the same thing however here it might mean massive amounts of param drilling to do the same.

@Rich-Harris
Copy link
Member

It occurred to me that since we always need to serialize the data, we can do the checks at serialization time with a custom replacer argument to JSON.stringify, with very little overhead. I implemented that in a new PR since this one is a little out of date since #5778, so I'll close this — thanks

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.

3 participants