Skip to content

Commit fa4f120

Browse files
committed
fix: mount Svelte example and CLI template with Svelte 5 API
The svelte example and the native init Svelte scaffold both called new App({ target }), the Svelte 4 component constructor. Svelte 5 removed it, so every checkout of examples/svelte and every freshly generated Svelte project throws component_api_invalid_new on load. Switch both to mount(App, { target }) from the svelte package. Fixes #48
1 parent 36d295a commit fa4f120

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

changelog.d/svelte-mount-api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: **Svelte example and template mount correctly on Svelte 5**: `main.js` used the removed Svelte 4 `new App({ target })` constructor, which throws `component_api_invalid_new` under Svelte 5. Both the `examples/svelte` app and the `native init` Svelte scaffold now mount with `mount(App, { target })` from `svelte`.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { mount } from "svelte";
12
import App from "./App.svelte";
23
import "./app.css";
34

4-
const app = new App({ target: document.getElementById("app") });
5+
const app = mount(App, { target: document.getElementById("app") });
56

67
export default app;

src/tooling/templates.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2589,10 +2589,11 @@ fn svelteIndexHtml(allocator: std.mem.Allocator, names: TemplateNames) ![]const
25892589

25902590
fn svelteMainJs() []const u8 {
25912591
return
2592+
\\import { mount } from "svelte";
25922593
\\import App from "./App.svelte";
25932594
\\import "./app.css";
25942595
\\
2595-
\\const app = new App({ target: document.getElementById("app") });
2596+
\\const app = mount(App, { target: document.getElementById("app") });
25962597
\\
25972598
\\export default app;
25982599
\\

0 commit comments

Comments
 (0)