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

react-helmet mixing fields during renderStatic #667

Open
Montana opened this issue Jan 25, 2022 · 1 comment
Open

react-helmet mixing fields during renderStatic #667

Montana opened this issue Jan 25, 2022 · 1 comment

Comments

@Montana
Copy link

Montana commented Jan 25, 2022

Hey folks,

I'm running server-side render of the React application. I'm using express for this purposes. The whole server-side render code looks like this:

import * as React from "react"
import * as ReactDOMServer from "react-dom/server"
import * as express from "express"
import { StaticRouter } from "react-router-dom"
import walker = require("react-tree-walker")
import { useStaticRendering } from "mobx-react"

import Helmet from "react-helmet"
import Provider from "../src/Provider"
import { StaticRouterContext } from "react-router"
import version = require("../version")

var _template: string = require(`../dist/${version.v()}/index.html`)

interface IRenderResponse {
    statusCode: number,
    template: string,
    redirect?: string
}

I feel like this happens because of react-helmet uses static fields, I suppose. So, if two requests are being handled in parallel, this fields are being changed chaotically. I looked into the thread-safe issue via: https://github.com/openameba/react-safety-helmet. Still no luck.

Cheers,
Montana Mendy

@edkimmel
Copy link

edkimmel commented May 4, 2022

You should look into rendering in isolated contexts, either with Node's built in VM or a library like VM2 (https://github.com/patriksimek/vm2)

That will let you render multiple requests concurrently without any issues like the above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants