-
Notifications
You must be signed in to change notification settings - Fork 67
Use splats in SSG redirects instead of adding a redirect for every exact prerendered path #123
Comments
can you elaborate why we currently do this? I'm trying to understand the problem to see if we can come up with a better solution. |
Hi @calavera, nice to meet you! 😊 We create two redirects for every SSG page to support Next.js preview mode. The redirects look like this:
In other words, if the special preview-mode cookies are present, we ignore the local, statically-generated-and-prerendered file and instead hit the Netlify function. We need two redirects: One for the actual route (/my-static-page) and one for the "data route". For a large site, this could lead to several thousand rewrites in the We thought we could tackle this with splats. For example, if a Next.js page with dynamic routing But because the redirects for preview mode are force-redirects (so that we ignore the pre-rendered HTML and JSON files), the splat rewrite/redirect would cause any pages or assets that match For example, a separate Next.js We don't really know how to best address this. One idea we have been daydreaming about would be to have two By default, Netlify would use the When a user is in preview mode and makes a HTTP request, Netlify would detect the presence of those cookies (__prerender_bypass and/or __next_preview_data) and then use the much bigger This "daydream" would require Netlify to implement such custom logic specifically for Next.js... 😊 We would be thrilled to hear any ideas and suggestions! |
@FinnWoelm thank you for the thorough breakdown!!! i happened to respond to david (@calavera) in our slack but what you said is still super helpful context, some of which i didn't include. let me break down what david brainstormed on slack:
he said "I don't think that's much better [than what we currently have] but it might be quicker and less visible to our users" other thoughts quoted from david:
|
Hi @calavera, @lindsaylevine told me briefly about your chat. Thanks so much for looking into this and helping us figure out a solution! 😊 I'm not sure if I'm correctly understanding your proposal/brainstorm. I can't quite imagine how it could work. The issue is that preview mode requires forced rewrites for all of these paths, because there are pre-rendered HTML files that are shadowed by default. Any splat redirect/rewrite will break (force rewrite) requests for static html files and static assets that match the rewrite mask, but that are not actually supposed to be served by that particular Netlify Function. It is valid to have static files/assets, such as It's a tricky issue. Perhaps I'm misunderstanding your proposal/brainstorm! @lindsaylevine suggested that we could have a chat about it some time (next year)! 😊 |
closing because it seems this isn't really a real issue at the moment outside of moop-moop bringing it up, and we can re-address when edge handlers are out. |
right now there are more redirects than necessary being added to _redirects for dynamic SSG'd pages (for ex, a user like moop-moop may have thousands of paths prerendered via getStaticPaths and each of these is getting its own redirect). we should use a splat instead.
#26 (comment)
cc @moop-moop
The text was updated successfully, but these errors were encountered: