Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add usage of DynamiHTML in remix #1114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion apps/cyberstorm-remix/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { LinkingProvider } from "@thunderstore/cyberstorm";
import { DapperTs } from "@thunderstore/dapper-ts";
import { CurrentUser } from "@thunderstore/dapper/types";
import { getDapper } from "cyberstorm/dapper/sessionUtils";
import { replaceDjangoUnicode } from "cyberstorm/utils/utils";

import { captureRemixErrorBoundaryError, withSentry } from "@sentry/remix";

Expand Down Expand Up @@ -62,6 +63,12 @@ export async function loader() {
},
},
currentUser: await dapper.getCurrentUser(),
// dynamicHeaders: await dapper.getDynamicHTML("cyberstorm_content_left"),
dynamicBodyBeginning: await dapper.getDynamicHTML(
"cyberstorm_body_beginning"
),
// dynamicLeftColumn: await dapper.getDynamicHTML("cyberstorm_header"),
// dynamicRightColumn: await dapper.getDynamicHTML("cyberstorm_content_right"),
};
}

Expand All @@ -77,6 +84,12 @@ export async function clientLoader() {
},
},
currentUser: await dapper.getCurrentUser(),
// dynamicHeader: await dapper.getDynamicHTML("cyberstorm_content_left"),
dynamicBodyBeginning: await dapper.getDynamicHTML(
"cyberstorm_body_beginning"
),
// dynamicLeftColumn: await dapper.getDynamicHTML("cyberstorm_header"),
// dynamicRightColumn: await dapper.getDynamicHTML("cyberstorm_content_right"),
};
}

Expand All @@ -95,7 +108,16 @@ function Root() {
};
sessionId: string | null;
currentUser: CurrentUser;
// dynamicHeader: string[];
dynamicBodyBeginning: string[];
// dynamicLeftColumn: string[];
// dynamicRightColumn: string[];
} = JSON.parse(JSON.stringify(loaderOutput));
console.log(
parsedLoaderOutput.dynamicBodyBeginning.map((dhtml) =>
replaceDjangoUnicode(dhtml)
)
);

return (
<html lang="en">
Expand All @@ -104,6 +126,7 @@ function Root() {
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
{/* {parsedLoaderOutput.dynamicHeader} */}
</head>
<body>
<ScrollRestoration />
Expand All @@ -116,7 +139,14 @@ function Root() {
/>
<Scripts />
{/* REMIX TODO: This Ads script seem to break hydration for styles in the head. */}
{/* <script async src={`https://s.nitropay.com/ads-785.js`} /> */}
<div
dangerouslySetInnerHTML={{
__html: parsedLoaderOutput.dynamicBodyBeginning.map((dhtml) =>
replaceDjangoUnicode(dhtml)
),
}}
/>

<LinkingProvider value={LinkLibrary}>
<TooltipProvider>
<div className={styles.root}>
Expand Down
28 changes: 28 additions & 0 deletions apps/cyberstorm-remix/cyberstorm/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// '\\' '\\u005C'
// '\'' '\\u0027'
// '"' '\\u0022'
// '>' '\\u003E'
// '<' '\\u003C'
// '&' '\\u0026'
// '=' '\\u003D'
// '-' '\\u002D'
// ';' '\\u003B'
// '`' '\\u0060'
// '\u2028' '\\u2028'
// '\u2029' '\\u2029'

export function replaceDjangoUnicode(unicodeString: string) {
return unicodeString
.replaceAll(/\\u005C/g, "\\\\")
.replaceAll(/\\u0027/g, `\\`)
Comment on lines +15 to +17

Check failure

Code scanning / CodeQL

Double escaping or unescaping High

This replacement may produce '' characters that are double-unescaped
here
.
.replaceAll(/\\u0022/g, `"`)
.replaceAll(/\\u003E/g, ">")
.replaceAll(/\\u003C/g, "<")
.replaceAll(/\\u0026/g, "&")
.replaceAll(/\\u003D/g, "=")
.replaceAll(/\\u002D/g, "-")
.replaceAll(/\\u003B/g, ";")
.replaceAll(/\\u0060/g, "`")
.replaceAll(/\\u2028/g, ")")
.replaceAll(/\\u2029/g, "(");
}
Loading