Skip to content

Commit

Permalink
Merge pull request #2623 from OpenNeuroOrg/utf-8-hydrate-fix
Browse files Browse the repository at this point in the history
fix(ssr): Prevent Apollo state from corrupting UTF-8 objects
  • Loading branch information
nellh authored Jun 30, 2022
2 parents bc6b359 + 9f0d9c4 commit df251c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/openneuro-app/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<body>
<div id="main">${react}</div>
<script src="/client.jsx" type="module"></script>
<script>window.__APOLLO_STATE__=atob("${apolloState}");</script>
<script>window.__APOLLO_STATE__=decodeURIComponent(atob("${apolloState}"));</script>
</body>

</html>
6 changes: 3 additions & 3 deletions packages/openneuro-app/src/server.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export async function render(url, cookies) {
const head = `${helmet.title.toString()}${helmet.meta.toString()}${helmet.style.toString()}`

// Prevent <script> tags from strings
const apolloState = Buffer.from(JSON.stringify(client.extract())).toString(
'base64',
)
const apolloState = Buffer.from(
encodeURIComponent(JSON.stringify(client.extract())),
).toString('base64')

return { react, apolloState, head, css: redesignStyles }
}

0 comments on commit df251c4

Please sign in to comment.