refactor(KeepAlive): scope wrapChildren props, drop as any in getExisting#10
Merged
Conversation
…isting Two small cleanups to KeepAlive.tsx: 1. Stop leaking KeepAlive-level config onto the Lightning view `wrapChildren` spread the full props bag onto the inner `<view>` and then overrode the handful it actually wanted (`onRemove`, `onRender`, `transition`, `preserve`, `forwardFocus`). That meant the view was also receiving `id`, `shouldDispose`, and the *original* (unchained) `onRemove` / `onRender` / `transition` before they were re-set — harmless for `id`, but `shouldDispose` is not a view-level concern and noisily lands on the Lightning element. Switch to passing only the props the view needs, and insert `props.children` explicitly. 2. Reflect that KeepAliveElement is built up lazily `getExisting` constructs a partial entry holding only `id` + the `isAlive` signal until the route mounts; it then `as any`-casts to satisfy a type that declared `owner`, `children`, and `dispose` as required. Mark those three fields optional on `KeepAliveElement` (matching reality), drop the `as any`, and tighten the casts at call-sites: `as unknown as ElementNode | undefined` so optional chaining works without lying about the value's presence. No behavior change. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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
Two small cleanups to
src/primitives/KeepAlive.tsx. No behavior change.1. Stop leaking KeepAlive-level config onto the Lightning view
wrapChildrendid:propsiss.ParentProps<KeepAliveProps>, so the spread also pushedid,shouldDispose, and the original unchainedonRemove/onRender/transitiononto the view before the targeted overrides re-set them. Harmless forid, butshouldDisposeis purely KeepAlive-level — it has no business landing on a Lightning element. Replace the spread with explicit props the view needs and insertprops.childrendirectly.2. Reflect that
KeepAliveElementis populated lazilygetExistingconstructs a partial entry holding onlyid+ theisAlivesignal, and only populatesowner/children/disposeonce the route mounts or preload runs. Today the type marks those three fields as required, andgetExistingresorts toas any. Mark them optional onKeepAliveElement(matching reality), drop the cast, and tighten the existing casts at call-sites toas unknown as ElementNode | undefinedso optional chaining can work honestly.Test plan
tsc --noEmitclean (pre-existing errors elsewhere in the repo are unaffected).eslint src/primitives/KeepAlive.tsxclean.🤖 Generated with Claude Code