-
-
Notifications
You must be signed in to change notification settings - Fork 463
Catch-all at /pages root breaks static file serving #646
Comments
Thanks, I will take a look at this this week. I think this component should support it according to features list but I believe catch-all and |
Hey @dphang I found something worse: Adding a dynamic SSG route at
So, to summarize my understanding of the issue:
This is fatal for my current project as I had promised complete control over URLs, based on Next's support for this use case (seems like an important break in compatibility, no?). Any idea how soon this can be addressed? |
Sure, sorry I got busy this weekend but I will take a look some time this week. I don't use catch-all (and didn't write the feature) and unfortunately we don't have e2e test coverage for catch-all yet, but I'd like to add some test coverage as well so this doesn't break in the future. |
No worries, thanks for the work. It seems the issue is Another question: As a workaround, I attempted to achieve my "clean URLs" goal using the new
This works when I build; however, on deployed site, when I visit Can you confirm this approach should work? Are there any "gotchas" to know about when getting this working? (ex: I have not added custom domain config to serveless.yml). I'm going off of this issue. |
Could you please check CloudWatch and post the logs? It may be a bug in the rewrite code - it's in alpha now and I have tests for it, but it seems it could still have issues. |
Published a fix in: https://www.npmjs.com/package/@sls-next/serverless-component/v/1.18.0-alpha.6, please try out and see if it works. |
Hey @dphang thanks for the update. Unfortunately, I'm getting 404 when I access Some other info, in case it's helpful:
To clarify: I have not tested under the original issue case of catch all at Thanks again! |
Ah, I fixed the public file serving conflicting with the getStaticPaths with dynamic pages at root level. For the rewrites issue, I see you are using Next.js 9.4.4 and @sls-next/serverless-component 1.17.0
Rewrites are supported only in Next.js 9.5 as per https://nextjs.org/docs/api-reference/next.config.js/rewrites, and you also need to upgrade @sls-next/serverless-component to the 1.18 alphas, where rewrites are implemented. Could you please upgrade to the latest 1.18.0-alpha.7 and see if that works for you. It will have rewrites implementation and also the fix I mentioned for getStaticPaths. |
Ah, I had upgraded to Next.js I just tried with I can also comment in the rewrites RFC or open a new issue. |
No worries... please open a separate issue so it can be better tracked. Also please ensure you are pinning the latest alpha version correctly in If this is not the case, please open the issue and include your I think this issue by itself should be resolved. Thanks! |
Also with this rewrite config you mentioned: return [{
source: '/:path*',
destination: '/:path*',
},{
source: '/:path*',
destination: '/content-pages/:path*',
}]; Just wondering if 1st rewrite is correct? Because the way it's implemented in this component, it will only match the 1st one and then the 2nd one is ignored. Let me test on Next dev server to see the behavior. EDIT: on Next dev server it's also the same behavior, the 2nd rewrite is never matched since the 1st one matches it. |
Actually, also need to handle the SSR page breaking, it looks like it also interferes with the dynamic page. I'll make a fix today. |
Thanks for checking, I have indeed been updating via serverless config.
That rewrite is from the next docs. The first one is there so SSG routes are checked first before the rewrite is done.
Unsure what you're seeing on devserver, but I'm able to access pages using the second rewrite. Removing it causes 404s on pages that were working. Removing the first also has some additional effects when using serverless-nextjs:
( |
I see, I added rewrites to the e2e-test next app here:
When I added the first rewrite, the Anyway, so I thought that first no-op rewrite is only needed when you are proxying to another domain, which I hadn't implemented yet. But the way it's implemented now, it doesn't know about this special no-op rewrite; the first rewrite will get matched. I think there are a few things to fix:
BTW, do you have a minimal repro you can create and share? It will make it easier to debug and fix the specific scenario(s) you have in mind. Since in this case it looks like multiple things (catch-all, public files, SSR/SSG pages, rewrites) are interacting with each other, it may be hard for me to repro just via descriptions. Thanks! |
@patricktyndall I don't use this and didn't implement it so I'm not completely sure how it works, but I thought there is a Thanks for providing the logs, I think that means the S3 key requested from origin request handler does not exist in the bucket itself. Hopefully the logs have more details on what the key value is or we can add more logging to provide a more helpful message - or I can just debug once I get a minimal repro. I don't actually use the catch-all in my real apps so I probably have limited experience with all its nuances - so a minimal repro will help a lot! Thanks. |
Have fixed the SSR/SSG pages conflict in: #685 |
On the rewrites issue, I'll get a repo together this weekend. Revisiting the original issue and looking your recent releases, I think it's broken when multiple catch-alls are involved. I have the following setup:
Now I get 404s when I try to visit |
Hey just wanted to tag onto this issue. Also facing the dynamic SSG page conflicts with SSR pages. I've put up a demo with v1.17.0 https://d2jucf2wqkn40w.cloudfront.net. I'll check to see if v1.18.0-alpha.14 helps. Repo: https://github.com/himynameistimli/nextjs-serverless-503-cloudfront |
@himynameistimli yes please try the latest alphas, there are fixes with conflicts with existing nonDynamic routes that were fixed |
hey @dphang yes, just updated the test repo and demo to @sls-next/[email protected]. I can confirm that the SSR static page works, but the dynamic SSR pages still do not work after refreshing the page. Returns a 404. |
Thanks, let me take a look at the repro later this week. |
@himynameistimli from repro you shared it seems the dynamic SSR page it is now working? 404s are cached by CloudFront/browser for some time I think, perhaps it is working from me since I'm hitting a different edge node (from Seattle). |
Hey @dphang my bad, was testing out a fix I made to lambda-at-edge, which I deployed to the demo. It fixes it for my specific use case, but that's because I don't make use of fallbacks for SSG pages. I copied the repro manifests into a fiddle to see what was happening. https://jsfiddle.net/sbpxqeft/. So I essentially told it to ignore the fallback if there is a dynamic SSR route that also matches. I don't know if this is generally right, but I think that there should be some check between the manifest and the prerenderManifest to make sure that they are talking about the same route. I will restore the demo back to the latest beta. Sorry for the confusion. |
Yea, I think it sounds like right direction but now that I think about it, I think we are mixing the fallback logic with the general routing logic... Using From Next.js priority is as follows: Predefined routes > Dynamic routes > Catch-all routes. I think all of this data is in the build manifest. So we may need to rework the logic a bit: if it's matching one of them try to figure out page to render: either it's prerendered (e.g SSG from getStaticPaths), needs SSR (renders JS file) or has fallback |
Why is this closed? When I add a catch-all at |
@patricktyndall it was closed automatically by the merging of the linked PR, which I assumed fixed all the latest issues. Could you please add more details for the latest bug? Is it still the same catch-all page with getStaticPaths and fallback = true? I thought I had added and verified tests for this, but let me check the behavior again. |
@dphang here's reproduction: https://github.com/patricktyndall/sls-next-bug-reproduction/tree/catchall-bug (note the branch)
(note also there are no rewrites involved here) |
Possibly related to: #967 |
I think some of the latest changes may have fixed this as the routing precedence was fixed by @jvarho. Can you try in latest one and see if it works? Then I will close it if it is fixed. I will close, feel free to comment or open a new issue in case it is still a problem |
Hi, I'm still having this issue. It seems my favicon, which is served from the public folder, loads incorrectly (it loads a URL relative to my catch-all route). The favicon is being loaded in the head of my custom |
Describe the bug
Next supports having a catch-all route at
pages/[...all]
(this works withnext start
). However, when I add this file (withgetStaticPaths fallback: true
) and deploy using serverless-next.js, requests for static assets break.Actual behavior
Assets don't load
pages/[...all]
(next's fallback rendering). This results in a 200 with type text/html. I can paste these asset URLs in my browser and get the fallback page.This applies to all kinds of assets (next's
/_next
files as well as things inpublic/
).Expected behavior
Static files are served correctly.
Steps to reproduce
Add a catch-all route at
pages/[...all]
withgetStaticPaths
. (I haven't tested this with SSR)Versions
Other info
When I add
fallback: false
the requests become 503s, but otherwise the issue is the same.Does serverless-next.js support this? I couldn't find mention in the documentation, sorry if I missed something. It makes sense that this would be tricky, but wondering if there's a known workaround.
If this is unsupported, is there a roadmap or further discussion on this? This is very high-value to my team, as it would unlock the ability to define any URL path using CMS.
ETA:
pages/[all]
) and it still breaks forpublic/test.png
, but no longer breaks forpublic/assets/test.png
or for/_next
assets. This seems to confirm the rule that assets URLs can't match/pages
patterns.My solution for now is to both a) use
[all]
for content pages (ie limit created pages to one path segment), and b) require everything inpublic
to be inpublic/assets
so they don't match[all]
The text was updated successfully, but these errors were encountered: