コンパイラの警告
Svelte は、アクセスできないマークアップの作成など、潜在的なミスを検出した場合、コンパイル時に警告を発します。
具体的なユースケースでは、一部の警告が正しくない場合があります。このような誤検知は、警告の原因となっている行の上に <!-- svelte-ignore <code> -->
コメントを配置することで無効にすることができます。 例
<!-- svelte-ignore a11y_autofocus -->
<input autofocus />
1つのコメントに複数のルールをリストし(カンマで区切る)、説明的なメモを括弧内に追加できます。
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions (because of reasons) -->
<div onclick>...</div>
a11y_accesskey
Avoid using accesskey
要素に accesskey
を使用しないようにします。アクセスキーは、Web 開発者が要素にキーボードショートカットを割り当てることができる HTML 属性です。キーボードショートカットと、スクリーンリーダーやキーボードのみのユーザーが使用するキーボードコマンドとの間に不整合があると、アクセシビリティの問題が発生します。問題を回避するために、アクセスキーを使用しないでください。
<!-- A11y: Avoid using accesskey -->
<div accesskey="z"></div>
a11y_aria_activedescendant_has_tabindex
An element with an aria-activedescendant attribute should have a tabindex value
aria-activedescendant
を持つ要素はタブ移動可能である必要があるため、固有の tabindex
を持つ必要があります。または属性として tabindex
を宣言する必要があります。
<!-- A11y: Elements with attribute aria-activedescendant should have tabindex value -->
<div aria-activedescendant="some-id"></div>
a11y_aria_attributes
`<%name%>` should not have aria-* attributes
特定の予約済み DOM 要素は、ARIA のロール、状態、およびプロパティをサポートしていません。これは、多くの場合、meta
、html
、script
、style
など、表示されないためです。このルールは、これらの DOM 要素に aria-*
プロパティが含まれていないことを強制します。
<!-- A11y: <meta> should not have aria-* attributes -->
<meta aria-hidden="false" />
a11y_autocomplete_valid
'%value%' is an invalid value for 'autocomplete' on `<input type="%type%">`
a11y_autofocus
Avoid using autofocus
要素に autofocus
が使用されていないことを強制します。要素の自動フォーカスは、晴眼ユーザーと非晴眼ユーザーの両方にとって、使いやすさの問題を引き起こす可能性があります。
<!-- A11y: Avoid using autofocus -->
<input autofocus />
a11y_click_events_have_key_events
Visible, non-interactive elements with a click event must be accompanied by a keyboard event handler. Consider whether an interactive element such as `<button type="button">` or `<a>` might be more appropriate. See https://svelte.dokyumento.jp/docs/accessibility-warnings#a11y-click-events-have-key-events for more details
表示されていて、インタラクティブではない onclick
イベントを持つ要素には、キーボードイベントハンドラが付属していることを強制します。
ユーザーはまず、アクションの場合は <button type="button">
要素、ナビゲーションの場合は <a>
要素など、インタラクティブな要素の方が適切かどうかを検討する必要があります。これらの要素は、意味的に意味があり、組み込みのキー処理が備わっています。例:Space
キーと Enter
キーは <button>
をトリガーし、Enter
キーは <a>
要素をトリガーします。
インタラクティブでない要素が必要な場合は、onclick
に加えて、ユーザーがキーボードを介して同等の操作を実行できる onkeyup
または onkeydown
ハンドラが必要です。ユーザーがキーを押せるようにするには、tabindex
を追加して、要素にフォーカスできるようにする必要もあります。onkeypress
ハンドラもこの警告を抑制しますが、keypress
イベントは非推奨であることに注意してください。
<!-- A11y: visible, non-interactive elements with an onclick event must be accompanied by a keyboard event handler. -->
<div onclick={() => {}}></div>
キーボードのコーディングは、マウスを使用できない身体障害のあるユーザー、支援技術の互換性、およびスクリーンリーダーのユーザーにとって重要です。
a11y_consider_explicit_label
Buttons and links should either contain text or have an `aria-label` or `aria-labelledby` attribute
a11y_distracting_elements
Avoid `<%name%>` elements
気を散らす要素が使用されていないことを強制します。視覚的に気を散らす可能性のある要素は、視覚障害のあるユーザーのアクセシビリティの問題を引き起こす可能性があります。このような要素はほとんどの場合非推奨であり、避ける必要があります。
視覚的に気を散らす要素は次のとおりです。<marquee>
と <blink>
。
<!-- A11y: Avoid <marquee> elements -->
<marquee></marquee>
a11y_figcaption_index
`<figcaption>` must be first or last child of `<figure>`
a11y_figcaption_parent
`<figcaption>` must be an immediate child of `<figure>`
特定の DOM 要素が正しい構造になっていることを強制します。
<!-- A11y: <figcaption> must be an immediate child of <figure> -->
<div>
<figcaption>Image caption</figcaption>
</div>
a11y_hidden
`<%name%>` element should not be hidden
特定の DOM 要素は、スクリーンリーダーのナビゲーションに役立ち、非表示にしないでください。
<!-- A11y: <h2> element should not be hidden -->
<h2 aria-hidden="true">invisible header</h2>
a11y_img_redundant_alt
Screenreaders already announce `<img>` elements as an image
img alt 属性に image、picture、photo などの単語が含まれていないことを強制します。スクリーンリーダーはすでに img
要素を画像としてアナウンスしています。 _image_、_photo_、_picture_ などの単語を使用する必要はありません。
<img src="foo" alt="Foo eating a sandwich." />
<!-- aria-hidden, won't be announced by screen reader -->
<img src="bar" aria-hidden="true" alt="Picture of me taking a photo of an image" />
<!-- A11y: Screen readers already announce <img> elements as an image. -->
<img src="foo" alt="Photo of foo being weird." />
<!-- A11y: Screen readers already announce <img> elements as an image. -->
<img src="bar" alt="Image of me at a bar!" />
<!-- A11y: Screen readers already announce <img> elements as an image. -->
<img src="foo" alt="Picture of baz fixing a bug." />
a11y_incorrect_aria_attribute_type
The value of '%attribute%' must be a %type%
aria 属性に正しいタイプの値のみが使用されていることを強制します。たとえば、aria-hidden
はブール値のみを受け取る必要があります。
<!-- A11y: The value of 'aria-hidden' must be exactly one of true or false -->
<div aria-hidden="yes"></div>
a11y_incorrect_aria_attribute_type_boolean
The value of '%attribute%' must be either 'true' or 'false'. It cannot be empty
a11y_incorrect_aria_attribute_type_id
The value of '%attribute%' must be a string that represents a DOM element ID
a11y_incorrect_aria_attribute_type_idlist
The value of '%attribute%' must be a space-separated list of strings that represent DOM element IDs
a11y_incorrect_aria_attribute_type_integer
The value of '%attribute%' must be an integer
a11y_incorrect_aria_attribute_type_token
The value of '%attribute%' must be exactly one of %values%
a11y_incorrect_aria_attribute_type_tokenlist
The value of '%attribute%' must be a space-separated list of one or more of %values%
a11y_incorrect_aria_attribute_type_tristate
The value of '%attribute%' must be exactly one of true, false, or mixed
a11y_interactive_supports_focus
Elements with the '%role%' interactive role must have a tabindex value
インタラクティブなロールとインタラクティブなハンドラ(マウスまたはキー押下)を持つ要素は、フォーカス可能またはタブ移動可能である必要があることを強制します。
<!-- A11y: Elements with the 'button' interactive role must have a tabindex value. -->
<div role="button" onkeypress={() => {}} />
a11y_invalid_attribute
'%href_value%' is not a valid %href_attribute% attribute
アクセシビリティに重要な属性が有効な値を持っていることを強制します。たとえば、href
は空、 `'#'`、または `javascript:`であってはなりません。
<!-- A11y: '' is not a valid href attribute -->
<a href="">invalid</a>
a11y_label_has_associated_control
A form label must be associated with a control
label タグにテキストラベルと関連付けられたコントロールがあることを強制します。
ラベルをコントロールに関連付けるには、2つの方法がサポートされています。
- コントロールを label タグで囲みます。
- label に `for` を追加し、ページ上の入力の ID を割り当てます。
<label for="id">B</label>
<label>C <input type="text" /></label>
<!-- A11y: A form label must be associated with a control. -->
<label>A</label>
a11y_media_has_caption
`<video>` elements must have a `<track kind="captions">`
聴覚障害のあるユーザーがメディアの内容を理解するには、キャプションを提供することが不可欠です。キャプションは、会話、効果音、関連する音楽の手がかり、およびその他の関連するオーディオ情報の文字起こしまたは翻訳である必要があります。これはアクセシビリティにとって重要であるだけでなく、メディアが利用できない場合(画像が読み込めない場合の画像の `alt` テキストと同様)にすべてのユーザーにとって役立つ可能性があります。
キャプションには、対応するメディアを理解するために重要かつ関連するすべての情報が含まれている必要があります。これは、キャプションがメディアコンテンツの会話と 1:1 で対応しているとは限らないことを意味する場合があります。ただし、`muted` 属性を持つビデオコンポーネントにはキャプションは必要ありません。
<video><track kind="captions" /></video>
<audio muted></audio>
<!-- A11y: Media elements must have a <track kind=\"captions\"> -->
<video></video>
<!-- A11y: Media elements must have a <track kind=\"captions\"> -->
<video><track /></video>
a11y_misplaced_role
`<%name%>` should not have role attribute
特定の予約済み DOM 要素は、ARIA のロール、状態、およびプロパティをサポートしていません。これは、多くの場合、`meta`、`html`、`script`、`style` など、表示されないためです。このルールは、これらの DOM 要素に `role` プロパティが含まれていないことを強制します。
<!-- A11y: <meta> should not have role attribute -->
<meta role="tooltip" />
a11y_misplaced_scope
The scope attribute should only be used with `<th>` elements
scope 属性は、`<th>` 要素にのみ使用する必要があります。
<!-- A11y: The scope attribute should only be used with <th> elements -->
<div scope="row" />
a11y_missing_attribute
`<%name%>` element should have %article% %sequence% attribute
アクセシビリティに必要な属性が要素に存在することを強制します。これには、次のチェックが含まれます。
- `<a>` には href が必要です(フラグメント定義タグでない限り)。
- `<area>` には alt、aria-label、または aria-labelledby が必要です。
- `<html>` には lang が必要です。
- `<iframe>` には title が必要です。
- `<img>` には alt が必要です。
- `<object>` には title、aria-label、または aria-labelledby が必要です。
- `<input type="image">` には alt、aria-label、または aria-labelledby が必要です。
<!-- A11y: <input type=\"image\"> element should have an alt, aria-label or aria-labelledby attribute -->
<input type="image" />
<!-- A11y: <html> element should have a lang attribute -->
<html></html>
<!-- A11y: <a> element should have an href attribute -->
<a>text</a>
a11y_missing_content
`<%name%>` element should contain text
見出し要素(`h1`、`h2` など)とアンカーにコンテンツがあり、そのコンテンツがスクリーンリーダーでアクセスできることを強制します。
<!-- A11y: <a> element should have child content -->
<a href="/foo"></a>
<!-- A11y: <h1> element should have child content -->
<h1></h1>
a11y_mouse_events_have_key_events
'%event%' event must be accompanied by '%accompanied_by%' event
`onmouseover` と `onmouseout` にそれぞれ `onfocus` と `onblur` が付属していることを強制します。これにより、これらのマウスイベントによってトリガーされる機能がキーボードユーザーにもアクセスできるようになります。
<!-- A11y: onmouseover must be accompanied by onfocus -->
<div onmouseover={handleMouseover} />
<!-- A11y: onmouseout must be accompanied by onblur -->
<div onmouseout={handleMouseout} />
a11y_no_abstract_role
Abstract role '%role%' is forbidden
a11y_no_interactive_element_to_noninteractive_role
`<%element%>` cannot have role '%role%'
WAI-ARIAのロールは、インタラクティブな要素を非インタラクティブな要素に変換するために使用すべきではありません。非インタラクティブなARIAロールには、article
、banner
、complementary
、img
、listitem
、main
、region
、tooltip
などがあります。
<!-- A11y: <textarea> cannot have role 'listitem' -->
<textarea role="listitem"></textarea>
a11y_no_noninteractive_element_interactions
Non-interactive element `<%element%>` should not be assigned mouse or keyboard event listeners
非インタラクティブな要素は、イベントハンドラ(マウスおよびキーハンドラ)をサポートしていません。非インタラクティブな要素には、<main>
、<area>
、<h1>
(、<h2>
など)、<p>
、<img>
、<li>
、<ul>
、<ol>
などがあります。非インタラクティブなWAI-ARIAロールには、article
、banner
、complementary
、img
、listitem
、main
、region
、tooltip
などがあります。
<!-- `A11y: Non-interactive element <li> should not be assigned mouse or keyboard event listeners.` -->
<li onclick={() => {}}></li>
<!-- `A11y: Non-interactive element <div> should not be assigned mouse or keyboard event listeners.` -->
<div role="listitem" onclick={() => {}}></div>
a11y_no_noninteractive_element_to_interactive_role
Non-interactive element `<%element%>` cannot have interactive role '%role%'
WAI-ARIAのロールは、非インタラクティブな要素をインタラクティブな要素に変換するために使用すべきではありません。インタラクティブなARIAロールには、button
、link
、checkbox
、menuitem
、menuitemcheckbox
、menuitemradio
、option
、radio
、searchbox
、switch
、textbox
などがあります。
<!-- A11y: Non-interactive element <h3> cannot have interactive role 'searchbox' -->
<h3 role="searchbox">Button</h3>
a11y_no_noninteractive_tabindex
noninteractive element cannot have nonnegative tabIndex value
Tabキーによるナビゲーションは、ページ上で操作可能な要素のみに限定する必要があります。
<!-- A11y: noninteractive element cannot have nonnegative tabIndex value -->
<div tabindex="0"></div>
a11y_no_redundant_roles
Redundant role '%role%'
一部のHTML要素には、デフォルトのARIAロールが設定されています。ブラウザによって既に設定されているARIAロールをこれらの要素に指定しても効果はなく、冗長です。
<!-- A11y: Redundant role 'button' -->
<button role="button">...</button>
<!-- A11y: Redundant role 'img' -->
<img role="img" src="foo.jpg" />
a11y_no_static_element_interactions
`<%element%>` with a %handler% handler must have an ARIA role
click
のようなインタラクティブなハンドラを持つ<div>
のような要素には、ARIAロールが必要です。
<!-- A11y: <div> with click handler must have an ARIA role -->
<div onclick={() => ''}></div>
a11y_positive_tabindex
Avoid tabindex values above zero
正のtabindex
プロパティ値は避けてください。これは、要素を想定されるタブ順序から外れさせ、キーボードユーザーにとって混乱を招く操作性となります。
<!-- A11y: avoid tabindex values above zero -->
<div tabindex="1"></div>
a11y_role_has_required_aria_props
Elements with the ARIA role "%role%" must have the following attributes defined: %props%
ARIAロールを持つ要素は、そのロールに必要なすべての属性を持っている必要があります。
<!-- A11y: A11y: Elements with the ARIA role "checkbox" must have the following attributes defined: "aria-checked" -->
<span role="checkbox" aria-labelledby="foo" tabindex="0"></span>
a11y_role_supports_aria_props
The attribute '%attribute%' is not supported by the role '%role%'
明示的または暗黙的に定義されたロールを持つ要素には、そのロールでサポートされているaria-*
プロパティのみが含まれています。
<!-- A11y: The attribute 'aria-multiline' is not supported by the role 'link'. -->
<div role="link" aria-multiline></div>
<!-- A11y: The attribute 'aria-required' is not supported by the role 'listitem'. This role is implicit on the element <li>. -->
<li aria-required></li>
a11y_role_supports_aria_props_implicit
The attribute '%attribute%' is not supported by the role '%role%'. This role is implicit on the element `<%name%>`
明示的または暗黙的に定義されたロールを持つ要素には、そのロールでサポートされているaria-*
プロパティのみが含まれています。
<!-- A11y: The attribute 'aria-multiline' is not supported by the role 'link'. -->
<div role="link" aria-multiline></div>
<!-- A11y: The attribute 'aria-required' is not supported by the role 'listitem'. This role is implicit on the element <li>. -->
<li aria-required></li>
a11y_unknown_aria_attribute
Unknown aria attribute 'aria-%attribute%'
Unknown aria attribute 'aria-%attribute%'. Did you mean '%suggestion%'?
既知のARIA属性のみが使用されるようにします。これは、WAI-ARIAの状態とプロパティの仕様に基づいています。
<!-- A11y: Unknown aria attribute 'aria-labeledby' (did you mean 'labelledby'?) -->
<input type="image" aria-labeledby="foo" />
a11y_unknown_role
Unknown role '%role%'
Unknown role '%role%'. Did you mean '%suggestion%'?
ARIAロールを持つ要素は、有効な、抽象的でないARIAロールを使用する必要があります。ロール定義のリファレンスは、WAI-ARIAサイトにあります。
<!-- A11y: Unknown role 'toooltip' (did you mean 'tooltip'?) -->
<div role="toooltip"></div>
attribute_avoid_is
The "is" attribute is not supported cross-browser and should be avoided
attribute_global_event_reference
You are referencing `globalThis.%name%`. Did you forget to declare a variable with that name?
attribute_illegal_colon
Attributes should not contain ':' characters to prevent ambiguity with Svelte directives
attribute_invalid_property_name
'%wrong%' is not a valid HTML attribute. Did you mean '%right%'?
attribute_quoted
Quoted attributes on components and custom elements will be stringified in a future version of Svelte. If this isn't what you want, remove the quotes
bind_invalid_each_rest
The rest operator (...) will create a new object and binding '%name%' with the original object will not work
block_empty
Empty block
component_name_lowercase
`<%name%>` will be treated as an HTML element unless it begins with a capital letter
css_unused_selector
Unused CSS selector "%name%"
element_invalid_self_closing_tag
Self-closing HTML tags for non-void elements are ambiguous — use `<%name% ...></%name%>` rather than `<%name% ... />`
event_directive_deprecated
Using `on:%name%` to listen to the %name% event is deprecated. Use the event attribute `on%name%` instead
export_let_unused
Component has unused export property '%name%'. If it is for external reference only, please consider using `export const %name%`
legacy_code
`%code%` is no longer valid — please use `%suggestion%` instead
legacy_component_creation
Svelte 5 components are no longer classes. Instantiate them using `mount` or `hydrate` (imported from 'svelte') instead.
node_invalid_placement_ssr
%message%. When rendering this component on the server, the resulting HTML will be modified by the browser (by moving, removing, or inserting elements), likely resulting in a `hydration_mismatch` warning
HTMLは、特定の要素が出現できる場所を制限しています。違反が発生した場合、ブラウザはHTMLを「修復」しますが、その方法はSvelteのコンポーネント構造に関する前提を覆すような方法で行われます。いくつかの例を以下に示します。
<p>hello <div>world</div></p>
は<p>hello </p><div>world</div><p></p>
という結果になります(<p>
はブロックレベル要素を含むことができないため、<div>
によって<p>
が自動的に閉じられました)。<option><div>option a</div></option>
は<option>option a</option>
という結果になります(<div>
は削除されます)。<table><tr><td>cell</td></tr></table>
は<table><tbody><tr><td>cell</td></tr></tbody></table>
という結果になります(<tbody>
が自動的に挿入されます)。
このコードは、コンポーネントがクライアントでレンダリングされる場合は動作しますが(そのため、これはエラーではなく警告です)、サーバーレンダリングを使用する場合は、ハイドレーションが失敗します。
non_reactive_update
`%name%` is updated, but is not declared with `$state(...)`. Changing its value will not correctly trigger updates
options_deprecated_accessors
The `accessors` option has been deprecated. It will have no effect in runes mode
options_deprecated_immutable
The `immutable` option has been deprecated. It will have no effect in runes mode
options_missing_custom_element
The `customElement` option is used when generating a custom element. Did you forget the `customElement: true` compile option?
options_removed_enable_sourcemap
The `enableSourcemap` option has been removed. Source maps are always generated now, and tooling can choose to ignore them
options_removed_hydratable
The `hydratable` option has been removed. Svelte components are always hydratable now
options_removed_loop_guard_timeout
The `loopGuardTimeout` option has been removed
options_renamed_ssr_dom
`generate: "dom"` and `generate: "ssr"` options have been renamed to "client" and "server" respectively
perf_avoid_inline_class
Avoid 'new class' — instead, declare the class at the top level scope
perf_avoid_nested_class
Avoid declaring classes below the top level scope
reactive_declaration_invalid_placement
Reactive declarations only exist at the top level of the instance script
reactive_declaration_module_script_dependency
Reassignments of module-level declarations will not cause reactive statements to update
script_context_deprecated
`context="module"` is deprecated, use the `module` attribute instead
script_unknown_attribute
Unrecognized attribute — should be one of `generics`, `lang` or `module`. If this exists for a preprocessor, ensure that the preprocessor removes it
slot_element_deprecated
Using `<slot>` to render parent content is deprecated. Use `{@render ...}` tags instead
state_referenced_locally
State referenced in its own scope will never update. Did you mean to reference it inside a closure?
store_rune_conflict
It looks like you're using the `$%name%` rune, but there is a local binding called `%name%`. Referencing a local variable with a `$` prefix will create a store subscription. Please rename `%name%` to avoid the ambiguity
svelte_component_deprecated
`<svelte:component>` is deprecated in runes mode — components are dynamic by default
以前のバージョンのSvelteでは、コンポーネントコンストラクタはコンポーネントのレンダリング時に固定されていました。つまり、X
が変更されたときに <X>
を再レンダリングしたい場合は、<svelte:component this={X}>
を使用するか、コンポーネントを {#key X}...{/key}
ブロック内に配置する必要がありました。
Svelte 5 では、これはもはや当てはまりません。X
が変更されると、<X>
は再レンダリングされます。
場合によっては、<object.property>
構文を代替として使用できます。プロパティアクセスを持つ小文字の変数は、Svelte 5 ではコンポーネントとして認識されます。
複雑なコンポーネント解決ロジックの場合は、中間の大文字変数が必要になる場合があります。たとえば、@const
を使用できる場所などです。
{#each items as item}
<svelte:component this={item.condition ? Y : Z} />
{@const Component = item.condition ? Y : Z}
<Component />
{/each}
派生値は他のコンテキストで使用できます。
<script>
// ...
let condition = $state(false);
const Component = $derived(condition ? Y : Z);
</script>
<svelte:component this={condition ? Y : Z} />
<Component />
svelte_element_invalid_this
`this` should be an `{expression}`. Using a string attribute value will cause an error in future versions of Svelte
svelte_self_deprecated
`<svelte:self>` is deprecated — use self-imports (e.g. `import %name% from './%basename%'`) instead
unknown_code
`%code%` is not a recognised code
`%code%` is not a recognised code (did you mean `%suggestion%`?)