-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(data-loader): unify the response logic of the Loader in SSR (#6720)
- Loading branch information
Showing
9 changed files
with
190 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@modern-js/plugin-data-loader': patch | ||
'@modern-js/runtime': patch | ||
--- | ||
|
||
feat: unify the response logic of the Loader in SSR | ||
feat: 统一 SSR 中 Loader 的响应逻辑 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 34 additions & 9 deletions
43
tests/integration/routes/src/three/routes/error/response/page.data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,35 @@ | ||
export const loader = () => { | ||
throw new Response( | ||
JSON.stringify({ | ||
message: "can't found the user", | ||
}), | ||
{ | ||
status: 255, | ||
}, | ||
); | ||
import type { LoaderFunctionArgs } from '@modern-js/runtime/router'; | ||
|
||
export const loader = ({ request }: LoaderFunctionArgs) => { | ||
const url = new URL(request.url); | ||
const responseType = url.searchParams.get('type') as string; | ||
const statusCode = url.searchParams.get('code') as string; | ||
|
||
if (responseType === 'throw_error') { | ||
throw new Error("can't found the user"); | ||
} | ||
|
||
if (responseType === 'throw_response') { | ||
throw new Response( | ||
JSON.stringify({ | ||
message: "can't found the user", | ||
}), | ||
{ | ||
status: Number(statusCode), | ||
}, | ||
); | ||
} | ||
|
||
if (responseType === 'return_response') { | ||
return new Response( | ||
JSON.stringify({ | ||
message: 'user modern.js', | ||
}), | ||
{ | ||
status: Number(statusCode), | ||
}, | ||
); | ||
} | ||
|
||
return null; | ||
}; |
8 changes: 2 additions & 6 deletions
8
tests/integration/routes/src/three/routes/error/response/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
import { Outlet, useLoaderData } from '@modern-js/runtime/router'; | ||
import { useLoaderData } from '@modern-js/runtime/router'; | ||
|
||
export default function Page() { | ||
const data = useLoaderData(); | ||
return ( | ||
<div> | ||
<Outlet /> | ||
</div> | ||
); | ||
return <div className="response-content">Response Page</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters