Replies: 24 comments 94 replies
-
|
I love this! I think that this is my favorite part 😊:
Good job! |
Beta Was this translation helpful? Give feedback.
-
|
About Question 1: A common use case is vanilla JS 3rd party libraries that might alter the DOM. (e.g. some code highlighters) |
Beta Was this translation helpful? Give feedback.
-
|
Ad Question 3: Aren't there alternatives to deprecating I guess the migration script will not be able migrate it to 100%? |
Beta Was this translation helpful? Give feedback.
-
|
How does it relate to renderer api? Will it get deprecated too? |
Beta Was this translation helpful? Give feedback.
-
How migrations are going to handle this? There is no way to automatically replace ElementRef with DomRef if a code logic change is required. |
Beta Was this translation helpful? Give feedback.
-
|
The cause that Angular cannot create the dom ref is not only by SSR, but also the element doesn't exist. For example, the referred element may be dismissed by if block. So my question is: Why it throws rather than returns null? |
Beta Was this translation helpful? Give feedback.
-
|
Not sure if the goal, namely partial hydration and streaming are worth such a huge breaking change. Now, if the change was enabling resumability, I'd have zero doubts. |
Beta Was this translation helpful? Give feedback.
-
|
What will the viewChild API that returns |
Beta Was this translation helpful? Give feedback.
-
|
This sounds terrible for low level devs like me, who are focused on Web APIs and UI components libraries as it potentially introduces a lot of imperative boilerplate, dependent on the order of execution. |
Beta Was this translation helpful? Give feedback.
-
|
Question 3: That's a great step forward for Angular. I have always found the ElementRef API not developer friendly. I like that the new api throw error when it is called. It will force developer to write code that follows the best practices. Returning Question 2: The limits are easy to understand. Angular has always discouraged DOM manipulation. This is the time to restrict it by throwing errors |
Beta Was this translation helpful? Give feedback.
-
|
q2: no. Will be there any changes in comparison to ElementRef? ElementRef was not always accessible either. q3:
No, I see no difference. ElementRef will throw an exception if undefined, and DomRef will throw an exception if not ready. What's the difference? A framework should have breaking changes to move forward, but what is the difference here? What for these breaking changes? Almost every library in the ecosystem will be affected - some apps will stuck with an upgrade not because they can't run a migration, but because a library they use didn't migrate. Maybe you could just improve the existing ElementRef somehow? |
Beta Was this translation helpful? Give feedback.
-
I think yes. Basically: Only access the DOM in the browser.
I do not agree with the first proposed benefit (that Especially the case of a domRef = viewChild('something');
const a = domRef(); // () here means "access the signal value"
const b = a(); // () here means "access the native element"
const c = nodeRef()(); // the repated () could be interpreted as bug on first glanceHowever, I think it is good that unwrapping a Property getters should never throw in my opinion - that would be unexpected. There is one third alternative API besides a getter and a function: just a method. I think it could be easier to understand, especially when combined with getters: The name |
Beta Was this translation helpful? Give feedback.
-
|
answering Question 1 case 1. multiple language supportin projects that support multiple languages especially if it's mixed between RTL and LTR languages (e.g. Arabic and English), we need to change the dir and language attributes of the html elements, and to add the proper css style files (e.g. bootstrap.min.css or bootstrap.rtl.min.css) on the server depending on the route the user is using (e.g. start with without rendering this in the SSR, it will mean only one language will be properly indexed, e.g. both Arabic and English pages will be indexed as English, and that the page will show initially as LTR then later on to switch to RTL here is an example of how this work case 2. SEO tagsadd SEO tags to the dom, e.g. canonical, keywords, description as they are dynamically generated from the URL or comes from the API side |
Beta Was this translation helpful? Give feedback.
-
|
I would like to see alternatives to deprecating ElementRef |
Beta Was this translation helpful? Give feedback.
-
|
Discussion Question 1: We’re proposing moving away from DOM emulation as a well-lit path. Do you have any use-cases that strictly depend on Angular's server-side DOM emulation today? Currently to use a Canonical Links how example ` createCanonicalLink(url: string) { ` Other hand it's render or append a custom overlay in server with usa document and send to client a modal or toast previous render `attachRoot(componentType: Type) { Question 3 Possible breaking change a libs or wrapper or elements if not migration applied to ElementRef , i prefer deprecated or coexist by certain of time |
Beta Was this translation helpful? Give feedback.
-
Use cases for ElementRef that I feel are going to become a lot harderI have voiced my concern regarding this RFC and in numerous places were asked for examples that I'm worried about, so here's a list of them in a separate branch of discussion.
If any of those are not self evident — feel free to ask about particular bullet and I will try to bring up a real life scenario. I understand that there might be criticism of most of these cases that they don't really make sense for SSR part of app lifecycle, however to this I would respond — it is MUCH easier to organize your app in a way that works both for client side and server side by just using early returns or properly reacting to, say, nullish size of elements on the server, than to branch it out explicitly into client side and server side pieces of executed code. I though DI was EXACTLY the answer to doing it this way by providing different dependencies in different environments to allow us to write code if we have everything we need all the time. Otherwise what was the point of |
Beta Was this translation helpful? Give feedback.
-
It depends, for webapps maybe, but if we use Angular to build websites, the inability to access DOM in SSR context would lead to a different HTML being produced on server vs in browser after bootstrapping of Angular / hydration, I would image this would potentially lead to content layout shifts (and hence rise in the CLS lighthouse metric) which is penalized. Angular, especially with SSR / SSG / hydration is an attractive option for websites as well as webapps and custom component libraries can provide unified style for all organization touchpoints which is very valuable and efficient. It seems that impact of this change would have negative consequences on this use case. |
Beta Was this translation helpful? Give feedback.
-
|
Care to give any details what |
Beta Was this translation helpful? Give feedback.
-
|
We have an application written in Angular and we have a set of web components for the common componentw (header, footer, menu, the shell component with the layout, notification center, etc). These components use shadow dom, both, open and close and expose not only props and events but also methods. We had a requirement to implement SSR but found, as mentioned, several problems. Would be possible with the new API using web components? |
Beta Was this translation helpful? Give feedback.
-
SEO tagsWe have a requirement to be able to set a few elements in One of the thing we rely on is the Today the implementation of
|
Beta Was this translation helpful? Give feedback.
-
|
Discussion Question 1: As mentioned, there are use cases where the checking the HTML structure is needed. For example, a directive that sets the Discussion Question 2: Yes, reasoning is clear and solution looks nice. However, there are private apps that will never need SSR or SEO. Forcing them to do a major refactor that can't be automated because of the deprecation of Discussion Question 3: Current API with I understand that the new one provides more benefits such as runtime checks. With the new Something similar will happen with Thoughts on the API I wonder why the generic type for |
Beta Was this translation helpful? Give feedback.
-
|
Discussion Question 1: We’re proposing moving away from DOM emulation as a well-lit path. Do you have any use-cases that strictly depend on Angular's server-side DOM emulation today? I'm concerned about limiting the ability of my organization, which chose the difficult path of supporting many frameworks, to use SSR alongside an ecosystem of design system components written in lit. I'm comfortable with "two" paths but uncomfortable with the risk of dwindling support for a domino-based app. My suggestion is to allow both, but keep domino-based the default for some time. Discussion Question 2: To help create components that always work great on the server and browser, we’re proposing limits to when and how native DOM elements can be accessed. Are these limits (and their rationale) easy to understand? Yes but I agree with sentiment expressed elsewhere which amounts to: I'd like to see an Angular way to dynamically create or update, during SSR, more parts of the Head -- inserting links, styles, tags, scripts, etc. Today I do this outside of Angular and provide the "processed" HTML to the commonEngine's render method. I'd rather do it in Angular. |
Beta Was this translation helpful? Give feedback.
-
|
Discussion Question 1: We’re proposing moving away from DOM emulation as a well-lit path. Do you have any use-cases that strictly depend on Angular's server-side DOM emulation today? My use case is that i need to be able to set a class on the document.body on the server, before it's sent to the client. This is used to allow the theme/colours to be set based on the config of the client using the app. |
Beta Was this translation helpful? Give feedback.
-
|
Hello everyone 👋 To start, thank you to everyone who participated in this RFC! Your feedback has been incredibly valuable. Additionally, we would like to thank you for your continued patience over the last few weeks. Many of you have raised valid concerns with this particular proposal, such as:
This is great feedback and demonstrates exactly why we have RFCs in the first place ✨. We strongly believe in the original motivations for this RFC: making DOM emulation optional while providing powerful but safer alternatives. However, this was always intended to be a longer term goal that we expected to gradually move toward over several major releases, while helping the ecosystem adjust along the way. Put simply: there’s no rush. That is why we’ve decided to put this idea back into the oven for the time being, so that we can spend more time considering your concerns and how best to address them. We’ll share more information in the future when we’re able to. Thank you again for your valuable feedback and insights 🙏 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Background
When server-side rendering an application today, Angular uses a library called Domino to provide implementations of a subset of browser APIs such as
DocumentandHTMLOListElement. With these emulated APIs, components that accessDOCUMENTorElementRef#nativeElementcan run on the server via the same code paths as the browser. This means that Angular developers can write code that interacts directly with the DOM and, in many cases, that code successfully runs on the server. However, the approach comes with some downsides:Limited support: As DOM emulation only implements a subset of the DOM, it works great in some cases, but falls apart in others. Standard browser features, like Shadow DOM, aren't supported, leading to issues that can be tricky to diagnose. This problem grows over time as browsers introduce new features.
Inefficient, error-prone: While manual DOM manipulation can be useful (for example, to avoid change detection errors), it prevents Angular from having full knowledge of the state of the DOM. This has two considerable consequences:
Separately from the technical challenges with DOM emulation, the framework's existing API for interacting with the DOM (
ElementRef) is more verbose than it needs to be. In considering how Angular developers interact with the DOM, we think there's an opportunity to make this API more ergonomic while also providing additional guard rails for building high performance apps.We would eventually like to move Angular toward a world where DOM emulation is an optional feature that developers explicitly choose to enable, as opposed to an integral part of its design. This opt-in approach will lead to components that are compatible with more advanced SSR features (e.g. partial hydration) by default. It will additionally help make Angular less complicated and easier to reason about.. To that end, we see a lot of potential in changing how we think about and expose the DOM to Angular components.
What kind of feedback are we looking for?
While we're excited to hear any and all comments on the changes proposed below, we have a few specific discussion points that we are especially keen to hear about. In particular:
ElementRefAPI with a new API namedDomRef. From a developer ergonomics perspective, doesDomRefseem easier to use thanElementRef? Are there any use-cases forElementRefthat are made worse by usingDomRef?When you leave a comment, be sure to note the question(s) to which you're responding. As always, keep our code of conduct in mind. We know that a proposal of this scope significantly impacts Angular and the way you use it in your projects. We appreciate your commitment and investment in this project and ask to keep comments respectful.
DomRefAPIA
DomRefis a wrapper around a DOM element. There are a few differences compared toElementRef. First,DomRefhas a more streamlined API: the value can be unwrapped simply by calling it:Second,
DomRefis contextual. To help prevent accidentally creating components that cannot be server-side rendered, aDomRefwill throw if you attempt to unwrap it before the nextafterRenderorafterNextRender:In general, we believe that the only time you should need to unwrap and access a native DOM element is on the browser, after the page has been rendered, typically in response to a user interacting with the page. The
DomRefAPI encourages this by making it an error to unwrap it elsewhere, while still allowing the reference to be safely passed around. In other situations, you should use features like host bindings to declaratively specify the DOM state.At the same time,
ElementRefwill be marked as deprecated.DOCUMENT_REFTokenToday, Angular provides a
DOCUMENTtoken that can be used to access the applicationDocumentsafely, without branching, during server-side rendering or on the browser.In a world where DOM emulation is optional, this value will need to be
null,undefined, or simply not provided during server-side rendering. To bridge this gap, we want to exposeDOCUMENT_REF: DomRef<Document>as a safer alternative. At the same time,DOCUMENTwill be marked as deprecated.Changes to view and content queries
Today, signal-based queries (e.g.
viewChild) and detector-based queries (e.g.@ViewChild) return anElementRefby default when noreadoption is configured. AsElementRefwill be deprecated in favor ofDomRef, a future major version will change this default toDomRefinstead. A schematic will provide an automatic migration as part ofng updateto avoid breaking existing code.(this RFC is posted by @jelbourn on behalf of its author, @devknoll)
Beta Was this translation helpful? Give feedback.
All reactions