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(server-runtime): deprecate SerializeFrom type #10173

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

brophdawg11
Copy link
Contributor

No description provided.

Copy link

changeset-bot bot commented Oct 29, 2024

🦋 Changeset detected

Latest commit: f222092

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

This PR includes changesets to release 19 packages
Name Type
@remix-run/server-runtime Minor
@remix-run/cloudflare Minor
@remix-run/deno Minor
@remix-run/dev Minor
@remix-run/node Minor
@remix-run/react Minor
@remix-run/testing Minor
@remix-run/cloudflare-pages Minor
@remix-run/cloudflare-workers Minor
@remix-run/fs-routes Major
@remix-run/route-config Major
@remix-run/routes-option-adapter Major
@remix-run/architect Minor
@remix-run/express Minor
@remix-run/serve Minor
create-remix Minor
remix Minor
@remix-run/css-bundle Minor
@remix-run/eslint-config Minor

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

@brophdawg11 brophdawg11 merged commit f9764f7 into dev Oct 29, 2024
5 checks passed
@brophdawg11 brophdawg11 deleted the brophdawg11/deprecate-serliaze-from branch October 29, 2024 16:19
@github-actions github-actions bot added the awaiting release This issue has been fixed and will be released soon label Oct 29, 2024
@MichaelDeBoey MichaelDeBoey changed the title Deprecate SerializeFrom feat(server-runtime): deprecate SerializeFrom type Oct 29, 2024
Copy link
Contributor

github-actions bot commented Nov 5, 2024

🤖 Hello there,

We just published version 2.14.0-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

github-actions bot commented Nov 8, 2024

🤖 Hello there,

We just published version 2.14.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@github-actions github-actions bot removed the awaiting release This issue has been fixed and will be released soon label Nov 8, 2024
@bpetetot
Copy link

bpetetot commented Nov 10, 2024

@kentcdodds

I was able to reproduce the behavior of SerializeFrom by doing:

type SerializeFrom<T> = ReturnType<typeof useLoaderData<T>>;

It can be used in the same way as the current SerializeFrom for data from loader functions. You can make an equivalent type with useActionLoader if you need it.

@kentcdodds
Copy link
Member

Thanks! That'll work I think.

@artemis-prime
Copy link

Please, please, please document this better! What a PITA to have to poke around to use such core functionality!

@felixmokross
Copy link

felixmokross commented Jan 4, 2025

To me it seems the current implementation in RR7 doesn't cover all the use cases which SerializeFrom in Remix used to cover (at least before Single Fetch). I used it in two ways so far:

// Given these type definitions:
type SerializeFrom<T> = ReturnType<typeof useLoaderData<T>>;
type Car = {
  
  price: Prisma.Decimal;
};

// 1)
type ResultDto = SerializeFrom<typeof loader>;

// 2)
type CarDto = SerializeFrom<Car>;

Use case (1) still works since I upgraded from Remix to React Router (incl. migration to Single Fetch). But if I use it as shown in (2), CarDto just is the same as Car, it doesn't serialize the props. I use Prisma Decimals, where this is an issue.

If I look into the RR7 package, I see the following type definition for the return type of useLoader:

export type SerializeFrom<T> = T extends (...args: infer Args) => unknown
  ? Args extends [ClientLoaderFunctionArgs | ClientActionFunctionArgs]
    ? ClientDataFrom<T>
    : ServerDataFrom<T>
  : T;

So if T is not a function, it just returns T. Shouldn't it return Serialize<T>?

To work around the issue, I see that I could define CarDto like this (assuming we have a car prop on the object returned by the loader):

type CarDto = SerializeFrom<typeof loader>["car"];

But I would like to avoid having to always use a specific loader to define CarDto. I have centralized type files being used in many places which should not depend on specific routes.

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

Successfully merging this pull request may close these issues.

6 participants