fix: prevent double base in assets on dev mode when assets plugin is applied before html transformation#15345
fix: prevent double base in assets on dev mode when assets plugin is applied before html transformation#15345m1san wants to merge 1 commit intovitejs:mainfrom
Conversation
… before html transforms
|
|
| originalUrl !== '/' && | ||
| htmlPath === '/index.html') | ||
| // avoid duplicate base prefix when applying html transforms after assets plugin | ||
| !url.startsWith(config.base) && |
There was a problem hiding this comment.
We can't do this, or we won't support projects having /root-path/base/ in the fs.
/base/base/file.js is a valid module.
|
Checking the reproduction, |
@patak-dev In the reproduction, the intent is to demonstrate rendering content without having an actual index html so I can do a direct render pass and use the result to call While I could do my own custom Thanks for everything y'all do in Vite, really love using it so far. Happy new year! |
|
Let's close this PR. We can keep #15214 open to discuss. In case it is helpful, there are efforts to integrate RSC and Vite that don't seem to be running into that issue. Maybe a good idea to check them out facebook/react#26926 |
This reworks the exports of _server.tsx. According to [this](vitejs/vite#15345 (comment)) transformIndexHtml should be called on the index.html (which is provided automatically) and not the entire result of calling render (after the server code is injected). It hasn’t actually posed a problem but I’d like to get ahead of it and make sure we’re doing it the right way. It really only affects local dev but it’s breaking since what’s exported from _server.tsx has changed. _server.tsx is now expected to export 3 things: ``` export const render = async (pageContext: PageContext<any>) => { const { Page, pageProps } = pageContext; return ReactDOMServer.renderToString(<Page {...pageProps} />); }; export const replacementTag = "<!--YEXT-SERVER-->"; export const indexHtml = `<!DOCTYPE html> <html lang="<!--app-lang-->"> <head></head> <body> <div id="reactele">${replacementTag}</div> </body> </html>`; ``` Specifically, `indexHtml` is now split out from the server `render`. It also requires a `replacementTag` to know where the server html should be injected into the indexHtml. --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Description
On dev mode, for absolute asset URLs in monorepos, the assets plugin resolves the asset including the
baseandoriginfrom the vite config when calling fileToDevUrl, then whentransformIndexHtmlis applied, theindexHtmlplugin appendsbaseagain when resolving the asset path in processNodeUrl thebaseis appended again.Fixes #15214
Before


After


Additional context
Setup
vite config
directory structure
example snippet
library-file.tsxapp-file.tsxThe resolved asset URL in dev mode results as
/my-path/my-path/@fs/Users/myuser/example/lib/library-assets/myicon.svgWhat is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).