fix!: only serve dev static assets from publish dir as fallback#508
fix!: only serve dev static assets from publish dir as fallback#508
Conversation
|
@copilot what does this have to do with SPAs and redirects? did you cross wires with another issue? also, can you compare this with the behaviour implemented in https://github.com/netlify/cli/? when does it use static files in the publish dir during dev? |
The SPA redirect is directly related to the issue. Here's how:
Without the SPA redirect, the issue would still exist but be less obvious - direct requests for files that exist in both dist and source would serve from dist. Regarding comparison with Netlify CLI: The CLI doesn't integrate with Vite's dev server, so it doesn't have this conflict. During Commit: 71ed852 |
When using `@netlify/vite-plugin`, `vite dev` (or e.g. `astro dev`) was incorrectly serving files from the Netlify publish dir (e.g. `dist/`) instead of the source directory during vite dev. I can't think of any reason to ever augment the directories passed to `@netlify/dev`'s options with the default directory. In every known use case (`@netlify/vite-plugin`, `@netlify/nuxt`...), we pass a known set of directories that should be used to serve static assets in dev. It seems reasonable to use some reasonable defaults here for future use cases. This commit makes this change. Co-authored-by: serhalp <1377702+serhalp@users.noreply.github.com>
71ed852 to
3a6c743
Compare
|
Note: this PR is ready as is. I just wanted to do some local testing to verify the fix (for #513 as well at the same time). I'll get to it eventually, so I'm keeping these open. |
packages/dev/src/main.ts
Outdated
There was a problem hiding this comment.
Updated the documentation to use @default JSDoc tag and more precisely describe the fallback behavior: build.publish from netlify.toml if configured, otherwise projectRoot.
Commit: 23e4a66
Updated the JSDoc comment for the staticFiles.directories option to use the @default tag and more precisely describe the fallback behavior: - Uses build.publish from netlify.toml if configured - Otherwise falls back to projectRoot This addresses the review comment to document the default more clearly. Co-authored-by: serhalp <1377702+serhalp@users.noreply.github.com>
Fixes #436
Problem
When using
@netlify/vite-plugin,vite dev(or e.g.astro dev) was incorrectly serving files from the Netlify publish dir (e.g.dist/) instead of the source directory during vite dev.This causes various problems, the most basic of which is that if you've ever previously run
vite build(or e.g. `astro build) your dev server scans the production build output dir and serves assets from it. This is confusing and incorrect.Solution
I can't think of any reason to ever augment the directories explicitly passed to
@netlify/dev's options with a default directory. In every known use case (@netlify/vite-plugin,@netlify/nuxt...), we pass the known, exhaustive set of directories that should be used to serve static assets in dev, so we should respect these as is.It seems reasonable to use some sensible defaults here when not provided (for hypothetical future or direct use cases).
This PR makes this change.
Changes
@defaultJSDoc tag💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.