Open
Conversation
… after $onDestroy Add _destroyed flag in $onDestroy and guard $doCheck/$onChanges with early return to avoid "Cannot update an unmounted root" error in React 19 when AngularJS fires $onChanges after $onDestroy in the same digest cycle. Bump version to 18.0.1. Made-with: Cursor
Replace incorrect React.Element with ComponentType<TProps>, add generic bindings constraint to map component props to AngularJS binding types. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #33
_destroyedflag set in$onDestroyto guard against late lifecycle calls$doCheckand$onChangeswith early return when_destroyedistrue$onChangesafter$onDestroyin the same digest cycleReact.ElementwithComponentType<TProps>, add generic bindings constraint18.0.0→18.0.1Problem
AngularJS does not guarantee that
$onChangeswon't fire after$onDestroywhen both a binding change and component destruction occur in the same digest cycle. This causesroot.render()to be called on an already-unmounted React root.Changes
src/index.js(3 lines added):this.$doCheck = () => { + if (this._destroyed) return; for (let previousKey of Object.keys(previous)) { this.$onChanges = () => { + if (this._destroyed) return; this.root.render(React.createElement(Component, this)); }; this.$onDestroy = () => { + this._destroyed = true; this.root.unmount(); };index.d.ts— improved type declarations:React.Element→ComponentType<TProps>(was incorrectly typed as JSX element instead of component)bindings: any→{ [K in keyof TProps]?: '<' | '=' | '@' | '&' }(type-safe mapping of component props to AngularJS binding types)<TProps>to link component props with bindingsindex.js— regenerated vianpm run buildpackage.json— version bump to18.0.1Test plan
<and=bindings