diff options
author | Vitaly Takmazov | 2023-08-12 00:44:00 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-08-23 15:43:38 +0300 |
commit | bbbb6d762b03c7d42327a71380b531017cbf5ee0 (patch) | |
tree | 4b2c4029fc107de2b7f9233552b1ebb8205f9b38 /vnext/server/middleware/renderer.js | |
parent | 90991337d07434e6e5638c178bb62f49725df1f1 (diff) |
Fix SSR props decoding
Binary solution includes some trailing zero bytes and I have no time to debug
Diffstat (limited to 'vnext/server/middleware/renderer.js')
-rw-r--r-- | vnext/server/middleware/renderer.js | 12 |
1 files changed, 1 insertions, 11 deletions
diff --git a/vnext/server/middleware/renderer.js b/vnext/server/middleware/renderer.js index e7e0324e..ae2600a7 100644 --- a/vnext/server/middleware/renderer.js +++ b/vnext/server/middleware/renderer.js @@ -12,16 +12,6 @@ import { VisitorProvider } from '../../src/ui/VisitorContext' import path from 'path' import fs from 'fs' -// convert a Unicode string to a string in which -// each 16-bit unit occupies only one byte -function toBinary(string) { - const codeUnits = new Uint16Array(string.length) - for (let i = 0; i < codeUnits.length; i++) { - codeUnits[i] = string.charCodeAt(i) - } - return Buffer.from(String.fromCharCode(...new Uint8Array(codeUnits.buffer))).toString('base64') -} - const STATIC_ROOT = config.get('service.static_root') || path.resolve(__dirname, 'public') const serverRenderer = async (req, res) => { @@ -47,7 +37,7 @@ const serverRenderer = async (req, res) => { const marker = '<div id="app">' const data = htmlData.split(marker) - const propsData = `<script>window.__PROPS__="${toBinary(JSON.stringify(props))}";</script>${marker}` + const propsData = `<script>window.__PROPS__="${btoa(unescape(encodeURIComponent(JSON.stringify(props))))}";</script>${marker}` let didError = false const { pipe } = ReactDOMServer.renderToPipeableStream( <VisitorProvider> |