-
Notifications
You must be signed in to change notification settings - Fork 12k
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
ng serve does not allow us access to raw 'index.csr.html' when using SSR #28063
Comments
Workaround:ExplanationDuring ImplementationIn your app.component.ts: protected readonly blankPage$ = signal(false);
private serveBlankPage() {
this.route.queryParamMap
.pipe(takeUntilDestroyed(this.dRef))
.subscribe(params => {
if (params.has('__blank_page')) {
console.debug(params);
this.blankPage$.set(true);
}
});
}
ngOnInit() {
this.serveBlankPage();
} In your app.component.html: <header></header>
@if (!blankPage$()) {
<router-outlet></router-outlet>
}
<footer></footer> Finally, for precaching, use the url: DrawbacksYou can only wrap the router outlet in the While you can choose to make the |
Ensure direct requests to HTML files result in them being served. Closes angular#28063
Can you please elaborate on what you mean by "precaching" and what you are trying to achieve with it? |
Ensure direct requests to HTML files result in them being served. Closes angular#28063
@alan-agius4 Sorry for the delay in getting back. So, I use a service worker, and instead of @angular/pwa, I use workbox to implement a custom service worker. And workbox has the ability to "pre-cache" certain files to ensure that the application always loads, even if offline. To do this, it loads certain files up-front at the time of installation. Usually, this would mean all files in the 'initial' chunk + the index.html file + global styles + polyfills. So for those items, I would need the file names in the build output, then make a list, and pass that to the service worker. The service worker would then, at install-time, eagerly cache all the files in the list by making a network request. In the case of index.html/index.csr.html, it was returning a 404, and the service worker installation would error out. If used https://developer.chrome.com/docs/workbox/modules/workbox-precaching |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Command
serve
Is this a regression?
The previous version in which this bug was not present was
No response
Description
If I go to
http://localhost:4200/
, I get a transformed html response which includes my lazy-loaded router-component for the''
path. This is as expected during SSR.However,
If I go to
http://localhost:4200/index.html
, I expect to get an html response which is exactly the index.html on disk, without the ssr transformation. But the dev server sends me a "404 Not Found" instead.Turns out that, for SSR, angular creates 2 index.html -
index.csr.html
andindex.server.html
. I am interested in the csr version, because I want to precache it.However, the angular dev server's middleware prevents me from accessing that file.
This is a screenshot of me debugging the dev-server. The request was for
/index.html
In line 25, the middleware tries to search the outputFiles for 'index.html'. The problem is that the outputFile don't have 'index.html'. They have 'index.csr.html' and 'index.server.html'. As a result,
rawHtml
is going to be always beundefined
, and the middleware is going to go to line 27 and skip the middleware.If I try to go for
/index.csr.html
, then the middleware will skip out before it even reaches Line 25, due to theif
condition on Line 12Line 12 says that any request that are not '/' or '/index.html' will be ignored.
So we are perpetually denied being served the raw
index.html
while serving in SSRMinimal Reproduction
Create a new angular app
Add SSR to it as per the documentation
Add a lazy loaded component for the path
''
with the selectortest-element
and an empty template,Remove the contents of app.component's template and add a router outlet to app.component.html
Do other task necessary to set up routing
Serve the app with ng serve
Go to
http://localhost:4200
and check the response that came on first load. You should see the element<test-element></test-element>
in the html. This is okGo to
http://localhost:4200/index.html
. This should result in 404 Not Found. This is ok.Go to
http://localhost:4200/index.csr.html
. This should result in 404 Not Found. This is not ok. It should have returned html without the test-element in it.Exception or Error
No response
Your Environment
Anything else relevant?
angular-cli/packages/angular/build/src/tools/vite/middlewares/index-html-middleware.ts
Lines 30 to 42 in f5c250a
This is the part that likely needs to be changed.
index.csr.html
index.csr.html
orindex.html
as per the actual requestThe text was updated successfully, but these errors were encountered: