Skip to content

Commit

Permalink
chore: remove html element inject
Browse files Browse the repository at this point in the history
  • Loading branch information
zllkjc committed Dec 23, 2024
1 parent af76f9e commit 100edf5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .changeset/young-trains-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/plugin-router-v5': patch
'@modern-js/runtime': patch
---

chore: remove server data parse when use convention routes
chore: 移除约定式路由时解析 server data 的逻辑
18 changes: 2 additions & 16 deletions packages/server/core/src/plugins/render/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,10 @@ async function renderHandler(
response = csrRender(options.html);
}

const newRes = transformResponse(response, injectServerData(serverData));

const { routeInfo } = options;
applyExtendHeaders(newRes, routeInfo);
applyExtendHeaders(response, routeInfo);

return newRes;
return response;

function applyExtendHeaders(r: Response, route: ServerRoute) {
Object.entries(route.responseHeaders || {}).forEach(([k, v]) => {
Expand Down Expand Up @@ -357,15 +355,3 @@ function csrRender(html: string): Response {
}),
});
}

function injectServerData(serverData: Record<string, any>) {
const { head } = REPLACE_REG.before;
const searchValue = new RegExp(head);

const replcaeCb = (beforeHead: string) =>
`${beforeHead}<script type="application/json" id="__MODERN_SERVER_DATA__">${JSON.stringify(
serverData,
)}</script>`;

return (template: string) => template.replace(searchValue, replcaeCb);
}

0 comments on commit 100edf5

Please sign in to comment.