Skip to content

Hydration crashes in if branch for undefined data #15819

Closed
@kkarikos

Description

@kkarikos

Describe the bug

Hydration can crash at

hydrate_index = parseInt(data.substring(1));
because data is undefined.

When browser extension (or browser itself in some cases*) modifies the DOM content before the hydration executes, the value of data can become undefined. The result is that the whole page disappears which is unacceptable. Adding a check for undefined here fixes the issue but I am not certain what would be the desired value in this case.

*Safari WebView for example can detect some content as being telephone number and will modify it to become a link.

Reproduction

I created simple browser extension to modify #results of my application.

// manifest.json

{
  "manifest_version": 3,
  "name": "Localhost DOM Modifier",
  "version": "1.0",
  "description": "Modifies DOM for pages running on localhost",
  "permissions": ["activeTab", "scripting"],
  "host_permissions": ["http://localhost/*"],
  "content_scripts": [
    {
      "matches": ["http://localhost/*"],
      "js": ["content.js"],
      "run_at": "document_start"
    }
  ]
}

// content.js

window.addEventListener("load", function () {
  // Get #results container and add a test message as first child
  const resultsContainer = document.getElementById("results");
  const testMessage = document.createElement("div");
  testMessage.textContent = "TEST: This is a test message";
  resultsContainer.insertBefore(testMessage, resultsContainer.firstChild);
});

Logs

System Info

Binaries:
    Node: 20.17.0
    npm: 11.2.0
    pnpm: 9.11.0
  Browsers:
    Brave Browser: 135.1.77.100
    Chrome: 135.0.7049.95
  npmPackages:
    svelte: 5.28.2 => 5.28.

Severity

blocking all usage of svelte

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions