Skip to content

Add support for lydell’s fork of elm/virtual-dom #40

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

Draft
wants to merge 3 commits into
base: lamdera-next
Choose a base branch
from

Conversation

lydell
Copy link
Contributor

@lydell lydell commented Feb 11, 2025

This makes lamdera live work with my fork of elm/virtual-dom – read more here: https://github.com/lydell/elm-safe-virtual-dom.

However, this won’t work when migrating a production app from a version that uses the official elm/virtual-dom to a version that uses my fork. When migrating in production, we transfer the last-rendered virtual DOM node from the old app to the new. However, it won’t be compatible (since my fork naturally has changes). I think it’s possible to write a migration function that upgrades it, but I haven’t done that yet. I have not tested a production upgrade between two app versions, but I’ve gone through the code and it looks like other than that it should™️ work.

Another thing that won’t work in production is that your Elm code is compiled to JS on the server, where you don’t have the possibility to patch packages. However, Lamdera is interested in making this work and we’re collaborating on how to best do that.


Lamdera copies some functions from elm/virtual-dom, to make modifications to them. My fork of elm/virtual-dom also changes those functions. This PR copies those changes, and supports both the original version and my fork by if-ing on whether _VirtualDom_wrap exists (one of the new functions in my fork, arbitrary choice). This is for _VirtualDom_applyPatches, _VirtualDom_diff and _VirtualDom_applyPatches.

My fork also removes _VirtualDom_equalEvents, which Lamdera references. The solution is to just define the variable.

Finally, I added the data-elm attribute to <pre id="elm"></pre>. My fork only virtualizes elements with data-elm, for better compatibility with third-party scripts.

lamdera live assumes that initializing the Elm app removes that element, and displays a message in it otherwise:

compiler/extra/live.js

Lines 124 to 126 in 6415988

if (document.getElementById(elid)) {
document.getElementById(elid).innerText = 'This is a headless program, meaning there is nothing to show here.\n\nI started the program anyway though, and you can access it as `app` in the developer console.'
}

By adding data-elm to it, Elm will virtualize it, and then realize that it isn’t needed and remove it (just like before).

@lydell lydell marked this pull request as draft August 3, 2025 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant