Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions local-live-view/assets/local_live_view/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export interface LLVView {
opts: object,
): void;
addHook: (el: Element) => unknown;
ownsElement?: (el: Element) => boolean;
destroy?: (callback?: () => void) => void;
}

Expand Down
7 changes: 7 additions & 0 deletions local-live-view/assets/local_live_view/view_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ export function setupFakeView(
// stock Channel/Push machinery over the PopcornTransport.
view.channel = popcornSocket.channel(`lv:${llvId}`);

// LLV roots have no data-phx-session, so stock ownsElement (closestViewEl) would
// assign children to the host LiveView or reject them entirely — and addHook
// would skip every phx-hook under this container. Own the subtree by containment.
view.ownsElement = function (this: LLVView, el: Element) {
return this.el === el || this.el.contains(el);
};

// addHook: skip the root element to prevent Phoenix from trying to register it
// as a hook within this view's scope — hooks on children are still processed normally.
const origAddHook = view.addHook.bind(view);
Expand Down
6 changes: 6 additions & 0 deletions local-live-view/priv/static/local_live_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,12 @@ function setupFakeView(socket, views, popcornSocket, pop_view_el) {
// diffs, out-of-band "diff" frames, ref bookkeeping — runs through the
// stock Channel/Push machinery over the PopcornTransport.
view.channel = popcornSocket.channel(`lv:${llvId}`);
// LLV roots have no data-phx-session, so stock ownsElement (closestViewEl) would
// assign children to the host LiveView or reject them entirely — and addHook
// would skip every phx-hook under this container. Own the subtree by containment.
view.ownsElement = function (el) {
return this.el === el || this.el.contains(el);
};
// addHook: skip the root element to prevent Phoenix from trying to register it
// as a hook within this view's scope — hooks on children are still processed normally.
const origAddHook = view.addHook.bind(view);
Expand Down