Skip to content

[bug] web_dev_server removes HTML template element contents #6165

@AlainSchneble

Description

@AlainSchneble

Describe the bug

When serving html files through web_dev_server by using cargo tauri dev, any template element contents in the served HTML are removed.

While looking further into this issue, the culprit seem to be this:

f = document.to_string().as_bytes().to_vec();

FMPOV, this should be changed to:

f = tauri_utils::html::serialize_node(&document);

(I've actually tried this change out and it solves the issue)

A similar issue has already been fixed for the assets compilation process / asset csp modification, see #5247 (and also #4410) but the web_dev_server hasn't catched up with this change.

Reproduction

  1. cargo create-tauri-app

  2. Select plain vanilla HTML/CSS/JavaScript

  3. Add the following template element before the closing body tag in src/index.html:

<template>
    <tr>
        <td>[ID]</td>
        <td>[Name]</td>
    <tr>
</template>
  1. cargo tauri dev
  2. Inspect the DOM and observe that the template element is empty

Expected behavior

HTML template element contents should be served properly.

For the example above, I would expect to see the following children when inspecting the DOM:

<template>
    #document-fragment
        <tr>
            <td>[ID]</td>
            <td>[Name]</td>
        <tr>
</template>

Platform and versions

Environment
  › OS: Windows 10.0.19045 X64
  › Webview2: 109.0.1518.69
  › MSVC:
      - Visual Studio Community 2022
      - Visual Studio Community 2019
  › Node.js: 19.1.0
  › npm: 8.19.3
  › pnpm: Not installed!
  › yarn: Not installed!
  › rustup: 1.25.1
  › rustc: 1.66.1
  › cargo: 1.66.1
  › Rust toolchain: stable-x86_64-pc-windows-msvc 

Packages                                       
WARNING: no lock files found, defaulting to npm
  › @tauri-apps/cli [NPM]: 1.2.3
  › @tauri-apps/api [NPM]: Not installed!
  › tauri [RUST]: 1.2.4,
  › tauri-build [RUST]: 1.2.1,
  › tao [RUST]: 0.15.8,
  › wry [RUST]: 0.23.4,

App
  › build-type: bundle
  › CSP: default-src 'self'
  › distDir: ../src
  › devPath: ../src
package.json not found

App directory structure
  ├─ .vscode
  ├─ src
  └─ src-tauri

Stack trace

No response

Additional context

No response

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