-
Notifications
You must be signed in to change notification settings - Fork 367
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: support modern.js data action #4736
Conversation
|
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4736 +/- ##
==========================================
- Coverage 57.59% 50.52% -7.07%
==========================================
Files 672 691 +19
Lines 17794 19203 +1409
Branches 3876 4431 +555
==========================================
- Hits 10249 9703 -546
- Misses 6934 8746 +1812
- Partials 611 754 +143 ☔ View full report in Codecov by Sentry. |
Summary
This PR implements the RFC #4755.
🤖 Generated by Copilot at d28833c
This pull request adds support for data loader actions, which are optional files that define custom logic for fetching data in the
@modern-js/runtime
module. It refactors and updates the CLI, the runtime, and the app-tools modules to handle both loader and action requests, and to generate the appropriate code and types. It also adds and fixes some integration tests for the data loader feature, using different modes and scenarios.Details
🤖 Generated by Copilot at d28833c
createActionRequest
that creates a request handler for data loader actions (link)generateClient
function to take an object with inline, action, and routeId properties and generate client code for data loader requests accordingly (link, link, link)Context
to add more properties for data loader requests and parse them from the resourceQuery (link, link)generateClient
to pass the inline, action, and routeId properties from the options object (link)createLoaderRequest
tocreateRequest
and modify it to handle both loader and action requests (link, link, link, link, link, link, link, link)ACTION_EXPORT_NAME
that represents the name of the action export from the data loader files (link)walk
function to check if a data loader file has an action export and set the route.action property accordingly (link, link, link, link, link, link, link)generateRoutes
andgenerateLoaders
functions to include the action property in the route objects and the loadersMap object, and to use the loaderId, route, and action properties to generate the client code for data loader requests (link, link, link, link, link, link, link, link, link, link, link, link, link)hasAction
that checks if a data loader file has an action export or not (link, link)data.test.ts
that tests thehasLoader
andhasAction
functions (link)$.data.ts
that exports a loader and an action function as named exports (link)utils.ts
that exports a constantmodernTestActionName
that represents the name of the action used in the integration tests (link)page.data.ts
in the user/[id] directory that exports a loader and an action function as named exports, and use them in thepage.tsx
file in the same directory (link, link, link)page.data.ts
in the user/[id]/profile directory that exports a loader and an action function as named exports, and use them in thepage.tsx
file in the same directory (link, link, link)page.data.ts
in the user/profile directory that exports a loader function as a named export (link)supportActionInCSR
andsupportActionInSSR
that test the data loader actions in CSR and SSR modes respectively, and use them in the test cases 'support action in CSR' and 'support action in SSR' in theindex.test.ts
file (link, link, link, link)supportNoLayoutDir
function to expect the correct text for the user/[id] route (link)page.loader.ts
in the user/profile directory (link)Related Issue
Checklist
pnpm run change
.