You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This draft builds on #54 and adds a small set of production hardening changes without altering its props-diff or streams design:
make React root cleanup immediate and idempotent when a LiveView hook is destroyed
preserve both LiveReact.Encoder.encode/1 and encode/2 while removing deprecated protocol default arguments on Elixir 1.20
keep bitstring matching and unused compile-time dependencies warning-free on Elixir 1.20
guard Phoenix Ecto form encoding when the optional Ecto/FormData integration is unavailable
Why these changes are needed
React root lifecycle
The previous destroyed() callback deferred unmounting until phx:page-loading-stop. That event is tied to page navigation and is not guaranteed when a LiveView patch only removes the component, so the React root and its effects could remain alive after the hook had been destroyed. The deferred callback also read the mutable this._root later, which could target a different root if the hook state changed in the meantime.
The hook now captures the current root, clears this._root, and unmounts immediately. Clearing the reference before unmounting makes repeated or re-entrant destroyed() calls safe and guarantees that the same root is unmounted exactly once.
Protocol callback compatibility
The encoder previously declared def encode(value, opts \\ []) inside defprotocol. Elixir 1.20 deprecates default arguments in protocol definitions and warns that protocols may only declare callbacks without an implementation. These warnings fail projects that compile dependencies with warnings treated as errors.
The protocol now declares encode/1 and encode/2 explicitly. Each implementation defines encode(value) as a direct delegation to encode(value, []), preserving the existing one-argument API and behavior while making both protocol arities explicit and compatible with Elixir 1.20.
Validation
added a lifecycle regression test proving immediate, exactly-once unmounting, including a later phx:page-loading-stop and a repeated destroyed() call
verified the encoder retains the same encode(value) to encode(value, []) behavior across its protocol implementations
validated the changes on Elixir 1.20.3 with warnings treated as errors and through the Ptah production integration path
verified the optional phoenix_ecto boundary without requiring external provider or network calls
React root lifecycle
The previous destroyed() callback deferred unmounting until phx:page-loading-stop. That event is tied to page navigation and is not guaranteed when a LiveView patch only removes the component, so the React root and its effects could remain alive after the hook had been destroyed. The deferred callback also read the mutable this._root later, which could target a different root if the hook state changed in the meantime.
Incorrect. this is bind to the react instance it's not going to target another root.
The hook now captures the current root, clears this._root, and unmounts immediately. Clearing the reference before unmounting makes repeated or re-entrant destroyed() calls safe and guarantees that the same root is unmounted exactly once.
There is a good reason for that. First it come from the other live_vue and live_svelte
Destroy can trigger multiple time that's why we guard with a if.
Also the once prevent to attach the event multiple
This lv event is guarante.
Second if you do that before navigation if my memory is correct you unmount the component and create a flash before the navigation.
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
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.
Contributor checklist
Summary
This draft builds on #54 and adds a small set of production hardening changes without altering its props-diff or streams design:
LiveReact.Encoder.encode/1andencode/2while removing deprecated protocol default arguments on Elixir 1.20Why these changes are needed
React root lifecycle
The previous
destroyed()callback deferred unmounting untilphx:page-loading-stop. That event is tied to page navigation and is not guaranteed when a LiveView patch only removes the component, so the React root and its effects could remain alive after the hook had been destroyed. The deferred callback also read the mutablethis._rootlater, which could target a different root if the hook state changed in the meantime.The hook now captures the current root, clears
this._root, and unmounts immediately. Clearing the reference before unmounting makes repeated or re-entrantdestroyed()calls safe and guarantees that the same root is unmounted exactly once.Protocol callback compatibility
The encoder previously declared
def encode(value, opts \\ [])insidedefprotocol. Elixir 1.20 deprecates default arguments in protocol definitions and warns that protocols may only declare callbacks without an implementation. These warnings fail projects that compile dependencies with warnings treated as errors.The protocol now declares
encode/1andencode/2explicitly. Each implementation definesencode(value)as a direct delegation toencode(value, []), preserving the existing one-argument API and behavior while making both protocol arities explicit and compatible with Elixir 1.20.Validation
phx:page-loading-stopand a repeateddestroyed()callencode(value)toencode(value, [])behavior across its protocol implementationsphoenix_ectoboundary without requiring external provider or network callsFollow-up to #54.