Skip to content

Lit templating engineΒ #70

@dgp1130

Description

@dgp1130

To improve security of the rendered output, we should not be using raw strings. Instead we should be using a real templating system which escapes data and input from the actual structure of the rendered HTML. This isn't a massive concern in a Bazel context for rendering at build time, since Bazel requires builds to be hermetic and checked in source code is usually pretty trusted. However potential supply chain vulnerabilities could leak malicious content into their outputs which get sent to users, so this is still good to do. If we move forward with SSR, this will be even more important.

For now, I'd like to start with lit-html as a templating engine because:

  1. It nicely fits the mental model of @rules_prerender.
  2. It works in the browser and in Node, so templates can be shared between client side rendering and prerendering.
    • No need for DOM emulation in Node either, as long as we limit our usage to lit-html and don't pull in LitElement.
  3. It doesn't require a compile-step, which means we don't need a special compiler plugin.
    • A compile-step wouldn't be a hard-blocker given that we have a very comprehensive build system available, but prerender_component() directly wraps the prerender ts_project() or js_library(), meaning it is very convenient (though not strictly required) to have first-party support for any templating engine with a compile-step.
  4. It aligns with JavaScript syntax (no change in the language syntax or grammar).
  5. I'm somewhat familiar with it already.

I'm also open to considering a JSX-based templating system since that has direct support in tsc. I'm not very familiar with it though, so I think that should come secondary to a lit-html engine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions