-
Notifications
You must be signed in to change notification settings - Fork 111
docs: update entry.ts example in API Pipelining section #623
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,15 +14,25 @@ async function main() { | |
| let initialLoaderData: unknown | null = null; | ||
|
|
||
| for (const activity of config.activities) { | ||
| const t = makeTemplate({ path: activity.route }); | ||
| const match = t.parse(location.pathname + location.search); | ||
| let t: ReturnType<typeof makeTemplate> | null = null; | ||
|
|
||
| if (typeof activity.route === "string") { | ||
| t = makeTemplate({ path: activity.route }); | ||
| } else if (typeof activity.route === "object") { | ||
| t = makeTemplate(activity.route); | ||
| } | ||
|
Comment on lines
+19
to
+23
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the previous documentation, only a single case was provided as an example.
However, in actual use cases, activity.route can be either an object or a string, so we need to handle both cases.
Therefore, we have updated the example code to accommodate the above scenarios. |
||
|
|
||
| if (!match) { | ||
| if (!t) { | ||
| continue; | ||
| } | ||
|
|
||
| const match = t.parse(location.pathname + location.search); | ||
| if (!match || !activity.loader) { | ||
| continue; | ||
| } | ||
|
|
||
| // 1. Request API data (do not await) | ||
| initialLoaderData = activity.loader({ params: match as any }); | ||
| initialLoaderData = activity.loader({ params: match as any, config }); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| break; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,15 +14,25 @@ async function main() { | |||||||||||||||||||||
| let initialLoaderData: unknown | null = null; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| for (const activity of config.activities) { | ||||||||||||||||||||||
| const t = makeTemplate({ path: activity.route }); | ||||||||||||||||||||||
| const match = t.parse(location.pathname + location.search); | ||||||||||||||||||||||
| let t: ReturnType<typeof makeTemplate> | null = null; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (typeof activity.route === "string") { | ||||||||||||||||||||||
| t = makeTemplate({ path: activity.route }); | ||||||||||||||||||||||
| } else if (typeof activity.route === "object") { | ||||||||||||||||||||||
| t = makeTemplate(activity.route); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+19
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. null을 객체로 취급하는 것을 방지하세요 typeof null === "object" 이므로, activity.route가 nullish일 경우 makeTemplate(activity.route)가 예외를 던질 수 있어요. 객체 분기에서 null 체크를 추가해 주세요. - } else if (typeof activity.route === "object") {
- t = makeTemplate(activity.route);
+ } else if (activity.route && typeof activity.route === "object") {
+ t = makeTemplate(activity.route);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (!match) { | ||||||||||||||||||||||
| if (!t) { | ||||||||||||||||||||||
| continue; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const match = t.parse(location.pathname + location.search); | ||||||||||||||||||||||
| if (!match || !activity.loader) { | ||||||||||||||||||||||
| continue; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // 1. API 데이터를 요청해요 (await하지 않아요) | ||||||||||||||||||||||
| initialLoaderData = activity.loader({ params: match as any }); | ||||||||||||||||||||||
| initialLoaderData = activity.loader({ params: match as any, config }); | ||||||||||||||||||||||
| break; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||



There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard against null when treating route as an object
typeof null === "object". If activity.route can ever be nullish, makeTemplate(activity.route) would throw. Add a null check before the object branch.
📝 Committable suggestion
🤖 Prompt for AI Agents