Skip to content

Custom stringify/transform option for static content in sfc compiler and loader #1687

@mmis1000

Description

@mmis1000

What problem does this feature solve?

When you write a non DOM environment custom renderer, you need to implement all required nodeOps of the renderer.

Most of opts are actually unaware of the runtime enviroment an long as the structure looks like a tree and have method for manipulate node.

However, insertStaticContent is used to insert a HTML string to reduce the overhead of create elements.
Which may not exist in the environment of other non dom target (if any).

You end up need to embed a parser to parse the html back to ast again and process it. Which cause more overhead instead.

For example, when you are rendering to something like fixed size canvas.
You will probably want to just pre-render the static tree into image directly if you can.
But you now need to parse the html and render to image again during runtime, which is double overhead.

What does the proposed API look like?

An option in the vue-compiler to override how static content should be handled.

Receive a argument for the content vue want to insert as static content (in either html or v-dom tree format (provide as object may reduce the overhead during compile but harm future compatibility if the internal structure is going to change)).

Returns a serializable object that vue will feed into the insertStaticContent when rendering.

Or accept null so the compiler do not generate static node at all.

const compilerOptions = {
  serializeStatic (domOrHTML) {
    return {
      'this': 'object will be send to insertStaticContent during rendering'
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions