New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow nesting of phx-update="ignore" and phx-update="replace" within a single LiveView #2802
Comments
Additionally, while searching for solutions to integrate LiveView with JS logic-rich pages, I came across a export const morphdomOptions = {
onBeforeElUpdated(from, to) {
// Keep element attributes starting with data-js-
// which we set on the client.
for (const attr of from.attributes) {
if (attr.name.startsWith("data-js-")) {
to.setAttribute(attr.name, attr.value);
}
if (attr.name === "data-keep-attribute") {
if (from.hasAttribute(attr.value)) {
to.setAttribute(attr.value, from.getAttribute(attr.value));
} else {
to.removeAttribute(attr.value);
}
}
}
},
onNodeAdded(node) {
// Mimic autofocus for dynamically inserted elements
if (node.nodeType === Node.ELEMENT_NODE && node.hasAttribute("autofocus")) {
node.focus();
if (node.setSelectionRange && node.value) {
const lastIndex = node.value.length;
node.setSelectionRange(lastIndex, lastIndex);
}
}
},
}; While this approach helps in certain scenarios, especially for preserving specific attributes and mimicking autofocus, I'd be interested in recommendations from the team:
Looking forward to insights and suggestions. |
We have no plans to support this at the moment because it opens up a pandora box of complexity, as we now have to perform diffs anywhere in the page. :( What you could try is to use a separate LiveViews. For example, you render a LiveView, then you phx-update=ignore some content, and inside that content, you
Yup, this is very common (at least in my apps). We have discussed providing something along those lines out of the box but we never officially taken any action because some additional handling is always required anyway (like your autofocus feature). In any case, closing this as unplanned, thank you. :) |
Hey @josevalim, Thank you, I truly appreciate the response directly from elixir's father :) I've set up a minimal reproducible example that illustrates the redirect to the For a quick code overview, you can check out the commit diff. I'd greatly appreciate any help on this further. I think making Phoenix work seamlessly with static site generators have possibility to boost development process for many teams. Got your point about the Can say that making LV Lastly, here are a few lines of related logs from the browser:
|
Hi @orsenkucher, can you please open up a bug report with the issue and the link to the app? Thank you! The tokens are indeed stale but it should not redirect to null. :) |
@josevalim yep, sure! |
Environment
Issue
We are integrating raw HTML, CSS, and JS exported from Webflow into our Phoenix application. This allows us to utilize designs, animations, and form structures directly from the Webflow export by adding them into the
priv/static
folder. We subsequently convert specific pages into LiveViews to populate with data from our backend.However, when a page is converted to a LiveView, Phoenix LiveView takes over DOM diffing, causing the original JS functionality from the Webflow export to be bypassed. This affects our animations and other JS-based functionalities. To address this, we've been using a combination of
phx-update="ignore"
to preserve animations and JS behaviors, andphx-update="replace"
by creating nested LiveViews and communicating between them using thesend
function.It would significantly simplify our integration process if we could directly nest
phx-update="ignore"
andphx-update="replace"
within a single LiveView. This would allow us to selectively disable and enable DOM diffing in specific regions of the DOM as per our requirements.Expected behavior
Allow the nesting of
phx-update="ignore"
andphx-update="replace"
directives within a single LiveView, giving developers more granular control over DOM diffing on a per-region basis.Actual behavior
Currently, we need to use nested LiveViews to achieve this functionality, adding unnecessary complexity to our codebase.
The text was updated successfully, but these errors were encountered: