-
Notifications
You must be signed in to change notification settings - Fork 702
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
🐛 BUG: Removal of .html Extension Leads to Issue with Angular Service Worker Registration and Client-Side Navigation #5262
Comments
There is no plan to address this in Pages, but we are working to add asset hosting to Workers in general and we will ensure that this is fixed one way or another there. |
@petebacondarwin is there any update on this? |
Hey @naveedahmed1 - thanks for being patient with us. Last week we announced new support for Static Asset hosting for normal Workers, avoiding the need to use Pages when hosting assets. Moreover this support provides the ability to configure how we handle rewriting/redirecting of "index" Pages, and HTML requests with extensions. Take a look at https://developers.cloudflare.com/workers/static-assets/routing/. I believe this should provide you with a way forward.
|
Thanks @petebacondarwin I just tried it and deployed the sample app. But it seems that the request to index.html are till being redirect to the root directory. Incoming Request: /index.html Incoming Request: /index.csr.html Apparently the only thing changed is the status code, with previous version it was The requirement is to return the actual static html file if it exists without removing extension and without any redirect e.g. Incoming Request: /index.html Can you please confirm it from your side? |
Did you configure the html_handling option in your binding? You're looking for the This will serve the asset the incoming path without removing the extension or any redirects. |
Thanks @tanushree-sharma this seems to be working fine. One quick question, in order to update an existing Angular Project generated using the olrder version of the
And now when we deploy the project it will automatically convert existing Pages project to this new Static Asset Worker project, correct? |
It will not convert the Pages project to a Workers one. It will deploy a new Workers project, with the same name. The old Pages project will still be there and there is no link between the old and new. There is currently no "migration" tool in terms of the backend. |
I see, and the steps I mentioned above are the only changes I need to make, correct? |
I believe the steps to convert a standard Angular SSR app to run on Workers + Assets you need are:
|
Thanks @petebacondarwin! Please also add a section that guides on migration of existing Angular Pages project with SSR to Workers. |
already on it :) cloudflare/cloudflare-docs#17251 |
Awesome! Thanks @irvinebroque |
Angular Worker template seems broken. Try switching the
|
@naveedahmed1 - I had a quick play and I found that I needed to set the html handling in wrangler.toml. For example: assets = { directory = "./dist/browser", binding = "ASSETS", html_handling = "none" } Otherwise the request for |
And if you have // Get the root `index.html` content.
const indexUrl = new URL('/index.csr.html', url);
const indexResponse = await env.ASSETS.fetch(new Request(indexUrl));
const document = await indexResponse.text(); |
I'll update the C3 template and the docs... |
Thanks @petebacondarwin I tried the changes your suggested on the test project generated through the c3 and its seems to be working fine. Updating C3 template and the docs would be awesome. Would it be possible to update C3 to throw more dev friendly errors? that allow us to figure out such issues on our own. |
Can you please also guide how |
One more thing which I noticed is that, Cache Rules no longer work with this new approach probably due to this:
https://developers.cloudflare.com/workers/reference/how-the-cache-works/ I'm afraid this would be a dealbreaker for us to use new Worker Asset Hosting model :( Any chance developers could be given an option to select if they want the worker to execute after cache at least when using Worker Asset Hosting? |
We don't have a
Tell us more about what you're building, why this is a blocker. |
We need to diisable the SSR for routes like the account urls. It doesnt make sense to server render such routes since these routes require user to login and are private to the user. We want to be able to cache the server rendered response. Its an expenive task since it requires to pull the data from the backend api and then generate the page. Many of these pages dont change often so its better to have the response cached, slow respone impact both user expereince as well as the SEO. |
@petebacondarwin it seems that the angular template is still broken when uisng
|
@petebacondarwin just wanted to point out that the index file should point to So, when you update the template please ensure that index file is pointing to the
|
In fact it seems that when deployed, the
|
Which Cloudflare product(s) does this pertain to?
Pages
What version(s) of the tool(s) are you using?
wrangler: 0.0.0-0c535e72
What version of Node are you using?
v20.11.1
What operating system and version are you using?
Windows 11
Describe the Bug
Observed behavior
Currently, the platform automatically maps index.html to /, disrupting the expected behavior of Angular's service worker and client-side navigation for subsequent requests.
Current Behavior
The automatic mapping of index.html to / leads to issues with Angular's service worker and client-side navigation. When the Angular service worker initializes and attempts to fetch index.html, it receives a server-side rendered (SSR) response of /. This SSR response does not match the hash value expected by the service worker, causing a hash mismatch error and preventing the service worker from being registered. Attempts to mitigate this issue by renaming the index.html file in the Angular service worker configuration or by adding .html twice to the file name only partially resolve the problem, as page refreshes still result in requests to the server instead of to index.html on the client.
Expected behavior
Requests for index.html should return the contents of the index.html file without any redirection.
Steps to reproduce
To observe this behavior, visit https://www.mustakbil.com/. Upon the first request, you will receive a server-rendered response that registers the service worker. However, on subsequent page reloads, the request continues to go to the server instead of to index.html on the client.
Additional Information
Several users have reported similar issues, including discussions within the Cloudflare community:
Cloudflare Pages Truncates URLs by Removing the HTML Extension
Prevent Truncating and Removal of Page Name Extensions
and more:
https://community.cloudflare.com/search?q=%22.html%22%20%23developers%3Acloudflare-pages
The issue has been discussed with Adam Murray, @petebacondarwin, and @alan-agius4 from the Angular team. Alan Agius suggests that this seems to be more of a problem with Cloudflare and recommends filing an issue with them. He also emphasizes the importance of the file extension, as its absence can lead to invalid paths and build failures.
Here's what @alan-agius4 from Angular team says on the issue:
Please provide a link to a minimal reproduction
No response
Please provide any relevant error logs
No response
The text was updated successfully, but these errors were encountered: