Skip to content
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

Feature: Introduce "render" function for Angular v16 projects #327

Closed
2 tasks
brandonroberts opened this issue Apr 11, 2023 · 7 comments
Closed
2 tasks
Assignees
Labels
enhancement New feature or request

Comments

@brandonroberts
Copy link
Member

Which scope/s are relevant/related to the feature request?

create-analog

Information

To server render an Angular v16 application, the following setup is needed.

import 'zone.js/node';
import { enableProdMode } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import {
  provideServerRendering,
  renderApplication,
  ɵSERVER_CONTEXT as SERVER_CONTEXT,
} from '@angular/platform-server';

import { AppComponent } from './app/app.component';
import { mainProviders } from './main.providers';

if (import.meta.env.PROD) {
  enableProdMode();
}

export function bootstrap() {
  return bootstrapApplication(AppComponent, {
    providers: [
      mainProviders,
      provideServerRendering(),
      { provide: SERVER_CONTEXT, useValue: 'analog' },
    ],
  });
}

export default async function render(url: string, document: string) {
  const html = await renderApplication(bootstrap, {
    document,
    url,
  });

  return html;
}

The render function would accept the root component and application config and return a function that is used for server rendering.

import 'zone.js/node';
import { AppComponent } from './app/app.component';
import { config } from './app.config.server';
import { render } from '@analogjs/platform/server';

export default render(AppComponent, config);

It would include the following providers

  • provideServerRendering()
  • { provide: SERVER_CONTEXT, useValue: 'analog' }
  • Any providers added through the application config

Describe any alternatives/workarounds you're currently using

No response

I would be willing to submit a PR to fix this issue

  • Yes
  • No
@brandonroberts brandonroberts added the enhancement New feature or request label Apr 11, 2023
@brandonroberts brandonroberts changed the title Feature: Introduce "render" function Feature: Introduce "render" function for Angular v16 projects Apr 11, 2023
@R-Bower
Copy link

R-Bower commented May 5, 2023

@brandonroberts is the BrowserAnimationsModule going to be supported? I'm having trouble getting my components with animations to work. Wondering if this should be added to the bootstrap function.

@brandonroberts
Copy link
Member Author

@brandonroberts is the BrowserAnimationsModule going to be supported? I'm having trouble getting my components with animations to work. Wondering if this should be added to the bootstrap function.

If you're using standalone, you only need to add provideAnimations() in the main.ts providers as it's client only.

@R-Bower
Copy link

R-Bower commented May 5, 2023

@brandonroberts is the BrowserAnimationsModule going to be supported? I'm having trouble getting my components with animations to work. Wondering if this should be added to the bootstrap function.

If you're using standalone, you only need to add provideAnimations() in the main.ts providers as it's client only.

What about for the Astro integration?

@brandonroberts
Copy link
Member Author

@brandonroberts is the BrowserAnimationsModule going to be supported? I'm having trouble getting my components with animations to work. Wondering if this should be added to the bootstrap function.

If you're using standalone, you only need to add provideAnimations() in the main.ts providers as it's client only.

What about for the Astro integration?

There is an open issue for supporting passing providers to the render/client bootstrap, which is separate from this.

@goetzrobin goetzrobin self-assigned this May 10, 2023
@goetzrobin
Copy link
Member

@brandonroberts if you like the template used for the nx plugin (added here) I can also add the new template to create-analog.

@R-Bower
Copy link

R-Bower commented May 23, 2023

Definitely looking forward to this. I'm planning on building my component library docs in Astro, but need support for Angular Animations and root services before that can happen.

@brandonroberts
Copy link
Member Author

You can do this now

https://analogjs.org/docs/packages/astro-angular/overview#adding-component-providers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants