Preload WASM files for compiling code component previews

Created on 9 April 2025, 3 months ago

Overview

The real-time preview in the code editor for code components requires two large WASM files: one for SWC (~19M), and one for Lightning CSS (~11M). They are currently downloaded on-demand, whenever the code editor is used for the first time, after which browsers will cache them.

Using a slower network this can take a significant amount of time.

Proposed resolution

We can preload these files for user who have the appropriate permission to use the code editor. E.g.:

  • /modules/contrib/experience_builder/ui/dist/assets/wasm_bg.wasm
  • /modules/contrib/experience_builder/ui/dist/assets/lightningcss_node-1.27.0.wasm

User interface changes

None.

Feature request
Status

Active

Version

0.0

Component

Theme builder

Created by

🇳🇱Netherlands balintbrews Amsterdam, NL

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @balintbrews
  • 🇳🇱Netherlands balintbrews Amsterdam, NL

    @lauriii suggested this after investigating a performance bug report.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    I wonder if we could/should do this in requestIdleTimeout instead so it doesn't impact the initial load time of the rest of XB
    Although we could also use a fetchpriority of low and leave the browser to work it out

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    we have some prior art in \Drupal\experience_builder\Plugin\ExperienceBuilder\ComponentSource\JsComponent::renderComponent albeit for modulepreloads

  • 🇳🇱Netherlands balintbrews Amsterdam, NL

    Although we could also use a fetchpriority of low and leave the browser to work it out

    Something like that is what I had in mind.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
  • Pipeline finished with Success
    3 months ago
    Total: 75492s
    #472784
  • Pipeline finished with Failed
    2 months ago
    Total: 834s
    #484351
  • Pipeline finished with Failed
    2 months ago
    Total: 832s
    #484373
  • Pipeline finished with Failed
    2 months ago
    Total: 1356s
    #484375
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Apparently this massively reduces load times on high-latency environments: 8–10 seconds → <3 seconds.

  • 🇺🇸United States effulgentsia

    The code in the MR looks good, so I approved it (before seeing Wim's comments), but it seems questionable to me to be preloading 30MB of stuff (even with low fetch priority) before we even know the person wants to edit a code component. I wonder if we should delay this until there's some further indication of that, such as:

    • Clicking "Add new component" (after which there's a bit of time for the user to enter a name for it)
    • There already existing at least one code component (either as a real config entity or in auto-save)

    React-dom has a preload function by the way, if we want to initiate this based on some client-side determined condition.

    Since this MR only preloads for people with the "administer code component" permission, I'd be okay with this being merged as-is (once Wim's okay with it) and us discussing the above in a follow-up.

  • 🇺🇸United States effulgentsia

    Also, we don't need these when the user first enters the code editor, do we? Since either it's a new code component, so we're using the sample code, or it's an exiting code component, so we're using whatever was previously saved, so in both cases, we already have previously compiled stuff we can show in the preview. Which means we don't need to execute the wasm code until the user starts typing something into the code editor. At which point, could we put a message in the preview area saying "Generating Preview..." or something like that if the wasm files haven't fully downloaded yet?

  • 🇳🇱Netherlands balintbrews Amsterdam, NL

    I agree with #12 and #13 Preload WASM files for compiling code component previews Active : An action on the UI would be better to use as a trigger for preloading the assets.

    How close are we to introduce granular permissions to code components? If we are, I also agree that the current MR could go in, since it only impacts the "administer code component" permission.

    #13 Preload WASM files for compiling code component previews Active :

    Also, we don't need these when the user first enters the code editor, do we? Since either it's a new code component, so we're using the sample code, or it's an existing code component, so we're using whatever was previously saved, so in both cases, we already have previously compiled stuff we can show in the preview.

    This sounds very sensible, but at the time of implementing that, I thought it was a good idea to always re-compile the first preview for these components to ensure consistency with the current compilation config. Now it seems unnecessary, however, we do additional compilation for the code editor preview only: we compile the slot examples into Preact components. (dangerouslySetInnerHTML is not supported on Fragment, so we compile the example HTML code for slots into proper Preact components.) If we were to switch to using the compiled JS for the code editor preview, we'd need to start storing that as well.

    My recommendation for the (future) UI changes would be to use the toast and overlay that was introduced in 🐛 Auto-save changes from code editor get lost if you navigate out too quickly Active when the code editor opens, and the WASM assets are not available. If and when we decide to start using the compiled JS even for the first preview, we can still rely on this UI pattern, but not right when the code editor opens.

  • Pipeline finished with Success
    about 1 month ago
    Total: 1550s
    #514725
  • Status changed to Needs work 17 days ago
  • 🇺🇸United States effulgentsia

    This is currently a several second latency, just a single time and then browser cached, and only for people editing code components. It doesn't need to block a beta. It's possible we'll manage to squeeze it in before beta anyway, but we don't need to track it for that.

Production build 0.71.5 2024