-
Notifications
You must be signed in to change notification settings - Fork 563
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(prerender): ignore files already in public assets #3093
base: v2
Are you sure you want to change the base?
Conversation
This makes sense as general fix (since in general we always check static assets before hitting routes, prerender should not at least override files). But with current approach, i'm afraid it will at least add overhead (of two times scanning nested public dir) and also implicit behavior change of stopping crawler if there is an overlapping static asset file. Maybe we can add a guard to canWriteToDisk to skip if file entry exists already? Also perhaps Nuxt can explicitly ignore important files such as |
We do ignore the Nuxt manifest: The linked issue is for a user We could also add all public assets to ignore list but seemed better to fix in Nitro. Perhaps we could cache scanned public asset files on the nitro instance so we don't scan it twice? |
Even if we say it is needless operation, it is behavior change. we do SSR during prerendering to both write staric pages but also crawl them all (even urls we donβt finally write like the ones with query params and this hidden case for crawling) when subfolderIndex is on, we can check for existence of parrent without index.HTML? Im more lean towards dynamic write ignore since gives more flexibility (for example if we support emitting static assets from prerender routes) |
no worries, i can implement this in nuxt directly if you donβt think itβs worth a broader nitro change i regard the crawling of the path as a bug even if we donβt write it to disk, so personally i wouldnβt worry about the fact that it is a behaviour change let me know what you prefer nitro behaviour to be and iβll update the pr π |
not suggesting to diverge behavior (and main blast of behavior change is for nuxt users anyway) Maybe this:
Also thinking we could indeed cache result of static writes (it happens before prerender, we just can keep it in nitro internal) |
β¦t`) + cache public asset scan
As it happens, This also means FS protection step won't work (as it's order-dependent). |
@@ -120,6 +128,11 @@ export async function prerender(nitro: Nitro) { | |||
} | |||
} | |||
|
|||
// do not prerender any files in the public assets | |||
if (publicAssets.has(route)) { |
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.
One thing we can optimize (for almost free -- no cache && no glob), are nitro.options.publicAssets
with dir (no fallthrugh) such as client assets and build manifest dir.
We can also do it by default since this dirs (prefixes) were already explicitly configured as static (not mixed prefixes)
Another benefit is that regardless of prerender/copy order it works same.
if (nitro.options.noPublicDir) { | ||
return; | ||
} | ||
|
||
if (nitro._cachedPublicAssets) { | ||
return nitro._cachedPublicAssets; |
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.
I think this cache will be unreliable if nuxt emits assets after prerendering.
We can keep copyPublicAssets
intact and introduce a util that scans only unprefixed public assets (usable for opt-in feature of prerenderer for nxut)
// Check if file already exists, for example copied across from public assets | ||
const fileAlreadyExists = | ||
existsSync(join(nitro.options.output.publicDir, route.fileName!)) || | ||
existsSync(join(nitro.options.output.publicDir, route.route)); |
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 optimize to reduce one stat if we check fileName
ending with /index.html
, then skip on parent existence (manifest.json/index.html
)
π Linked issue
β Type of change
π Description
Currently there's no checking to see if a file already exists in public assets, and this has to be added manually to the ignore list. I think it's generally safe to ignore public assets paths as otherwise we have multiple possible files resolving to the same path.
Context: nuxt/nuxt#25378
π Checklist