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

Single-fetch typesafety #9893

Merged
merged 17 commits into from
Aug 28, 2024
Merged

Single-fetch typesafety #9893

merged 17 commits into from
Aug 28, 2024

Conversation

pcattori
Copy link
Contributor

@pcattori pcattori commented Aug 20, 2024

Fixes #9428 #9514 #9649 #9714 #9776 #9834

TODO

  • fix tests
  • unstable_ prefix for Future.singleFetch
  • remove Future re-exports
  • Docs (vite.config.ts -> declare module "@remix-run/server-runtime")
  • changeset

Copy link

changeset-bot bot commented Aug 20, 2024

🦋 Changeset detected

Latest commit: 599ed30

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

This PR includes changesets to release 16 packages
Name Type
@remix-run/cloudflare Patch
@remix-run/deno Patch
@remix-run/node Patch
@remix-run/react Patch
@remix-run/server-runtime Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
@remix-run/dev Patch
@remix-run/architect Patch
@remix-run/express Patch
@remix-run/serve Patch
@remix-run/testing Patch
create-remix Patch
remix Patch
@remix-run/css-bundle Patch
@remix-run/eslint-config 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

@punkpeye
Copy link

I think that the code in this PR has the same issue as described here #9776

@pcattori
Copy link
Contributor Author

I think that the code in this PR has the same issue as described here #9776

Turns out the new code with Serialize<T> helper doesn't have this issue, but just added some test cases and explicit handling for ReadonlyArray to be safe.

@pcattori pcattori marked this pull request as ready for review August 28, 2024 19:14
@romansndlr
Copy link

Let's goooo!!! Can't wait for all the goodness that will come from this PR!

@pcattori
Copy link
Contributor Author

pcattori commented Aug 28, 2024

@romansndlr don't get too excited, this is just a quick patch for improved types for single-fetch in Remix, though yea that is pretty exciting on its own! The full typesafety story is coming soon in RRv7 😉 this is the first step towards that

Copy link
Contributor

@brophdawg11 brophdawg11 left a comment

Choose a reason for hiding this comment

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

👌 great work!

docs/guides/single-fetch.md Outdated Show resolved Hide resolved
@romansndlr
Copy link

@romansndlr don't get too excited, this is just a quick patch for improved types for single-fetch in Remix, though yea that is pretty exciting on its own! The full typesafety story is coming soon in RRv7 😉 this is the first step towards that

For sure! I assumed as much... This is defiantly existing on it's own but also for what's to come!

@pcattori pcattori merged commit 5a38eba into dev Aug 28, 2024
5 checks passed
@pcattori pcattori deleted the single-fetch-typesafety branch August 28, 2024 19:54
@github-actions github-actions bot added the awaiting release This issue has been fixed and will be released soon label Aug 28, 2024
```

There are also client-side equivalents un `defineClientLoader`/`defineClientAction` that don't have the same return value restrictions because data returned from `clientLoader`/`clientAction` does not need to be serialized over the wire:
Methods are also not serializable, so class instances get slimmed down to just their serializable properties:
Copy link
Member

Choose a reason for hiding this comment

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

@pcattori Couldn't Remix call classInstance.toJSON()? If it's not defined then grab the serializable properties automatically

Copy link
Contributor Author

@pcattori pcattori Aug 28, 2024

Choose a reason for hiding this comment

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

It could but that's what json(...) is for. The mental model for Single Fetch is that types are preserved as much as possible. We don't want a class with a bunch of serializable properties (Date, bigint, RegExp, etc.) to show up as a bag of strings on the client.

serhalp added a commit to netlify/remix-compute that referenced this pull request Sep 18, 2024
These unstable functions and types were removed in
remix-run/remix#9893.

Since they were clearly named `unstable_` and Remix doesn't require
major releases for changes to these, we'll do the same thing.
serhalp added a commit to netlify/remix-compute that referenced this pull request Sep 18, 2024
These unstable functions and types were removed in
remix-run/remix#9893.

Since they were clearly named `unstable_` and Remix doesn't require
major releases for changes to these, we'll do the same thing.
serhalp added a commit to netlify/remix-compute that referenced this pull request Sep 18, 2024
* fix: stop re-exporting exports removed in remix 2.12.0

These unstable functions and types were removed in
remix-run/remix#9893.

Since they were clearly named `unstable_` and Remix doesn't require
major releases for changes to these, we'll do the same thing.

* chore(deps): bump to latest remix everywhere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants