From 25a48be0efb482f74f6b9643a312256f31dc601f Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sun, 27 Jun 2021 00:09:00 +0800 Subject: [PATCH 01/14] update docs for style tag in elements (#6415) --- site/content/docs/01-component-format.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/site/content/docs/01-component-format.md b/site/content/docs/01-component-format.md index 09451701a0..c51b56fcf9 100644 --- a/site/content/docs/01-component-format.md +++ b/site/content/docs/01-component-format.md @@ -291,3 +291,23 @@ The `-global-` part will be removed when compiled, and the keyframe then be refe @keyframes -global-my-animation-name {...} ``` + +--- + +There should only be 1 top-level ` + +``` \ No newline at end of file From 142de015eb02e0799bdd48eead5c066d951872fe Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sun, 27 Jun 2021 00:09:40 +0800 Subject: [PATCH 02/14] add accessibility warnings to the docs (#5316) --- .../content/docs/05-accessibility-warnings.md | 255 ++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100644 site/content/docs/05-accessibility-warnings.md diff --git a/site/content/docs/05-accessibility-warnings.md b/site/content/docs/05-accessibility-warnings.md new file mode 100644 index 0000000000..3151ef259d --- /dev/null +++ b/site/content/docs/05-accessibility-warnings.md @@ -0,0 +1,255 @@ +--- +title: Accessibility warnings +--- + +Accessibility (shortened to a11y) isn't always easy to get right, but Svelte will help by warning you if you write inaccessible markup. + +Here is a list of accessibility checks Svelte will do it for you. + +--- + +### `a11y-accesskey` + +Enforce no `accesskey` on element. Access keys are HTML attributes that allow web developers to assign keyboard shortcuts to elements. Inconsistencies between keyboard shortcuts and keyboard commands used by screenreader and keyboard only users create accessibility complications so to avoid complications, access keys should not be used. + +```sv + +
+``` + +--- + +### `a11y-aria-attributes` + +Certain reserved DOM elements do not support ARIA roles, states and properties. This is often because they are not visible, for example `meta`, `html`, `script`, `style`. This rule enforces that these DOM elements do not contain the `aria-*` props. + +```sv + + +``` + +--- + +### `a11y-autofocus` + +Enforce that `autofocus` is not used on elements. Autofocusing elements can cause usability issues for sighted and non-sighted users, alike. + +```sv + + +``` + +--- + +### `a11y-distracting-elements` + +Enforces that no distracting elements are used. Elements that can be visually distracting can cause accessibility issues with visually impaired users. Such elements are most likely deprecated, and should be avoided. + +The following elements are visually distracting: `` and ``. + +```sv + + +``` + +--- + +### `a11y-hidden` + +Certain DOM elements are useful for screen readers navigation and should not be hidden. + +```sv + +

invisible header

+``` + +--- + +### `a11y-img-redundant-alt` + +Enforce img alt attribute does not contain the word image, picture, or photo. Screenreaders already announce `img` elements as an image. There is no need to use words such as _image_, _photo_, and/or _picture_. + +```sv +Foo eating a sandwich. + + +Picture of me taking a photo of an image + + +Photo of foo being weird. + + +Image of me at a bar! + + +Picture of baz fixing a bug. +``` + +--- + +### `a11y-invalid-attribute` + +Enforce that accessibility attribute should have valid value + +```sv + +invalid +``` + +--- + +### `a11y-label-has-associated-control` + +Enforce that a label tag has a text label and an associated control. + +There are two supported ways to associate a label with a control: + +- Wrapping a control in a label tag. +- Adding `for` to a label and assigning it a DOM ID string that indicates an input on the page. + +```sv + + + + + + +``` + +--- + +### `a11y-media-has-caption` + +Providing captions for media is essential for deaf users to follow along. Captions should be a transcription or translation of the dialogue, sound effects, relevant musical cues, and other relevant audio information. Not only is this important for accessibility, but can also be useful for all users in the case that the media is unavailable (similar to `alt` text on an image when an image is unable to load). + +The captions should contain all important and relevant information to understand the corresponding media. This may mean that the captions are not a 1:1 mapping of the dialogue in the media content. However, captions are not necessary for video components with the `muted` attribute. + +```sv + + + + + + + + + +``` + +--- + +### `a11y-misplaced-role` + +Certain reserved DOM elements do not support ARIA roles, states and properties. This is often because they are not visible, for example `meta`, `html`, `script`, `style`. This rule enforces that these DOM elements do not contain the `role` props. + +```sv + + +``` + +--- + +### `a11y-misplaced-scope` + +The scope scope should be used only on `` elements. + +```sv + +
+``` + +--- + +### `a11y-missing-attribute` + +Enforce that element should have required accessibility attribute + +```sv + + + + + + + +text +``` + +--- + +### `a11y-missing-content` + +Enforce that heading elements (`h1`, `h2`, etc.) and anchors have content and that the content is accessible to screen readers + +```sv + + + + +

+``` + +--- + +### `a11y-no-onchange` + +Enforce usage of `on:blur` over/in parallel with `on:change` on select menu elements for accessibility. `on:blur` should be used instead of `on:change`, unless absolutely necessary and it causes no negative consequences for keyboard only or screen reader users. `on:blur` is a more declarative action by the user: for instance in a dropdown, using the arrow keys to toggle between options will trigger the `on:change` event in some browsers. Regardless, when a change of context results from an `on:blur` event or an `on:change` event, the user should be notified of the change unless it occurs below the currently focused element. + +```sv + + + + +``` + +--- + +### `a11y-positive-tabindex` + +Avoid positive `tabIndex` property values to synchronize the flow of the page with keyboard tab order. + +```sv + +
+``` + +--- + +### `a11y-structure` + +Warns when accessibility related elements are not in a right structure. + +```sv + +
+
Image caption
+
+``` + +--- + +### `a11y-unknown-aria-attribute` + +Invalid aria attribute. Enforces valid `aria-*` property based on [WAI-ARIA States and Properties spec](https://www.w3.org/WAI/PF/aria-1.1/states_and_properties) + +```sv + + +``` + +--- + +### `a11y-unknown-role` + +Elements with ARIA roles must use a valid, non-abstract ARIA role. A reference to role definitions can be found at [WAI-ARIA](https://www.w3.org/TR/wai-aria/#role_definitions) site. + +```sv + +
+``` From 7bf3f20dc328d0d59190e3f0a4c6793d2a8d025c Mon Sep 17 00:00:00 2001 From: Geoff Rich Date: Sat, 26 Jun 2021 09:56:10 -0700 Subject: [PATCH 03/14] Add docs for compound :global selector (#6271) * Add docs for compound :global selector Co-authored-by: Antony Jones --- site/content/docs/01-component-format.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/site/content/docs/01-component-format.md b/site/content/docs/01-component-format.md index c51b56fcf9..30c53b225f 100644 --- a/site/content/docs/01-component-format.md +++ b/site/content/docs/01-component-format.md @@ -277,6 +277,15 @@ To apply styles to a selector globally, use the `:global(...)` modifier. to this component */ color: goldenrod; } + + p:global(.red) { + /* this will apply to all

elements belonging to this + component with a class of red, even if class="red" does + not initially appear in the markup, and is instead + added at runtime. This is useful when the class + of the element is dynamically applied, for instance + when updating the element's classList property directly. */ + } ``` From 46fac828f72b2a75afb858cc0b6eeb87e0c4b007 Mon Sep 17 00:00:00 2001 From: Ava Johnson Date: Sat, 26 Jun 2021 09:59:27 -0700 Subject: [PATCH 04/14] Bubble svelte dev events (#5994) --- src/runtime/internal/dev.ts | 2 +- src/runtime/internal/dom.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runtime/internal/dev.ts b/src/runtime/internal/dev.ts index 8a7415d872..4e4e5326f9 100644 --- a/src/runtime/internal/dev.ts +++ b/src/runtime/internal/dev.ts @@ -2,7 +2,7 @@ import { custom_event, append, insert, detach, listen, attr } from './dom'; import { SvelteComponent } from './Component'; export function dispatch_dev(type: string, detail?: T) { - document.dispatchEvent(custom_event(type, { version: '__VERSION__', ...detail })); + document.dispatchEvent(custom_event(type, { version: '__VERSION__', ...detail }, true)); } export function append_dev(target: Node, node: Node) { diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 32756ed9a5..bdc5538941 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -521,9 +521,9 @@ export function toggle_class(element, name, toggle) { element.classList[toggle ? 'add' : 'remove'](name); } -export function custom_event(type: string, detail?: T) { +export function custom_event(type: string, detail?: T, bubbles: boolean = false) { const e: CustomEvent = document.createEvent('CustomEvent'); - e.initCustomEvent(type, false, false, detail); + e.initCustomEvent(type, bubbles, false, detail); return e; } From 4b4717b3518218397816ec22d891650d54aec43c Mon Sep 17 00:00:00 2001 From: Aswin Vayiravan Date: Sat, 26 Jun 2021 13:55:35 -0400 Subject: [PATCH 05/14] Reorder text area and output to improve visibility (#5790) --- .../06-bindings/05-textarea-inputs/app-a/App.svelte | 6 +++--- .../06-bindings/05-textarea-inputs/app-b/App.svelte | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/site/content/tutorial/06-bindings/05-textarea-inputs/app-a/App.svelte b/site/content/tutorial/06-bindings/05-textarea-inputs/app-a/App.svelte index 12ac68880c..b126fb4c84 100644 --- a/site/content/tutorial/06-bindings/05-textarea-inputs/app-a/App.svelte +++ b/site/content/tutorial/06-bindings/05-textarea-inputs/app-a/App.svelte @@ -3,10 +3,10 @@ let value = `Some words are *italic*, some are **bold**`; - - {@html marked(value)} + + \ No newline at end of file + diff --git a/site/content/tutorial/06-bindings/05-textarea-inputs/app-b/App.svelte b/site/content/tutorial/06-bindings/05-textarea-inputs/app-b/App.svelte index 7775ab6319..f9521d6db6 100644 --- a/site/content/tutorial/06-bindings/05-textarea-inputs/app-b/App.svelte +++ b/site/content/tutorial/06-bindings/05-textarea-inputs/app-b/App.svelte @@ -3,10 +3,10 @@ let value = `Some words are *italic*, some are **bold**`; - - {@html marked(value)} + + \ No newline at end of file + From 0f92863033316c8a87c02b775fffe78ccddd3292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20=C4=90=E1=BB=A9c=20H=C3=A0o?= <39975444+haond10adp@users.noreply.github.com> Date: Sun, 27 Jun 2021 00:57:48 +0700 Subject: [PATCH 06/14] tutorial: add name attribute to inputs (#5649) --- .../06-bindings/04-group-inputs/app-a/App.svelte | 12 ++++++------ .../06-bindings/04-group-inputs/app-b/App.svelte | 8 ++++---- .../tutorial/06-bindings/04-group-inputs/text.md | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/site/content/tutorial/06-bindings/04-group-inputs/app-a/App.svelte b/site/content/tutorial/06-bindings/04-group-inputs/app-a/App.svelte index 038790bc51..3a29f89484 100644 --- a/site/content/tutorial/06-bindings/04-group-inputs/app-a/App.svelte +++ b/site/content/tutorial/06-bindings/04-group-inputs/app-a/App.svelte @@ -11,34 +11,34 @@

Size

Flavours

diff --git a/site/content/tutorial/06-bindings/04-group-inputs/app-b/App.svelte b/site/content/tutorial/06-bindings/04-group-inputs/app-b/App.svelte index b12704b87d..d97db41f0b 100644 --- a/site/content/tutorial/06-bindings/04-group-inputs/app-b/App.svelte +++ b/site/content/tutorial/06-bindings/04-group-inputs/app-b/App.svelte @@ -17,17 +17,17 @@

Size

@@ -35,7 +35,7 @@ {#each menu as flavour} {/each} diff --git a/site/content/tutorial/06-bindings/04-group-inputs/text.md b/site/content/tutorial/06-bindings/04-group-inputs/text.md index 97edb8db76..b48b23921f 100644 --- a/site/content/tutorial/06-bindings/04-group-inputs/text.md +++ b/site/content/tutorial/06-bindings/04-group-inputs/text.md @@ -7,7 +7,7 @@ If you have multiple inputs relating to the same value, you can use `bind:group` Add `bind:group` to each input: ```html - + ``` In this case, we could make the code simpler by moving the checkbox inputs into an `each` block. First, add a `menu` variable to the ` + + diff --git a/site/content/tutorial/06-bindings/14-component-this/app-a/InputField.svelte b/site/content/tutorial/06-bindings/14-component-this/app-a/InputField.svelte new file mode 100644 index 0000000000..e2b04b93ed --- /dev/null +++ b/site/content/tutorial/06-bindings/14-component-this/app-a/InputField.svelte @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/06-bindings/14-component-this/app-b/App.svelte b/site/content/tutorial/06-bindings/14-component-this/app-b/App.svelte new file mode 100644 index 0000000000..f14332b398 --- /dev/null +++ b/site/content/tutorial/06-bindings/14-component-this/app-b/App.svelte @@ -0,0 +1,9 @@ + + + + + diff --git a/site/content/tutorial/06-bindings/14-component-this/app-b/InputField.svelte b/site/content/tutorial/06-bindings/14-component-this/app-b/InputField.svelte new file mode 100644 index 0000000000..e2b04b93ed --- /dev/null +++ b/site/content/tutorial/06-bindings/14-component-this/app-b/InputField.svelte @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/06-bindings/14-component-this/text.md b/site/content/tutorial/06-bindings/14-component-this/text.md new file mode 100644 index 0000000000..00af193604 --- /dev/null +++ b/site/content/tutorial/06-bindings/14-component-this/text.md @@ -0,0 +1,19 @@ +--- +title: Binding to component instances +--- + +Just as you can bind to DOM elements, you can bind to component instances themselves. For example, we can bind the instance of `` to a prop named `field` in the same way we did when binding DOM Elements + +```html + +``` + +Now we can programmatically interact with this component using `field`. + +```html + +``` + +> Note that we can't do `{field.focus}` since field is undefined when the button is first rendered and throws an error. \ No newline at end of file From f99deeb67b89687b4daf94416ceac7747f3eab7f Mon Sep 17 00:00:00 2001 From: Simon Scharf Date: Sat, 26 Jun 2021 20:18:09 +0200 Subject: [PATCH 09/14] docs: remove type property from special elements tutorial (#4715) Instead, determine type based on the existence of the files property. Removes console warnings --- .../01-svelte-self/app-a/App.svelte | 24 ++++++++----------- .../01-svelte-self/app-a/Folder.svelte | 4 ++-- .../01-svelte-self/app-b/App.svelte | 24 ++++++++----------- .../01-svelte-self/app-b/Folder.svelte | 4 ++-- .../01-svelte-self/text.md | 4 ++-- 5 files changed, 26 insertions(+), 34 deletions(-) diff --git a/site/content/tutorial/16-special-elements/01-svelte-self/app-a/App.svelte b/site/content/tutorial/16-special-elements/01-svelte-self/app-a/App.svelte index ff02fa6a42..de0b2e0179 100644 --- a/site/content/tutorial/16-special-elements/01-svelte-self/app-a/App.svelte +++ b/site/content/tutorial/16-special-elements/01-svelte-self/app-a/App.svelte @@ -3,39 +3,35 @@ let root = [ { - type: 'folder', name: 'Important work stuff', files: [ - { type: 'file', name: 'quarterly-results.xlsx' } + { name: 'quarterly-results.xlsx' } ] }, { - type: 'folder', name: 'Animal GIFs', files: [ { - type: 'folder', name: 'Dogs', files: [ - { type: 'file', name: 'treadmill.gif' }, - { type: 'file', name: 'rope-jumping.gif' } + { name: 'treadmill.gif' }, + { name: 'rope-jumping.gif' } ] }, { - type: 'folder', name: 'Goats', files: [ - { type: 'file', name: 'parkour.gif' }, - { type: 'file', name: 'rampage.gif' } + { name: 'parkour.gif' }, + { name: 'rampage.gif' } ] }, - { type: 'file', name: 'cat-roomba.gif' }, - { type: 'file', name: 'duck-shuffle.gif' }, - { type: 'file', name: 'monkey-on-a-pig.gif' } + { name: 'cat-roomba.gif' }, + { name: 'duck-shuffle.gif' }, + { name: 'monkey-on-a-pig.gif' } ] }, - { type: 'file', name: 'TODO.md' } + { name: 'TODO.md' } ]; - \ No newline at end of file + diff --git a/site/content/tutorial/16-special-elements/01-svelte-self/app-a/Folder.svelte b/site/content/tutorial/16-special-elements/01-svelte-self/app-a/Folder.svelte index 20096e805e..1108b3575c 100644 --- a/site/content/tutorial/16-special-elements/01-svelte-self/app-a/Folder.svelte +++ b/site/content/tutorial/16-special-elements/01-svelte-self/app-a/Folder.svelte @@ -16,7 +16,7 @@
    {#each files as file}
  • - {#if file.type === 'folder'} + {#if file.files} {:else} @@ -49,4 +49,4 @@ li { padding: 0.2em 0; } - \ No newline at end of file + diff --git a/site/content/tutorial/16-special-elements/01-svelte-self/app-b/App.svelte b/site/content/tutorial/16-special-elements/01-svelte-self/app-b/App.svelte index ff02fa6a42..de0b2e0179 100644 --- a/site/content/tutorial/16-special-elements/01-svelte-self/app-b/App.svelte +++ b/site/content/tutorial/16-special-elements/01-svelte-self/app-b/App.svelte @@ -3,39 +3,35 @@ let root = [ { - type: 'folder', name: 'Important work stuff', files: [ - { type: 'file', name: 'quarterly-results.xlsx' } + { name: 'quarterly-results.xlsx' } ] }, { - type: 'folder', name: 'Animal GIFs', files: [ { - type: 'folder', name: 'Dogs', files: [ - { type: 'file', name: 'treadmill.gif' }, - { type: 'file', name: 'rope-jumping.gif' } + { name: 'treadmill.gif' }, + { name: 'rope-jumping.gif' } ] }, { - type: 'folder', name: 'Goats', files: [ - { type: 'file', name: 'parkour.gif' }, - { type: 'file', name: 'rampage.gif' } + { name: 'parkour.gif' }, + { name: 'rampage.gif' } ] }, - { type: 'file', name: 'cat-roomba.gif' }, - { type: 'file', name: 'duck-shuffle.gif' }, - { type: 'file', name: 'monkey-on-a-pig.gif' } + { name: 'cat-roomba.gif' }, + { name: 'duck-shuffle.gif' }, + { name: 'monkey-on-a-pig.gif' } ] }, - { type: 'file', name: 'TODO.md' } + { name: 'TODO.md' } ]; - \ No newline at end of file + diff --git a/site/content/tutorial/16-special-elements/01-svelte-self/app-b/Folder.svelte b/site/content/tutorial/16-special-elements/01-svelte-self/app-b/Folder.svelte index f5f0a7b194..11049c2e52 100644 --- a/site/content/tutorial/16-special-elements/01-svelte-self/app-b/Folder.svelte +++ b/site/content/tutorial/16-special-elements/01-svelte-self/app-b/Folder.svelte @@ -16,7 +16,7 @@
      {#each files as file}
    • - {#if file.type === 'folder'} + {#if file.files} {:else} @@ -49,4 +49,4 @@ li { padding: 0.2em 0; } - \ No newline at end of file + diff --git a/site/content/tutorial/16-special-elements/01-svelte-self/text.md b/site/content/tutorial/16-special-elements/01-svelte-self/text.md index c7946f6c6d..894a8efc3d 100644 --- a/site/content/tutorial/16-special-elements/01-svelte-self/text.md +++ b/site/content/tutorial/16-special-elements/01-svelte-self/text.md @@ -7,7 +7,7 @@ Svelte provides a variety of built-in elements. The first, ``, allo It's useful for things like this folder tree view, where folders can contain *other* folders. In `Folder.svelte` we want to be able to do this... ```html -{#if file.type === 'folder'} +{#if file.files} {:else} @@ -17,7 +17,7 @@ It's useful for things like this folder tree view, where folders can contain *ot ...but that's impossible, because a module can't import itself. Instead, we use ``: ```html -{#if file.type === 'folder'} +{#if file.files} {:else} From 7115601cd39f7b1916ef99babad66ee11a6ba4cf Mon Sep 17 00:00:00 2001 From: The Jared Wilcurt Date: Sat, 26 Jun 2021 14:23:30 -0400 Subject: [PATCH 10/14] Docs: Accurately name function (#4060) --- .../01-reactive-assignments/app-b/App.svelte | 6 +++--- .../02-reactivity/01-reactive-assignments/text.md | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/site/content/tutorial/02-reactivity/01-reactive-assignments/app-b/App.svelte b/site/content/tutorial/02-reactivity/01-reactive-assignments/app-b/App.svelte index bc50d74cfc..dff5942d6e 100644 --- a/site/content/tutorial/02-reactivity/01-reactive-assignments/app-b/App.svelte +++ b/site/content/tutorial/02-reactivity/01-reactive-assignments/app-b/App.svelte @@ -1,11 +1,11 @@ - \ No newline at end of file + diff --git a/site/content/tutorial/02-reactivity/01-reactive-assignments/text.md b/site/content/tutorial/02-reactivity/01-reactive-assignments/text.md index b0909f1feb..15b58f0820 100644 --- a/site/content/tutorial/02-reactivity/01-reactive-assignments/text.md +++ b/site/content/tutorial/02-reactivity/01-reactive-assignments/text.md @@ -7,15 +7,15 @@ At the heart of Svelte is a powerful system of *reactivity* for keeping the DOM To demonstrate it, we first need to wire up an event handler. Replace line 9 with this: ```html - +

      + The Timer component has been open for + {seconds} {seconds === 1 ? 'second' : 'seconds'} +

      + {#if open} + + {/if} +
diff --git a/site/content/tutorial/07-lifecycle/02-ondestroy/app-a/Timer.svelte b/site/content/tutorial/07-lifecycle/02-ondestroy/app-a/Timer.svelte new file mode 100644 index 0000000000..0eb5a7461d --- /dev/null +++ b/site/content/tutorial/07-lifecycle/02-ondestroy/app-a/Timer.svelte @@ -0,0 +1,20 @@ + + +

+ This component executes a callback every + {interval} millisecond{interval === 1 ? '' : 's'} +

+ + diff --git a/site/content/tutorial/07-lifecycle/02-ondestroy/app-a/utils.js b/site/content/tutorial/07-lifecycle/02-ondestroy/app-a/utils.js index 7b65e75c8c..64ab7e50c7 100644 --- a/site/content/tutorial/07-lifecycle/02-ondestroy/app-a/utils.js +++ b/site/content/tutorial/07-lifecycle/02-ondestroy/app-a/utils.js @@ -1,5 +1,9 @@ import { onDestroy } from 'svelte'; export function onInterval(callback, milliseconds) { - // implementation goes here + const interval = setInterval(callback, milliseconds); + + onDestroy(() => { + // Fix the memory leak here + }); } \ No newline at end of file diff --git a/site/content/tutorial/07-lifecycle/02-ondestroy/app-b/App.svelte b/site/content/tutorial/07-lifecycle/02-ondestroy/app-b/App.svelte index 93a721ef44..49936b6617 100644 --- a/site/content/tutorial/07-lifecycle/02-ondestroy/app-b/App.svelte +++ b/site/content/tutorial/07-lifecycle/02-ondestroy/app-b/App.svelte @@ -1,11 +1,20 @@ -

- The page has been open for - {seconds} {seconds === 1 ? 'second' : 'seconds'} -

\ No newline at end of file +
+ +

+ The Timer component has been open for + {seconds} {seconds === 1 ? 'second' : 'seconds'} +

+ {#if open} + + {/if} +
diff --git a/site/content/tutorial/07-lifecycle/02-ondestroy/app-b/Timer.svelte b/site/content/tutorial/07-lifecycle/02-ondestroy/app-b/Timer.svelte new file mode 100644 index 0000000000..0eb5a7461d --- /dev/null +++ b/site/content/tutorial/07-lifecycle/02-ondestroy/app-b/Timer.svelte @@ -0,0 +1,20 @@ + + +

+ This component executes a callback every + {interval} millisecond{interval === 1 ? '' : 's'} +

+ + diff --git a/site/content/tutorial/07-lifecycle/02-ondestroy/text.md b/site/content/tutorial/07-lifecycle/02-ondestroy/text.md index 647fbaa160..34bbf83cbf 100644 --- a/site/content/tutorial/07-lifecycle/02-ondestroy/text.md +++ b/site/content/tutorial/07-lifecycle/02-ondestroy/text.md @@ -10,8 +10,8 @@ For example, we can add a `setInterval` function when our component initialises, @@ -37,7 +37,9 @@ export function onInterval(callback, milliseconds) { -``` \ No newline at end of file +``` + +Open and close the timer a few times and make sure the counter keeps ticking and the CPU load increases. This is due to a memory leak as the previous timers are not deleted. Don't forget to refresh the page before solving the example. \ No newline at end of file