|
2 | 2 | title: 'Runtime warnings'
|
3 | 3 | ---
|
4 | 4 |
|
5 |
| -## Client errors |
| 5 | +## Client warnings |
6 | 6 |
|
7 |
| -### bind_invalid_checkbox_value |
| 7 | +### binding_property_non_reactive |
8 | 8 |
|
9 | 9 | ```
|
10 |
| -Using `bind:value` together with a checkbox input is not allowed. Use `bind:checked` instead |
| 10 | +`%binding%` is binding to a non-reactive property |
11 | 11 | ```
|
12 | 12 |
|
13 |
| -### bind_invalid_export |
14 |
| - |
15 |
| -``` |
16 |
| -Component %component% has an export named `%key%` that a consumer component is trying to access using `bind:%key%`, which is disallowed. Instead, use `bind:this` (e.g. `<%name% bind:this={component} />`) and then access the property on the bound component instance (e.g. `component.%key%`) |
17 |
| -``` |
18 |
| - |
19 |
| -### bind_not_bindable |
20 |
| - |
21 | 13 | ```
|
22 |
| -A component is attempting to bind to a non-bindable property `%key%` belonging to %component% (i.e. `<%name% bind:%key%={...}>`). To mark a property as bindable: `let { %key% = $bindable() } = $props()` |
| 14 | +`%binding%` (%location%) is binding to a non-reactive property |
23 | 15 | ```
|
24 | 16 |
|
25 |
| -### component_api_changed |
| 17 | +### console_log_state |
26 | 18 |
|
27 | 19 | ```
|
28 |
| -%parent% called `%method%` on an instance of %component%, which is no longer valid in Svelte 5. See https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes for more information |
| 20 | +Your `console.%method%` contained `$state` proxies. Consider using `$inspect(...)` or `$state.snapshot(...)` instead |
29 | 21 | ```
|
30 | 22 |
|
31 |
| -### component_api_invalid_new |
| 23 | +When logging a [proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy), browser devtools will log the proxy itself rather than the value it represents. In the case of Svelte, the 'target' of a `$state` proxy might not resemble its current value, which can be confusing. |
32 | 24 |
|
33 |
| -``` |
34 |
| -Attempted to instantiate %component% with `new %name%`, which is no longer valid in Svelte 5. If this component is not under your control, set the `compatibility.componentApi` compiler option to `4` to keep it working. See https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes for more information |
35 |
| -``` |
| 25 | +The easiest way to log a value as it changes over time is to use the [`$inspect`](https://svelte.dev/docs/svelte/$inspect) rune. Alternatively, to log things on a one-off basis (for example, inside an event handler) you can use [`$state.snapshot`](https://svelte.dev/docs/svelte/$state#$state.snapshot) to take a snapshot of the current value. |
36 | 26 |
|
37 |
| -### derived_references_self |
| 27 | +### event_handler_invalid |
38 | 28 |
|
39 | 29 | ```
|
40 |
| -A derived value cannot reference itself recursively |
| 30 | +%handler% should be a function. Did you mean to %suggestion%? |
41 | 31 | ```
|
42 | 32 |
|
43 |
| -### each_key_duplicate |
44 |
| - |
45 |
| -``` |
46 |
| -Keyed each block has duplicate key at indexes %a% and %b% |
47 |
| -``` |
| 33 | +### hydration_attribute_changed |
48 | 34 |
|
49 | 35 | ```
|
50 |
| -Keyed each block has duplicate key `%value%` at indexes %a% and %b% |
| 36 | +The `%attribute%` attribute on `%html%` changed its value between server and client renders. The client value, `%value%`, will be ignored in favour of the server value |
51 | 37 | ```
|
52 | 38 |
|
53 |
| -### effect_in_teardown |
| 39 | +### hydration_html_changed |
54 | 40 |
|
55 | 41 | ```
|
56 |
| -`%rune%` cannot be used inside an effect cleanup function |
| 42 | +The value of an `{@html ...}` block changed between server and client renders. The client value will be ignored in favour of the server value |
57 | 43 | ```
|
58 | 44 |
|
59 |
| -### effect_in_unowned_derived |
60 |
| - |
61 | 45 | ```
|
62 |
| -Effect cannot be created inside a `$derived` value that was not itself created inside an effect |
| 46 | +The value of an `{@html ...}` block %location% changed between server and client renders. The client value will be ignored in favour of the server value |
63 | 47 | ```
|
64 | 48 |
|
65 |
| -### effect_orphan |
| 49 | +### hydration_mismatch |
66 | 50 |
|
67 | 51 | ```
|
68 |
| -`%rune%` can only be used inside an effect (e.g. during component initialisation) |
| 52 | +Hydration failed because the initial UI does not match what was rendered on the server |
69 | 53 | ```
|
70 | 54 |
|
71 |
| -### effect_update_depth_exceeded |
72 |
| - |
73 | 55 | ```
|
74 |
| -Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops |
| 56 | +Hydration failed because the initial UI does not match what was rendered on the server. The error occurred near %location% |
75 | 57 | ```
|
76 | 58 |
|
77 |
| -### hydration_failed |
| 59 | +### invalid_raw_snippet_render |
78 | 60 |
|
79 | 61 | ```
|
80 |
| -Failed to hydrate the application |
| 62 | +The `render` function passed to `createRawSnippet` should return HTML for a single element |
81 | 63 | ```
|
82 | 64 |
|
83 |
| -### invalid_snippet |
| 65 | +### legacy_recursive_reactive_block |
84 | 66 |
|
85 | 67 | ```
|
86 |
| -Could not `{@render}` snippet due to the expression being `null` or `undefined`. Consider using optional chaining `{@render snippet?.()}` |
| 68 | +Detected a migrated `$:` reactive block in `%filename%` that both accesses and updates the same reactive value. This may cause recursive updates when converted to an `$effect`. |
87 | 69 | ```
|
88 | 70 |
|
89 |
| -### lifecycle_legacy_only |
| 71 | +### lifecycle_double_unmount |
90 | 72 |
|
91 | 73 | ```
|
92 |
| -`%name%(...)` cannot be used in runes mode |
| 74 | +Tried to unmount a component that was not mounted |
93 | 75 | ```
|
94 | 76 |
|
95 |
| -### props_invalid_value |
| 77 | +### ownership_invalid_binding |
96 | 78 |
|
97 | 79 | ```
|
98 |
| -Cannot do `bind:%key%={undefined}` when `%key%` has a fallback value |
| 80 | +%parent% passed a value to %child% with `bind:`, but the value is owned by %owner%. Consider creating a binding between %owner% and %parent% |
99 | 81 | ```
|
100 | 82 |
|
101 |
| -### props_rest_readonly |
| 83 | +### ownership_invalid_mutation |
102 | 84 |
|
103 | 85 | ```
|
104 |
| -Rest element properties of `$props()` such as `%property%` are readonly |
| 86 | +Mutating a value outside the component that created it is strongly discouraged. Consider passing values to child components with `bind:`, or use a callback instead |
105 | 87 | ```
|
106 | 88 |
|
107 |
| -### rune_outside_svelte |
108 |
| - |
109 | 89 | ```
|
110 |
| -The `%rune%` rune is only available inside `.svelte` and `.svelte.js/ts` files |
| 90 | +%component% mutated a value owned by %owner%. This is strongly discouraged. Consider passing values to child components with `bind:`, or use a callback instead |
111 | 91 | ```
|
112 | 92 |
|
113 |
| -### state_descriptors_fixed |
| 93 | +### state_proxy_equality_mismatch |
114 | 94 |
|
115 | 95 | ```
|
116 |
| -Property descriptors defined on `$state` objects must contain `value` and always be `enumerable`, `configurable` and `writable`. |
| 96 | +Reactive `$state(...)` proxies and the values they proxy have different identities. Because of this, comparisons with `%operator%` will produce unexpected results |
117 | 97 | ```
|
118 | 98 |
|
119 |
| -### state_prototype_fixed |
120 |
| - |
121 |
| -``` |
122 |
| -Cannot set prototype of `$state` object |
123 |
| -``` |
| 99 | +`$state(...)` creates a [proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) of the value it is passed. The proxy and the value have different identities, meaning equality checks will always return `false`: |
124 | 100 |
|
125 |
| -### state_unsafe_local_read |
| 101 | +```svelte |
| 102 | +<script> |
| 103 | + let value = { foo: 'bar' }; |
| 104 | + let proxy = $state(value); |
126 | 105 |
|
| 106 | + value === proxy; // always false |
| 107 | +</script> |
127 | 108 | ```
|
128 |
| -Reading state that was created inside the same derived is forbidden. Consider using `untrack` to read locally created state |
129 |
| -``` |
130 |
| - |
131 |
| -### state_unsafe_mutation |
132 | 109 |
|
133 |
| -``` |
134 |
| -Updating state inside a derived or a template expression is forbidden. If the value should not be reactive, declare it without `$state` |
135 |
| -``` |
| 110 | +To resolve this, ensure you're comparing values where both values were created with `$state(...)`, or neither were. Note that `$state.raw(...)` will _not_ create a state proxy. |
136 | 111 |
|
137 | 112 |
|
138 |
| -## Shared errors |
| 113 | +## Shared warnings |
139 | 114 |
|
140 |
| -### invalid_default_snippet |
| 115 | +### dynamic_void_element_content |
141 | 116 |
|
142 | 117 | ```
|
143 |
| -Cannot use `{@render children(...)}` if the parent component uses `let:` directives. Consider using a named snippet instead |
| 118 | +`<svelte:element this="%tag%">` is a void element — it cannot have content |
144 | 119 | ```
|
145 | 120 |
|
146 |
| -### lifecycle_outside_component |
| 121 | +### state_snapshot_uncloneable |
147 | 122 |
|
148 | 123 | ```
|
149 |
| -`%name%(...)` can only be used during component initialisation |
| 124 | +Value cannot be cloned with `$state.snapshot` — the original value was returned |
150 | 125 | ```
|
151 | 126 |
|
152 |
| -### store_invalid_shape |
153 |
| - |
154 | 127 | ```
|
155 |
| -`%name%` is not a store with a `subscribe` method |
156 |
| -``` |
157 |
| - |
158 |
| -### svelte_element_invalid_this_value |
| 128 | +The following properties cannot be cloned with `$state.snapshot` — the return value contains the originals: |
159 | 129 |
|
160 |
| -``` |
161 |
| -The `this` prop on `<svelte:element>` must be a string, if defined |
| 130 | +%properties% |
162 | 131 | ```
|
163 | 132 |
|
0 commit comments