aboutsummaryrefslogtreecommitdiff
path: root/vnext
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-08-12 00:44:00 +0300
committerGravatar Vitaly Takmazov2023-08-23 15:43:38 +0300
commitbbbb6d762b03c7d42327a71380b531017cbf5ee0 (patch)
tree4b2c4029fc107de2b7f9233552b1ebb8205f9b38 /vnext
parent90991337d07434e6e5638c178bb62f49725df1f1 (diff)
Fix SSR props decoding
Binary solution includes some trailing zero bytes and I have no time to debug
Diffstat (limited to 'vnext')
-rw-r--r--vnext/server/middleware/renderer.js12
-rw-r--r--vnext/src/index.js12
2 files changed, 2 insertions, 22 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>
diff --git a/vnext/src/index.js b/vnext/src/index.js
index 5ab543c4..0c936257 100644
--- a/vnext/src/index.js
+++ b/vnext/src/index.js
@@ -16,17 +16,7 @@ import { CookiesProvider } from 'react-cookie'
import { VisitorProvider } from './ui/VisitorContext'
const Juick = lazy(() => import('./App'))
-
-function fromBinary(encoded) {
- const binary = window.atob(encoded)
- const bytes = new Uint8Array(binary.length)
- for (let i = 0; i < bytes.length; i++) {
- bytes[i] = binary.charCodeAt(i)
- }
- return String.fromCharCode(...new Uint16Array(bytes.buffer))
-}
-
-const props = window.__PROPS__ ? JSON.parse(fromBinary(window.__PROPS__)) : {}
+const props = window.__PROPS__ ? JSON.parse(decodeURIComponent(escape(atob(window.__PROPS__)))) : {}
const JuickApp = () => (
<StrictMode>