Open mkilpatrick opened 9 months ago
Hey, could this be actually the legitimate html escape done by renderToString
? I cannot say for sure since there isn't a reproduction, but my quick repro (without Vite) shows something like following, so your issue might not be related to Vite? Please let me know if I mis-understood your issue and I would appreciate if you can provide a reproduction to help investigation further.
https://stackblitz.com/edit/github-nr2ezh?file=repro.js
/*
node ./repro.js
{
result: '<div style="background-image:url('/anything')"></div>'
}
*/
async function main() {
const React = await import('react');
const ReactDOMServer = await import('react-dom/server');
const el = React.createElement('div', {
style: { backgroundImage: `url('/anything')` },
});
const result = ReactDOMServer.renderToString(el);
console.log({ result });
}
main();
Btw, there is react ssr template here https://github.com/bluwy/create-vite-extra/tree/master/template-ssr-react-ts so it might help when you want to investigate issues based on bare bone setup without frameworks.
Hello @mkilpatrick. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction
will be closed if they have no activity within 3 days.
It happens when calling transformIndexHtml on html where the app-html has already been replaced. The result is a little different from my original issue description. You can see that the server html is missing the background-image property completely. Diff here.
Thanks for clarifying the issue with reproduction. According to https://github.com/vitejs/vite/pull/15345#issuecomment-1855550194, currently it's not intended to apply transformIndexHtml
after the whole server render. It seems some different issue can manifest depending on configuration https://github.com/vitejs/vite/issues/15214.
For now, I added "pending triage" label back since this specific style url issue might have a different cause.
I tried to simplify the issue to transformIndexHtml
only, but this seems to work fine:
https://stackblitz.com/edit/vitejs-vite-hggc63?file=repro.mjs
import { createServer } from 'vite';
const server = await createServer();
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
</head>
<body>
<div style="background-image:url(/vite.svg)"></div>
</body>
</html>
`;
const html2 = await server.transformIndexHtml('/', html);
Describe the bug
When calling ssrLoadModule the resulting HTML, when passed to ReactDOMServer.renderToString, results in
'
(single quote) being html-escaped to'
. It results in the error:Warning: Prop
style
did not match. Server: "" Client: "background-image:url('/src/assets/images/tacos-1.avif')"Actual code
Server-rendered HTML
Reproduction
N/A
Steps to reproduce
No response
System Info
Used Package Manager
npm
Logs
No response
Validations