question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Depricate renderer2, and and explainer on docs

See original GitHub issue

Description

As Renderer2 is mostly tied to Viewengine, it should be marked as deprecated. Also, there should be a note in the docs explaining why renderer2 is no longer the recommended way to DOM manipulation. This is needed because in the Angular community, there is still this idea that they should use it, and this idea is watched up by time, but most missed the notice.

What is the affected URL?

nvt

Please provide the steps to reproduce the issue

nvt

Please provide the expected behavior vs the actual behavior you encountered

No response

Please provide a screenshot if possible

No response

Please provide the exception or error you saw

No response

Is this a browser-specific issue? If so, please specify the device, browser, and version.

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:10
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
SanderEliascommented, Jul 25, 2022

@ohois

class SomeComponent {
   doc = inject(DOCUMENT)
   
   ngOninit() {
     const document = this.doc;
     document.createElement('div')
     ... and so on
   }
}

So, inject DOCUMENT and use that like the old-fashioned way to do whatever you desire.

0reactions
edusperonicommented, Oct 11, 2022

Although I understand the reasoning behind it, the renderer interface might still be useful do use internally especially due to some extra optional APIs that can be used. One example is destroyNode, which is not in the dom spec but is useful for some clean ups on custom renderer implementations.

https://github.com/angular/angular/blob/6a88bad0192516f26a5a008c0634b73456b9447c/packages/core/src/render3/node_manipulation.ts#L95

Internally it seems to also be used for animations, where we need to intercept the node removal and sometimes delay the actual removal to a later time, which would be a bit troublesome to do if we had to override DOCUMENT with custom implementations of the methods needed:

https://github.com/angular/angular/blob/39b72e208b46d80f1d9a802cebf043c2ccf3c5f2/packages/platform-browser/animations/src/animation_renderer.ts#L22

https://github.com/angular/angular/blob/39b72e208b46d80f1d9a802cebf043c2ccf3c5f2/packages/platform-browser/animations/src/animation_renderer.ts#L176-L178

So maybe it having it moved to an internal API would make more sense? Then again, I’m not sure the implications would be if people are using Renderer2 specifically to trigger animations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Renderer is deprecated as a favor for renderer2, alternative ...
Problem is renderer is deprecated in favor of renderer2 and I cant seem to find alternative for the method invokeElementMethod in renderer2 ....
Read more >
Renderer2 - Angular
Use a custom renderer to bypass Angular's templating and make custom UI changes that can't be expressed declaratively. For example if you need...
Read more >
Dynamic Rendering | Google Search Central | Documentation
Dynamic rendering requires your web server to detect crawlers (for example, by checking the user agent). Requests from crawlers are routed to a...
Read more >
Chrome Enterprise and Education release notes
The next step is to remove support in non-secure contexts. In Chrome 105, we introduced a deprecation warning in DevTools. We'll remove this ......
Read more >
Deprecation policy - Pants build
A module, variable, method, function, or class is part of the public API if at least one of the following is true: Its...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found