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

fix: parse routerDataFnArgs in mergeLoaderData function #6475

Open
wants to merge 2 commits into
base: test-parse-merge-data
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fifty-starfishes-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/runtime': patch
---

fix: parse `routerDataFnArgs` in `mergeLoaderData` function
fix: 在 `mergeLoaderData` 函数中解析 routerDataFnArgs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const DeferredDataScripts = (props?: {
return {
key,
routerDataFnName: 's',
routerDataFnArgs: [routeId, key],
routerDataFnArgs: [serializeJson(routeId), serializeJson(key)],
};
} else {
const trackedPromise = deferredData.data[key] as TrackedPromise;
Expand All @@ -98,7 +98,10 @@ const DeferredDataScripts = (props?: {
return {
key,
routerDataFnName: 'p',
routerDataFnArgs: [undefined, serializeJson(error)],
routerDataFnArgs: [
serializeJson(undefined),
serializeJson(error),
],
};
} else {
if (typeof trackedPromise._data === 'undefined') {
Expand Down
10 changes: 8 additions & 2 deletions packages/runtime/plugin-runtime/src/router/runtime/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,15 @@ export const preResolvedFnStr = `function p(e,r){return void 0!==r?Promise.rejec
* Abstracting the above logic to `mergeLoaderData`:
* function mergeLoaderData (routeIdJsonStr, deferredKeyPromiseManifests) {
const source = deferredKeyPromiseManifests.reduce(function(o, {key, routerDataFnName, routerDataFnArgs }) {
return {...o, [key]: _ROUTER_DATA[routerDataFnName](...routerDataFnArgs)}
const args = routerDataFnArgs.map(arg => {
if (arg === 'undefined' || arg === null) {
return undefined;
}
return JSON.parse(arg);
});
return {...o, [key]: _ROUTER_DATA[routerDataFnName](...args)};
}, {});
Object.assign(_ROUTER_DATA.loaderData[routeIdJsonStr], source);
};
*/
export const mergeLoaderDataStr = `function mergeLoaderData(a,e){e=e.reduce(function(a,{key:e,routerDataFnName:r,routerDataFnArgs:t}){return{...a,[e]:_ROUTER_DATA[r](...t)}},{});Object.assign(_ROUTER_DATA.loaderData[a],e)}`;
export const mergeLoaderDataStr = `function mergeLoaderData(e,n){const r=n.reduce((function(e,{key:n,routerDataFnName:r,routerDataFnArgs:a}){const t=a.map((e=>{if("undefined"!==e&&null!==e)return JSON.parse(e)}));return console.info("args",t),{...e,[n]:_ROUTER_DATA[r](...t)}}),{});Object.assign(_ROUTER_DATA.loaderData[e],r)}`;
Loading