-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix: prevent double base in assets on dev mode when assets plugin is applied before html transformation #15345
Conversation
… before html transforms
Run & review this pull request in StackBlitz Codeflow. |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
base
andorigin
from the vite config when calling fileToDevUrl, then whentransformIndexHtml
is applied, theindexHtml
plugin appendsbase
again when resolving the asset path in processNodeUrl thebase
is appended again.Fixes #15214
Before
After
Additional context
Setup
vite config
directory structure
example snippet
library-file.tsx
app-file.tsx
The resolved asset URL in dev mode results as
/my-path/my-path/@fs/Users/myuser/example/lib/library-assets/myicon.svg
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).