Skip to content

Commit

Permalink
version: 2.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
dazjean committed Apr 28, 2024
1 parent 983aee9 commit 46c9466
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"name": "@umajs/plugin-react-ssr",
"version": "2.0.8",
"version": "2.0.9",
"keywords": [
"umajs",
"umajs-plugin",
"umajs-plugin-react",
"umajs-plugin-react-ssr"],
"description": "In umajs, React is used to develop the plug-in of SPA and MPA, which supports server-side rendering and client-side rendering",
"author": "zunyi_zjj@163.com",
"license": "MIT",
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ const renderDom = async (ctx:IContext, viewName:string, initProps?:any, options?
}

// 在SSR模式中, 将__SSR_DATA_匹配出来, 避免其中内容被模板引擎执行, 避免注入类攻击
const ssrReg = new RegExp(/<script[^>]*>window.__SSR_DATA__=([\s\S]*?)<\/script>/)
const placeholderStr = '<!--plAcehoLder-->'
const ssrScriptStr = html.match?.(ssrReg)?.[0] || ''
const renderHtml = html.replace(ssrReg, placeholderStr) // without ssr script
const ssrReg = new RegExp(/<script[^>]*>window.__SSR_DATA__=([\s\S]*?)<\/script>/);
const placeholderStr = '<!--plAcehoLder-->';
const ssrScriptStr = html.match?.(ssrReg)?.[0] || '';
const renderHtml = html.replace(ssrReg, placeholderStr); // without ssr script

// engine rendering
html = await engine.render(renderHtml, state);
// final result
html = html.replace(placeholderStr, ssrScriptStr)
html = html.replace(placeholderStr, ssrScriptStr);
}

return html;
Expand Down

0 comments on commit 46c9466

Please sign in to comment.