From c73b9a00ea64bcf2565bc224fd6e3afc760cc0fc Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 22 Dec 2022 13:08:06 +0100 Subject: [PATCH 01/61] [fix] add submitter property to submit event --- elements/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/index.d.ts b/elements/index.d.ts index 2534bfaf40..4668d190f9 100644 --- a/elements/index.d.ts +++ b/elements/index.d.ts @@ -84,7 +84,7 @@ export interface DOMAttributes { 'on:beforeinput'?: EventHandler | undefined | null; 'on:input'?: FormEventHandler | undefined | null; 'on:reset'?: FormEventHandler | undefined | null; - 'on:submit'?: EventHandler | undefined | null; // TODO make this SubmitEvent once we require TS>=4.4 + 'on:submit'?: EventHandler | undefined | null; // TODO make this SubmitEvent once we require TS>=4.4 'on:invalid'?: EventHandler | undefined | null; 'on:formdata'?: EventHandler | undefined | null; // TODO make this FormDataEvent once we require TS>=4.4 From 786505d6bc52ce9ad072f1c44cacfeb4f3bd58ab Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 22 Dec 2022 13:13:31 +0100 Subject: [PATCH 02/61] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 190caaf6e1..fd4ff5f7ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Svelte changelog +## 3.55.1 (unreleased) + +* add missing `submitter` property to `on:submit` event type + ## 3.55.0 * Add `svelte/elements` for HTML/Svelte typings ([#7649](https://github.com/sveltejs/svelte/pull/7649)) From b8f32c0b1a295fd56c7c04683402968f32f01597 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 22 Dec 2022 17:47:52 +0100 Subject: [PATCH 03/61] [docs] clear timeout on destroy backported from https://github.com/sveltejs/learn.svelte.dev/pull/166 --- .../02-adding-parameters-to-actions/app-a/longpress.js | 1 + .../02-adding-parameters-to-actions/app-b/longpress.js | 1 + 2 files changed, 2 insertions(+) diff --git a/site/content/tutorial/12-actions/02-adding-parameters-to-actions/app-a/longpress.js b/site/content/tutorial/12-actions/02-adding-parameters-to-actions/app-a/longpress.js index 00bb9d05c8..07235f21dc 100644 --- a/site/content/tutorial/12-actions/02-adding-parameters-to-actions/app-a/longpress.js +++ b/site/content/tutorial/12-actions/02-adding-parameters-to-actions/app-a/longpress.js @@ -18,6 +18,7 @@ export function longpress(node, duration) { return { destroy() { + clearTimeout(timer); node.removeEventListener('mousedown', handleMousedown); node.removeEventListener('mouseup', handleMouseup); } diff --git a/site/content/tutorial/12-actions/02-adding-parameters-to-actions/app-b/longpress.js b/site/content/tutorial/12-actions/02-adding-parameters-to-actions/app-b/longpress.js index 9d807cb13a..4ce0dfe05b 100644 --- a/site/content/tutorial/12-actions/02-adding-parameters-to-actions/app-b/longpress.js +++ b/site/content/tutorial/12-actions/02-adding-parameters-to-actions/app-b/longpress.js @@ -21,6 +21,7 @@ export function longpress(node, duration) { duration = newDuration; }, destroy() { + clearTimeout(timer); node.removeEventListener('mousedown', handleMousedown); node.removeEventListener('mouseup', handleMouseup); } From de6821a1de6574b1aa987944fe9a5f0b5f7724bb Mon Sep 17 00:00:00 2001 From: Yuichiro Yamashita Date: Sat, 31 Dec 2022 10:13:52 +0900 Subject: [PATCH 04/61] [ chore] disable puppeteer on Linux for Node8 and 10 (#8155) --- .github/workflows/ci.yml | 10 ++++++++++ test/custom-elements/index.ts | 3 +++ test/runtime-puppeteer/index.ts | 3 +++ 3 files changed, 16 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd826cafca..e24f106477 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,6 +59,16 @@ jobs: id: download-artifact with: name: build-assets + - name: Get Node version ${{ runner.os }} + run: echo "NODE_VERSION=`node --version`" >> $GITHUB_ENV + if: runner.os != 'Windows' + - name: Get Node version ${{ runner.os }} + run: | + chcp 65001 + echo ("NODE_VERSION=$(node --version)") >> $env:GITHUB_ENV + if: runner.os == 'Windows' + - run: npm install --save-dev puppeteer@13 + if: ${{ runner.os == 'Linux' && (!startsWith(env.NODE_VERSION, 'v8.') && !startsWith(env.NODE_VERSION, 'v10.')) }} - run: npm install env: SKIP_PREPARE: true diff --git a/test/custom-elements/index.ts b/test/custom-elements/index.ts index 42b27eebd3..534199d035 100644 --- a/test/custom-elements/index.ts +++ b/test/custom-elements/index.ts @@ -64,6 +64,9 @@ describe('custom-elements', function() { fs.readdirSync(`${__dirname}/samples`).forEach(dir => { if (dir[0] === '.') return; + // MEMO: puppeteer can not execute Chromium properly with Node8,10 on Linux at GitHub actions. + const { version } = process; + if ((version.startsWith('v8.') || version.startsWith('v10.')) && process.platform === 'linux') return; const solo = /\.solo$/.test(dir); const skip = /\.skip$/.test(dir); diff --git a/test/runtime-puppeteer/index.ts b/test/runtime-puppeteer/index.ts index 62952ad9f7..eba60544f6 100644 --- a/test/runtime-puppeteer/index.ts +++ b/test/runtime-puppeteer/index.ts @@ -77,6 +77,9 @@ describe('runtime (puppeteer)', function() { function runTest(dir, hydrate) { if (dir[0] === '.') return; + // MEMO: puppeteer can not execute Chromium properly with Node8,10 on Linux at GitHub actions. + const { version } = process; + if ((version.startsWith('v8.') || version.startsWith('v10.')) && process.platform === 'linux') return; const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`); const solo = config.solo || /\.solo/.test(dir); From f84c00edb9aab75c939963332da57af0e82894f3 Mon Sep 17 00:00:00 2001 From: Ramon Snir Date: Sun, 1 Jan 2023 03:41:00 -0500 Subject: [PATCH 05/61] [fix] static svelte:element not replaced with tag in production mode (#7938) * [fix] static svelte:element not replaced with tag in production mode * [fix] static svelte:element not replaced with tag in production mode * add optimization of static and fix a bug Co-authored-by: Yuichiro Yamashita --- src/compiler/compile/nodes/Element.ts | 1 + .../render_dom/wrappers/Element/index.ts | 11 +++++---- .../js/samples/svelte-element-svg/expected.js | 23 +++++++++++-------- .../samples/svelte-element-svg/input.svelte | 10 +++++--- .../samples/static-svelte-element/_config.js | 13 +++++++++++ .../samples/static-svelte-element/main.svelte | 3 +++ .../samples/static-svelte-element2/_config.js | 13 +++++++++++ .../static-svelte-element2/main.svelte | 7 ++++++ 8 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 test/runtime/samples/static-svelte-element/_config.js create mode 100644 test/runtime/samples/static-svelte-element/main.svelte create mode 100644 test/runtime/samples/static-svelte-element2/_config.js create mode 100644 test/runtime/samples/static-svelte-element2/main.svelte diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index a499d013e3..06ef1ba9c1 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -239,6 +239,7 @@ export default class Element extends Node { this.tag_expr = new Expression(component, this, scope, info.tag); } else { this.tag_expr = new Expression(component, this, scope, string_literal(info.tag) as Literal); + this.name = info.tag; } } else { this.tag_expr = new Expression(component, this, scope, string_literal(this.name) as Literal); diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts index 8d0429879e..cef758b89e 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts @@ -255,6 +255,7 @@ export default class ElementWrapper extends Wrapper { node.styles.length > 0 || this.node.name === 'option' || node.tag_expr.dynamic_dependencies().length || + node.is_dynamic_element || renderer.options.dev ) { this.parent.cannot_use_innerhtml(); // need to use add_location @@ -1176,10 +1177,12 @@ function to_html(wrappers: Array { if (is_empty_textarea && attr.node.name === 'value') { @@ -1196,7 +1199,7 @@ function to_html(wrappers: Array`. // see https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element const first = wrapper.fragment.nodes[0]; @@ -1221,7 +1224,7 @@ function to_html(wrappers: Array, block, literal, state); - state.quasi.value.raw += ``; + state.quasi.value.raw += ``; } else { state.quasi.value.raw += '/>'; } diff --git a/test/js/samples/svelte-element-svg/expected.js b/test/js/samples/svelte-element-svg/expected.js index 36ce583ef1..263f6c842b 100644 --- a/test/js/samples/svelte-element-svg/expected.js +++ b/test/js/samples/svelte-element-svg/expected.js @@ -18,7 +18,7 @@ function create_dynamic_element_1(ctx) { return { c: noop, m: noop, p: noop, d: noop }; } -// (1:0) +// (5:0) function create_dynamic_element(ctx) { let svelte_element1; let svelte_element0; @@ -38,8 +38,8 @@ function create_dynamic_element(ctx) { return { c() { - svelte_element1 = svg_element("svg"); - svelte_element0 = svg_element("path"); + svelte_element1 = svg_element(/*tag*/ ctx[0].svg); + svelte_element0 = svg_element(/*tag*/ ctx[0].path); set_svg_attributes(svelte_element0, svelte_element0_data); set_svg_attributes(svelte_element1, svelte_element1_data); }, @@ -60,9 +60,9 @@ function create_dynamic_element(ctx) { } function create_fragment(ctx) { - let previous_tag = "svg"; + let previous_tag = /*tag*/ ctx[0].svg; let svelte_element1_anchor; - let svelte_element1 = "svg" && create_dynamic_element(ctx); + let svelte_element1 = /*tag*/ ctx[0].svg && create_dynamic_element(ctx); return { c() { @@ -74,12 +74,12 @@ function create_fragment(ctx) { insert(target, svelte_element1_anchor, anchor); }, p(ctx, [dirty]) { - if ("svg") { + if (/*tag*/ ctx[0].svg) { if (!previous_tag) { svelte_element1 = create_dynamic_element(ctx); svelte_element1.c(); svelte_element1.m(svelte_element1_anchor.parentNode, svelte_element1_anchor); - } else if (safe_not_equal(previous_tag, "svg")) { + } else if (safe_not_equal(previous_tag, /*tag*/ ctx[0].svg)) { svelte_element1.d(1); svelte_element1 = create_dynamic_element(ctx); svelte_element1.c(); @@ -92,7 +92,7 @@ function create_fragment(ctx) { svelte_element1 = null; } - previous_tag = "svg"; + previous_tag = /*tag*/ ctx[0].svg; }, i: noop, o: noop, @@ -103,10 +103,15 @@ function create_fragment(ctx) { }; } +function instance($$self) { + const tag = { svg: 'svg', path: 'path' }; + return [tag]; +} + class Component extends SvelteComponent { constructor(options) { super(); - init(this, options, null, create_fragment, safe_not_equal, {}); + init(this, options, instance, create_fragment, safe_not_equal, {}); } } diff --git a/test/js/samples/svelte-element-svg/input.svelte b/test/js/samples/svelte-element-svg/input.svelte index 2dc4d54814..111c0183c6 100644 --- a/test/js/samples/svelte-element-svg/input.svelte +++ b/test/js/samples/svelte-element-svg/input.svelte @@ -1,3 +1,7 @@ - - - \ No newline at end of file + + + + + diff --git a/test/runtime/samples/static-svelte-element/_config.js b/test/runtime/samples/static-svelte-element/_config.js new file mode 100644 index 0000000000..a26de61338 --- /dev/null +++ b/test/runtime/samples/static-svelte-element/_config.js @@ -0,0 +1,13 @@ +export default { + html: ` +
+

+
+ `, + + test({ assert, target }) { + const p = target.querySelector('p'); + + assert.notEqual(p, undefined); + } +}; diff --git a/test/runtime/samples/static-svelte-element/main.svelte b/test/runtime/samples/static-svelte-element/main.svelte new file mode 100644 index 0000000000..3bdf853a5a --- /dev/null +++ b/test/runtime/samples/static-svelte-element/main.svelte @@ -0,0 +1,3 @@ +
+ +
diff --git a/test/runtime/samples/static-svelte-element2/_config.js b/test/runtime/samples/static-svelte-element2/_config.js new file mode 100644 index 0000000000..a26de61338 --- /dev/null +++ b/test/runtime/samples/static-svelte-element2/_config.js @@ -0,0 +1,13 @@ +export default { + html: ` +
+

+
+ `, + + test({ assert, target }) { + const p = target.querySelector('p'); + + assert.notEqual(p, undefined); + } +}; diff --git a/test/runtime/samples/static-svelte-element2/main.svelte b/test/runtime/samples/static-svelte-element2/main.svelte new file mode 100644 index 0000000000..a723b955d4 --- /dev/null +++ b/test/runtime/samples/static-svelte-element2/main.svelte @@ -0,0 +1,7 @@ + + +
+ +
From 06648d1f65ff9a9fc8392dd5c49ab5753b20abce Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sun, 1 Jan 2023 16:43:46 +0800 Subject: [PATCH 06/61] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd4ff5f7ac..aa0a2d4c52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 3.55.1 (unreleased) * add missing `submitter` property to `on:submit` event type +* Fix static `` optimization in production mode ([#7938](https://github.com/sveltejs/svelte/pull/7938)) ## 3.55.0 From 094483b397829d2c7633f7f6bc278e5ecfd0868a Mon Sep 17 00:00:00 2001 From: wackbyte Date: Mon, 2 Jan 2023 01:39:55 +0000 Subject: [PATCH 07/61] [fix] say "nonnegative" instead of "positive" tabIndex for `a11y-no-noninteractive-tabindex` (#8126) --- site/content/docs/06-accessibility-warnings.md | 2 +- src/compiler/compile/compiler_warnings.ts | 2 +- .../samples/a11y-no-nointeractive-tabindex/warnings.json | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/site/content/docs/06-accessibility-warnings.md b/site/content/docs/06-accessibility-warnings.md index 8be8eb888c..8d3d44a94e 100644 --- a/site/content/docs/06-accessibility-warnings.md +++ b/site/content/docs/06-accessibility-warnings.md @@ -268,7 +268,7 @@ Some HTML elements have default ARIA roles. Giving these elements an ARIA role t Tab key navigation should be limited to elements on the page that can be interacted with. ```sv - +
``` diff --git a/src/compiler/compile/compiler_warnings.ts b/src/compiler/compile/compiler_warnings.ts index bbc12617e9..3f552eb8b8 100644 --- a/src/compiler/compile/compiler_warnings.ts +++ b/src/compiler/compile/compiler_warnings.ts @@ -185,7 +185,7 @@ export default { }), a11y_no_noninteractive_tabindex: { code: 'a11y-no-noninteractive-tabindex', - message: 'A11y: noninteractive element cannot have positive tabIndex value' + message: 'A11y: noninteractive element cannot have nonnegative tabIndex value' }, redundant_event_modifier_for_touch: { code: 'redundant-event-modifier', diff --git a/test/validator/samples/a11y-no-nointeractive-tabindex/warnings.json b/test/validator/samples/a11y-no-nointeractive-tabindex/warnings.json index b2c3ec4168..1c643c896b 100644 --- a/test/validator/samples/a11y-no-nointeractive-tabindex/warnings.json +++ b/test/validator/samples/a11y-no-nointeractive-tabindex/warnings.json @@ -6,7 +6,7 @@ "column": 20, "line": 12 }, - "message": "A11y: noninteractive element cannot have positive tabIndex value", + "message": "A11y: noninteractive element cannot have nonnegative tabIndex value", "pos": 258, "start": { "character": 258, @@ -21,7 +21,7 @@ "column": 35, "line": 13 }, - "message": "A11y: noninteractive element cannot have positive tabIndex value", + "message": "A11y: noninteractive element cannot have nonnegative tabIndex value", "pos": 279, "start": { "character": 279, @@ -36,7 +36,7 @@ "column": 24, "line": 14 }, - "message": "A11y: noninteractive element cannot have positive tabIndex value", + "message": "A11y: noninteractive element cannot have nonnegative tabIndex value", "pos": 315, "start": { "character": 315, @@ -51,7 +51,7 @@ "column": 26, "line": 15 }, - "message": "A11y: noninteractive element cannot have positive tabIndex value", + "message": "A11y: noninteractive element cannot have nonnegative tabIndex value", "pos": 340, "start": { "character": 340, From a5d6713c8edff97bdcc01b4dda13c16579294acf Mon Sep 17 00:00:00 2001 From: Gus Wezerek Date: Sun, 1 Jan 2023 19:18:52 -0700 Subject: [PATCH 08/61] Fix bug with transition draw when delay is passed (#8094) Signed-off-by: Gus Wezerek Signed-off-by: Gus Wezerek Co-authored-by: Gus Wezerek --- src/runtime/transition/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/runtime/transition/index.ts b/src/runtime/transition/index.ts index 9315cd77d5..5940d054d3 100644 --- a/src/runtime/transition/index.ts +++ b/src/runtime/transition/index.ts @@ -198,7 +198,10 @@ export function draw(node: SVGElement & { getTotalLength(): number }, { delay, duration, easing, - css: (t, u) => `stroke-dasharray: ${t * len} ${u * len}` + css: (t, u) => ` + stroke-dasharray: ${len}; + stroke-dashoffset: ${u * len}; + ` }; } From 4f365f017174c3f9356c9987204e7f760aafcb13 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Mon, 2 Jan 2023 10:20:38 +0800 Subject: [PATCH 09/61] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa0a2d4c52..30eef65b74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * add missing `submitter` property to `on:submit` event type * Fix static `` optimization in production mode ([#7938](https://github.com/sveltejs/svelte/pull/7938)) +* Fix `draw` transition with delay showing a dot at the beginning of transition ([#6816](https://github.com/sveltejs/svelte/issues/6816)) ## 3.55.0 From 1f021226c5df92e0685cce806918b8953e521a2a Mon Sep 17 00:00:00 2001 From: Ming07 Date: Mon, 2 Jan 2023 10:23:35 +0800 Subject: [PATCH 10/61] [fix] named slots breaks svelte-ignore comments (#8105) * [fix] Named slots breaks svelte-ignore comments Fixes #8075 * test: add tests * refactor * refactor test Co-authored-by: mojinming Co-authored-by: Yuichiro Yamashita --- src/compiler/compile/nodes/InlineComponent.ts | 2 ++ .../samples/slot-warning-ignore/input.svelte | 8 ++++++++ .../samples/slot-warning-ignore/warnings.json | 1 + .../validator/samples/slot-warning/input.svelte | 7 +++++++ .../samples/slot-warning/warnings.json | 17 +++++++++++++++++ .../samples/slot-warning2/input.svelte | 8 ++++++++ .../samples/slot-warning2/warnings.json | 17 +++++++++++++++++ 7 files changed, 60 insertions(+) create mode 100644 test/validator/samples/slot-warning-ignore/input.svelte create mode 100644 test/validator/samples/slot-warning-ignore/warnings.json create mode 100644 test/validator/samples/slot-warning/input.svelte create mode 100644 test/validator/samples/slot-warning/warnings.json create mode 100644 test/validator/samples/slot-warning2/input.svelte create mode 100644 test/validator/samples/slot-warning2/warnings.json diff --git a/src/compiler/compile/nodes/InlineComponent.ts b/src/compiler/compile/nodes/InlineComponent.ts index 26cfeb7ef9..e9ac86a55c 100644 --- a/src/compiler/compile/nodes/InlineComponent.ts +++ b/src/compiler/compile/nodes/InlineComponent.ts @@ -143,6 +143,8 @@ export default class InlineComponent extends Node { children.push(slot_template); info.children.splice(i, 1); + } else if (child.type === 'Comment' && children.length > 0) { + children[children.length - 1].children.unshift(child); } } diff --git a/test/validator/samples/slot-warning-ignore/input.svelte b/test/validator/samples/slot-warning-ignore/input.svelte new file mode 100644 index 0000000000..003b5bde63 --- /dev/null +++ b/test/validator/samples/slot-warning-ignore/input.svelte @@ -0,0 +1,8 @@ + + + + +
hi!
+
diff --git a/test/validator/samples/slot-warning-ignore/warnings.json b/test/validator/samples/slot-warning-ignore/warnings.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/test/validator/samples/slot-warning-ignore/warnings.json @@ -0,0 +1 @@ +[] diff --git a/test/validator/samples/slot-warning/input.svelte b/test/validator/samples/slot-warning/input.svelte new file mode 100644 index 0000000000..3d60236edc --- /dev/null +++ b/test/validator/samples/slot-warning/input.svelte @@ -0,0 +1,7 @@ + + + +
hi!
+
diff --git a/test/validator/samples/slot-warning/warnings.json b/test/validator/samples/slot-warning/warnings.json new file mode 100644 index 0000000000..14691b4231 --- /dev/null +++ b/test/validator/samples/slot-warning/warnings.json @@ -0,0 +1,17 @@ +[ + { + "code": "a11y-click-events-have-key-events", + "message": "A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.", + "start": { + "character": 78, + "column": 1, + "line": 6 + }, + "end": { + "character": 112, + "column": 35, + "line": 6 + }, + "pos": 78 + } +] diff --git a/test/validator/samples/slot-warning2/input.svelte b/test/validator/samples/slot-warning2/input.svelte new file mode 100644 index 0000000000..ab3c52d35d --- /dev/null +++ b/test/validator/samples/slot-warning2/input.svelte @@ -0,0 +1,8 @@ + + + + +
hi!
+
diff --git a/test/validator/samples/slot-warning2/warnings.json b/test/validator/samples/slot-warning2/warnings.json new file mode 100644 index 0000000000..5554c3f764 --- /dev/null +++ b/test/validator/samples/slot-warning2/warnings.json @@ -0,0 +1,17 @@ +[ + { + "code": "a11y-click-events-have-key-events", + "message": "A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.", + "start": { + "character": 120, + "column": 1, + "line": 7 + }, + "end": { + "character": 154, + "column": 35, + "line": 7 + }, + "pos": 120 + } +] From 14d09a085036858de93148d283e4096d3cd39e53 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Mon, 2 Jan 2023 10:26:58 +0800 Subject: [PATCH 11/61] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30eef65b74..f1e7b6b5b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * add missing `submitter` property to `on:submit` event type * Fix static `` optimization in production mode ([#7938](https://github.com/sveltejs/svelte/pull/7938)) * Fix `draw` transition with delay showing a dot at the beginning of transition ([#6816](https://github.com/sveltejs/svelte/issues/6816)) +* Fix `svelte-ignore` comment breaks named slot ([#8075](https://github.com/sveltejs/svelte/issues/8075)) ## 3.55.0 From c9e98e6bbaed9b33df8087567235de9a54fdc537 Mon Sep 17 00:00:00 2001 From: Mathias Picker <48158184+MathiasWP@users.noreply.github.com> Date: Mon, 2 Jan 2023 03:48:34 +0100 Subject: [PATCH 12/61] [fix]: remove double up initialization on svelte:element (#8142) * fixed double up initialization on svelte:element elements * updated test and fixed bug * update other svelte:element test * removed whitespace * refactor * correctly update expected ouput resulting from #7938 * remove .solo Co-authored-by: Yuichiro Yamashita --- .../render_dom/wrappers/Element/index.ts | 39 ++-- .../svelte-element-event-handlers/expected.js | 168 ++++++++++++++++++ .../input.svelte | 3 + .../js/samples/svelte-element-svg/expected.js | 43 ++--- 4 files changed, 212 insertions(+), 41 deletions(-) create mode 100644 test/js/samples/svelte-element-event-handlers/expected.js create mode 100644 test/js/samples/svelte-element-event-handlers/input.svelte diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts index cef758b89e..8a8f59810b 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts @@ -170,6 +170,15 @@ export default class ElementWrapper extends Wrapper { ) { super(renderer, block, parent, node); + this.var = { + type: 'Identifier', + name: node.name.replace(regex_invalid_variable_identifier_characters, '_') + }; + + this.void = is_void(node.name); + + this.class_dependencies = []; + if (node.is_dynamic_element && block.type !== CHILD_DYNAMIC_ELEMENT_BLOCK) { this.child_dynamic_element_block = block.child({ comment: create_debugging_comment(node, renderer.component), @@ -185,16 +194,13 @@ export default class ElementWrapper extends Wrapper { strip_whitespace, next_sibling ); - } - this.var = { - type: 'Identifier', - name: node.name.replace(regex_invalid_variable_identifier_characters, '_') - }; - - this.void = is_void(node.name); - - this.class_dependencies = []; + // the original svelte:element is never used for rendering, because + // it gets assigned a child_dynamic_element which is used in all rendering logic. + // so doing all of this on the original svelte:element will just cause double + // code, because it will be done again on the child_dynamic_element. + return; + } if (this.node.children.length) { this.node.lets.forEach(l => { @@ -327,20 +333,19 @@ export default class ElementWrapper extends Wrapper { ${this.var}.p(#ctx, #dirty); } } else if (${previous_tag}) { - ${ - has_transitions - ? b` + ${has_transitions + ? b` @group_outros(); @transition_out(${this.var}, 1, 1, () => { ${this.var} = null; }); @check_outros(); ` - : b` + : b` ${this.var}.d(1); ${this.var} = null; ` - } + } } ${previous_tag} = ${tag}; `); @@ -682,9 +687,9 @@ export default class ElementWrapper extends Wrapper { function ${handler}(${params}) { ${binding_group.bindings.map(b => b.handler.mutation)} ${Array.from(dependencies) - .filter(dep => dep[0] !== '$') - .filter(dep => !contextual_dependencies.has(dep)) - .map(dep => b`${this.renderer.invalidate(dep)};`)} + .filter(dep => dep[0] !== '$') + .filter(dep => !contextual_dependencies.has(dep)) + .map(dep => b`${this.renderer.invalidate(dep)};`)} } `); diff --git a/test/js/samples/svelte-element-event-handlers/expected.js b/test/js/samples/svelte-element-event-handlers/expected.js new file mode 100644 index 0000000000..b9e648aadc --- /dev/null +++ b/test/js/samples/svelte-element-event-handlers/expected.js @@ -0,0 +1,168 @@ +/* generated by Svelte vX.Y.Z */ +import { + SvelteComponent, + append, + assign, + bubble, + detach, + element, + empty, + get_spread_update, + init, + insert, + listen, + noop, + run_all, + safe_not_equal, + set_attributes, + set_custom_element_data_map +} from "svelte/internal"; + +function create_dynamic_element(ctx) { + let svelte_element1; + let svelte_element0; + let mounted; + let dispose; + let svelte_element0_levels = [{ class: "inner" }]; + let svelte_element0_data = {}; + + for (let i = 0; i < svelte_element0_levels.length; i += 1) { + svelte_element0_data = assign(svelte_element0_data, svelte_element0_levels[i]); + } + + let svelte_element1_levels = [{ class: "outer" }]; + let svelte_element1_data = {}; + + for (let i = 0; i < svelte_element1_levels.length; i += 1) { + svelte_element1_data = assign(svelte_element1_data, svelte_element1_levels[i]); + } + + return { + c() { + svelte_element1 = element("a"); + svelte_element0 = element("span"); + + if ((/-/).test("span")) { + set_custom_element_data_map(svelte_element0, svelte_element0_data); + } else { + set_attributes(svelte_element0, svelte_element0_data); + } + + if ((/-/).test("a")) { + set_custom_element_data_map(svelte_element1, svelte_element1_data); + } else { + set_attributes(svelte_element1, svelte_element1_data); + } + }, + m(target, anchor) { + insert(target, svelte_element1, anchor); + append(svelte_element1, svelte_element0); + + if (!mounted) { + dispose = [ + listen(svelte_element0, "keydown", /*keydown_handler_1*/ ctx[2]), + listen(svelte_element0, "keyup", /*keyup_handler_1*/ ctx[3]), + listen(svelte_element1, "keydown", /*keydown_handler*/ ctx[0]), + listen(svelte_element1, "keyup", /*keyup_handler*/ ctx[1]) + ]; + + mounted = true; + } + }, + p(ctx, dirty) { + svelte_element0_data = get_spread_update(svelte_element0_levels, [{ class: "inner" }]); + + if ((/-/).test("span")) { + set_custom_element_data_map(svelte_element0, svelte_element0_data); + } else { + set_attributes(svelte_element0, svelte_element0_data); + } + + svelte_element1_data = get_spread_update(svelte_element1_levels, [{ class: "outer" }]); + + if ((/-/).test("a")) { + set_custom_element_data_map(svelte_element1, svelte_element1_data); + } else { + set_attributes(svelte_element1, svelte_element1_data); + } + }, + d(detaching) { + if (detaching) detach(svelte_element1); + mounted = false; + run_all(dispose); + } + }; +} + +function create_fragment(ctx) { + let previous_tag = "a"; + let svelte_element_anchor; + let svelte_element = "a" && create_dynamic_element(ctx); + + return { + c() { + if (svelte_element) svelte_element.c(); + svelte_element_anchor = empty(); + }, + m(target, anchor) { + if (svelte_element) svelte_element.m(target, anchor); + insert(target, svelte_element_anchor, anchor); + }, + p(ctx, [dirty]) { + if ("a") { + if (!previous_tag) { + svelte_element = create_dynamic_element(ctx); + svelte_element.c(); + svelte_element.m(svelte_element_anchor.parentNode, svelte_element_anchor); + } else if (safe_not_equal(previous_tag, "a")) { + svelte_element.d(1); + svelte_element = create_dynamic_element(ctx); + svelte_element.c(); + svelte_element.m(svelte_element_anchor.parentNode, svelte_element_anchor); + } else { + svelte_element.p(ctx, dirty); + } + } else if (previous_tag) { + svelte_element.d(1); + svelte_element = null; + } + + previous_tag = "a"; + }, + i: noop, + o: noop, + d(detaching) { + if (detaching) detach(svelte_element_anchor); + if (svelte_element) svelte_element.d(detaching); + } + }; +} + +function instance($$self) { + function keydown_handler(event) { + bubble.call(this, $$self, event); + } + + function keyup_handler(event) { + bubble.call(this, $$self, event); + } + + function keydown_handler_1(event) { + bubble.call(this, $$self, event); + } + + function keyup_handler_1(event) { + bubble.call(this, $$self, event); + } + + return [keydown_handler, keyup_handler, keydown_handler_1, keyup_handler_1]; +} + +class Component extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance, create_fragment, safe_not_equal, {}); + } +} + +export default Component; \ No newline at end of file diff --git a/test/js/samples/svelte-element-event-handlers/input.svelte b/test/js/samples/svelte-element-event-handlers/input.svelte new file mode 100644 index 0000000000..bb0b7b57a9 --- /dev/null +++ b/test/js/samples/svelte-element-event-handlers/input.svelte @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/test/js/samples/svelte-element-svg/expected.js b/test/js/samples/svelte-element-svg/expected.js index 263f6c842b..7db210219b 100644 --- a/test/js/samples/svelte-element-svg/expected.js +++ b/test/js/samples/svelte-element-svg/expected.js @@ -14,11 +14,6 @@ import { svg_element } from "svelte/internal"; -function create_dynamic_element_1(ctx) { - return { c: noop, m: noop, p: noop, d: noop }; -} - -// (5:0) function create_dynamic_element(ctx) { let svelte_element1; let svelte_element0; @@ -61,35 +56,35 @@ function create_dynamic_element(ctx) { function create_fragment(ctx) { let previous_tag = /*tag*/ ctx[0].svg; - let svelte_element1_anchor; - let svelte_element1 = /*tag*/ ctx[0].svg && create_dynamic_element(ctx); + let svelte_element_anchor; + let svelte_element = /*tag*/ ctx[0].svg && create_dynamic_element(ctx); return { c() { - if (svelte_element1) svelte_element1.c(); - svelte_element1_anchor = empty(); + if (svelte_element) svelte_element.c(); + svelte_element_anchor = empty(); }, m(target, anchor) { - if (svelte_element1) svelte_element1.m(target, anchor); - insert(target, svelte_element1_anchor, anchor); + if (svelte_element) svelte_element.m(target, anchor); + insert(target, svelte_element_anchor, anchor); }, p(ctx, [dirty]) { if (/*tag*/ ctx[0].svg) { if (!previous_tag) { - svelte_element1 = create_dynamic_element(ctx); - svelte_element1.c(); - svelte_element1.m(svelte_element1_anchor.parentNode, svelte_element1_anchor); + svelte_element = create_dynamic_element(ctx); + svelte_element.c(); + svelte_element.m(svelte_element_anchor.parentNode, svelte_element_anchor); } else if (safe_not_equal(previous_tag, /*tag*/ ctx[0].svg)) { - svelte_element1.d(1); - svelte_element1 = create_dynamic_element(ctx); - svelte_element1.c(); - svelte_element1.m(svelte_element1_anchor.parentNode, svelte_element1_anchor); + svelte_element.d(1); + svelte_element = create_dynamic_element(ctx); + svelte_element.c(); + svelte_element.m(svelte_element_anchor.parentNode, svelte_element_anchor); } else { - svelte_element1.p(ctx, dirty); + svelte_element.p(ctx, dirty); } } else if (previous_tag) { - svelte_element1.d(1); - svelte_element1 = null; + svelte_element.d(1); + svelte_element = null; } previous_tag = /*tag*/ ctx[0].svg; @@ -97,8 +92,8 @@ function create_fragment(ctx) { i: noop, o: noop, d(detaching) { - if (detaching) detach(svelte_element1_anchor); - if (svelte_element1) svelte_element1.d(detaching); + if (detaching) detach(svelte_element_anchor); + if (svelte_element) svelte_element.d(detaching); } }; } @@ -115,4 +110,4 @@ class Component extends SvelteComponent { } } -export default Component; +export default Component; \ No newline at end of file From 1d658e75012a361de6f6ae841995d423fb8d4e30 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Mon, 2 Jan 2023 10:51:01 +0800 Subject: [PATCH 13/61] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1e7b6b5b1..4dc3e9390d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ * Fix static `` optimization in production mode ([#7938](https://github.com/sveltejs/svelte/pull/7938)) * Fix `draw` transition with delay showing a dot at the beginning of transition ([#6816](https://github.com/sveltejs/svelte/issues/6816)) * Fix `svelte-ignore` comment breaks named slot ([#8075](https://github.com/sveltejs/svelte/issues/8075)) +* Fix duplicate event listeners for `` ([#8129](https://github.com/sveltejs/svelte/issues/8129)) + ## 3.55.0 From 762d0429b1fd2c3743fe7836108b3c1c557db750 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Mon, 2 Jan 2023 06:51:01 +0100 Subject: [PATCH 14/61] [fix] propagate bindings correctly (#8114) Fixes #8103 introduced through #7981 Keeps the infinite loop from happening but reopens #6298 and #5689 --- .../wrappers/InlineComponent/index.ts | 2 +- src/runtime/internal/Component.ts | 6 ++--- src/runtime/internal/scheduler.ts | 25 +++++++++++++++---- .../binding-indirect-value/Component.svelte | 6 +++++ .../_config.js | 3 ++- .../binding-indirect-value/main.svelte | 8 ++++++ .../Tab.svelte | 0 .../_config.js | 10 ++++++++ .../main.svelte | 0 9 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 test/runtime/samples/binding-indirect-value/Component.svelte rename test/runtime/samples/{binding-no-unnecessary-invalidation => binding-indirect-value}/_config.js (62%) create mode 100644 test/runtime/samples/binding-indirect-value/main.svelte rename test/runtime/samples/{binding-no-unnecessary-invalidation => binding-no-unnecessary-invalidation.skip}/Tab.svelte (100%) create mode 100644 test/runtime/samples/binding-no-unnecessary-invalidation.skip/_config.js rename test/runtime/samples/{binding-no-unnecessary-invalidation => binding-no-unnecessary-invalidation.skip}/main.svelte (100%) diff --git a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts index f7875dc1b0..bca01fdb4c 100644 --- a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts +++ b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts @@ -393,7 +393,7 @@ export default class InlineComponentWrapper extends Wrapper { component.partly_hoisted.push(body); - return b`@binding_callbacks.push(() => @bind(${this.var}, '${binding.name}', ${id}, ${snippet}));`; + return b`@binding_callbacks.push(() => @bind(${this.var}, '${binding.name}', ${id}));`; }); const munged_handlers = this.node.handlers.map(handler => { diff --git a/src/runtime/internal/Component.ts b/src/runtime/internal/Component.ts index eedf8dd1ad..5aec24c651 100644 --- a/src/runtime/internal/Component.ts +++ b/src/runtime/internal/Component.ts @@ -5,13 +5,11 @@ import { children, detach, start_hydrating, end_hydrating } from './dom'; import { transition_in } from './transitions'; import { T$$ } from './types'; -export function bind(component, name, callback, value) { +export function bind(component, name, callback) { const index = component.$$.props[name]; if (index !== undefined) { component.$$.bound[index] = callback; - if (value === undefined) { - callback(component.$$.ctx[index]); - } + callback(component.$$.ctx[index]); } } diff --git a/src/runtime/internal/scheduler.ts b/src/runtime/internal/scheduler.ts index c0b8e57b08..f95ba446f5 100644 --- a/src/runtime/internal/scheduler.ts +++ b/src/runtime/internal/scheduler.ts @@ -52,17 +52,32 @@ export function add_flush_callback(fn) { const seen_callbacks = new Set(); let flushidx = 0; // Do *not* move this inside the flush() function export function flush() { + // Do not reenter flush while dirty components are updated, as this can + // result in an infinite loop. Instead, let the inner flush handle it. + // Reentrancy is ok afterwards for bindings etc. + if (flushidx !== 0) { + return; + } + const saved_component = current_component; do { // first, call beforeUpdate functions // and update components - while (flushidx < dirty_components.length) { - const component = dirty_components[flushidx]; - flushidx++; - set_current_component(component); - update(component.$$); + try { + while (flushidx < dirty_components.length) { + const component = dirty_components[flushidx]; + flushidx++; + set_current_component(component); + update(component.$$); + } + } catch (e) { + // reset dirty state to not end up in a deadlocked state and then rethrow + dirty_components.length = 0; + flushidx = 0; + throw e; } + set_current_component(null); dirty_components.length = 0; diff --git a/test/runtime/samples/binding-indirect-value/Component.svelte b/test/runtime/samples/binding-indirect-value/Component.svelte new file mode 100644 index 0000000000..25bf0d6758 --- /dev/null +++ b/test/runtime/samples/binding-indirect-value/Component.svelte @@ -0,0 +1,6 @@ + + +Child component "{value}"
diff --git a/test/runtime/samples/binding-no-unnecessary-invalidation/_config.js b/test/runtime/samples/binding-indirect-value/_config.js similarity index 62% rename from test/runtime/samples/binding-no-unnecessary-invalidation/_config.js rename to test/runtime/samples/binding-indirect-value/_config.js index a34cf0121f..4eaf6839aa 100644 --- a/test/runtime/samples/binding-no-unnecessary-invalidation/_config.js +++ b/test/runtime/samples/binding-indirect-value/_config.js @@ -1,7 +1,8 @@ export default { async test({ assert, target }) { assert.htmlEqual(target.innerHTML, ` -

0

+ Parent component "bar"
+ Child component "bar"
`); } }; diff --git a/test/runtime/samples/binding-indirect-value/main.svelte b/test/runtime/samples/binding-indirect-value/main.svelte new file mode 100644 index 0000000000..db2734c890 --- /dev/null +++ b/test/runtime/samples/binding-indirect-value/main.svelte @@ -0,0 +1,8 @@ + + +Parent component "{value}"
+ diff --git a/test/runtime/samples/binding-no-unnecessary-invalidation/Tab.svelte b/test/runtime/samples/binding-no-unnecessary-invalidation.skip/Tab.svelte similarity index 100% rename from test/runtime/samples/binding-no-unnecessary-invalidation/Tab.svelte rename to test/runtime/samples/binding-no-unnecessary-invalidation.skip/Tab.svelte diff --git a/test/runtime/samples/binding-no-unnecessary-invalidation.skip/_config.js b/test/runtime/samples/binding-no-unnecessary-invalidation.skip/_config.js new file mode 100644 index 0000000000..d7e553fd46 --- /dev/null +++ b/test/runtime/samples/binding-no-unnecessary-invalidation.skip/_config.js @@ -0,0 +1,10 @@ +// this test currently fails because the fix that made it pass broke other tests, +// see https://github.com/sveltejs/svelte/pull/8114 for more context. +export default { + skip: true, + async test({ assert, target }) { + assert.htmlEqual(target.innerHTML, ` +

0

+ `); + } +}; diff --git a/test/runtime/samples/binding-no-unnecessary-invalidation/main.svelte b/test/runtime/samples/binding-no-unnecessary-invalidation.skip/main.svelte similarity index 100% rename from test/runtime/samples/binding-no-unnecessary-invalidation/main.svelte rename to test/runtime/samples/binding-no-unnecessary-invalidation.skip/main.svelte From 26c0d3f17d067fa5eab6e980dbeda5733b8998dd Mon Sep 17 00:00:00 2001 From: Yuichiro Yamashita Date: Mon, 2 Jan 2023 15:47:14 +0900 Subject: [PATCH 15/61] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dc3e9390d..7f6127ad87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ * Fix `draw` transition with delay showing a dot at the beginning of transition ([#6816](https://github.com/sveltejs/svelte/issues/6816)) * Fix `svelte-ignore` comment breaks named slot ([#8075](https://github.com/sveltejs/svelte/issues/8075)) * Fix duplicate event listeners for `` ([#8129](https://github.com/sveltejs/svelte/issues/8129)) - +* Fix max call stack exceeded ([#7032](https://github.com/sveltejs/svelte/issues/7032)) +* Revert to prevent running init binding unnecessarily ([#8103](https://github.com/sveltejs/svelte/issues/8103)) ## 3.55.0 From e1a1c7fa87aca46d5cf5ac68596df01631da585d Mon Sep 17 00:00:00 2001 From: Yuichiro Yamashita Date: Mon, 2 Jan 2023 15:55:14 +0900 Subject: [PATCH 16/61] [chore] Fix CI (#8160) * ci build * fix test * add test for #7938 --- generate-type-definitions.js | 8 +++- src/runtime/transition/index.ts | 2 +- .../svelte-element-event-handlers/expected.js | 25 ++++++----- .../input.svelte | 11 +++-- .../samples/svelte-element-static/expected.js | 41 +++++++++++++++++++ .../svelte-element-static/input.svelte | 3 ++ 6 files changed, 73 insertions(+), 17 deletions(-) create mode 100644 test/js/samples/svelte-element-static/expected.js create mode 100644 test/js/samples/svelte-element-static/input.svelte diff --git a/generate-type-definitions.js b/generate-type-definitions.js index d8f6e9f826..6ec2f313c3 100644 --- a/generate-type-definitions.js +++ b/generate-type-definitions.js @@ -3,8 +3,12 @@ const { execSync } = require('child_process'); const { readFileSync, writeFileSync } = require('fs'); -execSync('tsc -p src/compiler --emitDeclarationOnly && tsc -p src/runtime --emitDeclarationOnly'); - +try { + execSync('tsc -p src/compiler --emitDeclarationOnly && tsc -p src/runtime --emitDeclarationOnly'); +} catch (err) { + console.error(err.stderr.toString()); + throw err; +} // We need to add these types to the .d.ts files here because if we add them before building, the build will fail, // because the TS->JS transformation doesn't know these exports are types and produces code that fails at runtime. // We can't use `export type` syntax either because the TS version we're on doesn't have this feature yet. diff --git a/src/runtime/transition/index.ts b/src/runtime/transition/index.ts index 5940d054d3..c6d9dbc97a 100644 --- a/src/runtime/transition/index.ts +++ b/src/runtime/transition/index.ts @@ -198,7 +198,7 @@ export function draw(node: SVGElement & { getTotalLength(): number }, { delay, duration, easing, - css: (t, u) => ` + css: (_, u) => ` stroke-dasharray: ${len}; stroke-dashoffset: ${u * len}; ` diff --git a/test/js/samples/svelte-element-event-handlers/expected.js b/test/js/samples/svelte-element-event-handlers/expected.js index b9e648aadc..ab24f2e924 100644 --- a/test/js/samples/svelte-element-event-handlers/expected.js +++ b/test/js/samples/svelte-element-event-handlers/expected.js @@ -39,16 +39,16 @@ function create_dynamic_element(ctx) { return { c() { - svelte_element1 = element("a"); - svelte_element0 = element("span"); + svelte_element1 = element(a); + svelte_element0 = element(span); - if ((/-/).test("span")) { + if ((/-/).test(span)) { set_custom_element_data_map(svelte_element0, svelte_element0_data); } else { set_attributes(svelte_element0, svelte_element0_data); } - if ((/-/).test("a")) { + if ((/-/).test(a)) { set_custom_element_data_map(svelte_element1, svelte_element1_data); } else { set_attributes(svelte_element1, svelte_element1_data); @@ -72,7 +72,7 @@ function create_dynamic_element(ctx) { p(ctx, dirty) { svelte_element0_data = get_spread_update(svelte_element0_levels, [{ class: "inner" }]); - if ((/-/).test("span")) { + if ((/-/).test(span)) { set_custom_element_data_map(svelte_element0, svelte_element0_data); } else { set_attributes(svelte_element0, svelte_element0_data); @@ -80,7 +80,7 @@ function create_dynamic_element(ctx) { svelte_element1_data = get_spread_update(svelte_element1_levels, [{ class: "outer" }]); - if ((/-/).test("a")) { + if ((/-/).test(a)) { set_custom_element_data_map(svelte_element1, svelte_element1_data); } else { set_attributes(svelte_element1, svelte_element1_data); @@ -95,9 +95,9 @@ function create_dynamic_element(ctx) { } function create_fragment(ctx) { - let previous_tag = "a"; + let previous_tag = a; let svelte_element_anchor; - let svelte_element = "a" && create_dynamic_element(ctx); + let svelte_element = a && create_dynamic_element(ctx); return { c() { @@ -109,12 +109,12 @@ function create_fragment(ctx) { insert(target, svelte_element_anchor, anchor); }, p(ctx, [dirty]) { - if ("a") { + if (a) { if (!previous_tag) { svelte_element = create_dynamic_element(ctx); svelte_element.c(); svelte_element.m(svelte_element_anchor.parentNode, svelte_element_anchor); - } else if (safe_not_equal(previous_tag, "a")) { + } else if (safe_not_equal(previous_tag, a)) { svelte_element.d(1); svelte_element = create_dynamic_element(ctx); svelte_element.c(); @@ -127,7 +127,7 @@ function create_fragment(ctx) { svelte_element = null; } - previous_tag = "a"; + previous_tag = a; }, i: noop, o: noop, @@ -138,6 +138,9 @@ function create_fragment(ctx) { }; } +const a = 'a'; +const span = 'span'; + function instance($$self) { function keydown_handler(event) { bubble.call(this, $$self, event); diff --git a/test/js/samples/svelte-element-event-handlers/input.svelte b/test/js/samples/svelte-element-event-handlers/input.svelte index bb0b7b57a9..3a7b0f9800 100644 --- a/test/js/samples/svelte-element-event-handlers/input.svelte +++ b/test/js/samples/svelte-element-event-handlers/input.svelte @@ -1,3 +1,8 @@ - - - \ No newline at end of file + + + + + diff --git a/test/js/samples/svelte-element-static/expected.js b/test/js/samples/svelte-element-static/expected.js new file mode 100644 index 0000000000..68d895db3c --- /dev/null +++ b/test/js/samples/svelte-element-static/expected.js @@ -0,0 +1,41 @@ +/* generated by Svelte vX.Y.Z */ +import { + SvelteComponent, + attr, + detach, + element, + init, + insert, + noop, + safe_not_equal +} from "svelte/internal"; + +function create_fragment(ctx) { + let a; + + return { + c() { + a = element("a"); + a.innerHTML = ``; + attr(a, "class", "outer"); + }, + m(target, anchor) { + insert(target, a, anchor); + }, + p: noop, + i: noop, + o: noop, + d(detaching) { + if (detaching) detach(a); + } + }; +} + +class Component extends SvelteComponent { + constructor(options) { + super(); + init(this, options, null, create_fragment, safe_not_equal, {}); + } +} + +export default Component; \ No newline at end of file diff --git a/test/js/samples/svelte-element-static/input.svelte b/test/js/samples/svelte-element-static/input.svelte new file mode 100644 index 0000000000..4893d49847 --- /dev/null +++ b/test/js/samples/svelte-element-static/input.svelte @@ -0,0 +1,3 @@ + + + From 4b84c4df3a8c07f0a992e255350eb97db36c5cf6 Mon Sep 17 00:00:00 2001 From: Yuichiro Yamashita Date: Tue, 3 Jan 2023 12:48:06 +0900 Subject: [PATCH 17/61] [fix] Improve `is_promise` handling (#8162) * correctly handle promises that are of function type * add License Co-authored-by: Vilsol --- src/runtime/internal/utils.ts | 4 +++- .../samples/await-function-promise/_config.js | 19 +++++++++++++++++++ .../await-function-promise/main.svelte | 7 +++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/await-function-promise/_config.js create mode 100644 test/runtime/samples/await-function-promise/main.svelte diff --git a/src/runtime/internal/utils.ts b/src/runtime/internal/utils.ts index 8868e38ee2..8adb0c279b 100644 --- a/src/runtime/internal/utils.ts +++ b/src/runtime/internal/utils.ts @@ -10,8 +10,10 @@ export function assign(tar: T, src: S): T & S { return tar as T & S; } +// Adapted from https://github.com/then/is-promise/blob/master/index.js +// Distributed under MIT License https://github.com/then/is-promise/blob/master/LICENSE export function is_promise(value: any): value is PromiseLike { - return value && typeof value === 'object' && typeof value.then === 'function'; + return !!value && (typeof value === 'object' || typeof value === 'function') && typeof value.then === 'function'; } export function add_location(element, file, line, column, char) { diff --git a/test/runtime/samples/await-function-promise/_config.js b/test/runtime/samples/await-function-promise/_config.js new file mode 100644 index 0000000000..b6a9de6856 --- /dev/null +++ b/test/runtime/samples/await-function-promise/_config.js @@ -0,0 +1,19 @@ +const realPromise = Promise.resolve(42); + +const promise = () => {}; +promise.then = realPromise.then.bind(realPromise); +promise.catch = realPromise.catch.bind(realPromise); + +export default { + props: { + promise + }, + + test({ assert, target }) { + return promise.then(() => { + assert.htmlEqual(target.innerHTML, ` +

42

+ `); + }); + } +}; diff --git a/test/runtime/samples/await-function-promise/main.svelte b/test/runtime/samples/await-function-promise/main.svelte new file mode 100644 index 0000000000..aaefc6b782 --- /dev/null +++ b/test/runtime/samples/await-function-promise/main.svelte @@ -0,0 +1,7 @@ + + +{#await promise then value} +

{JSON.stringify(value)}

+{/await} From dd11917fe523a66d8f5d66aab8cbcf965f30f25f Mon Sep 17 00:00:00 2001 From: Yuichiro Yamashita Date: Tue, 3 Jan 2023 12:49:02 +0900 Subject: [PATCH 18/61] Update CHANGELOG.md --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f6127ad87..2c071d874f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,15 @@ # Svelte changelog -## 3.55.1 (unreleased) +## Unreleased -* add missing `submitter` property to `on:submit` event type +* Add missing `submitter` property to `on:submit` event type * Fix static `` optimization in production mode ([#7938](https://github.com/sveltejs/svelte/pull/7938)) * Fix `draw` transition with delay showing a dot at the beginning of transition ([#6816](https://github.com/sveltejs/svelte/issues/6816)) * Fix `svelte-ignore` comment breaks named slot ([#8075](https://github.com/sveltejs/svelte/issues/8075)) * Fix duplicate event listeners for `` ([#8129](https://github.com/sveltejs/svelte/issues/8129)) * Fix max call stack exceeded ([#7032](https://github.com/sveltejs/svelte/issues/7032)) * Revert to prevent running init binding unnecessarily ([#8103](https://github.com/sveltejs/svelte/issues/8103)) +* Improve `is_promise` logic ([#8162](https://github.com/sveltejs/svelte/pull/8162)) ## 3.55.0 From 1f8e53a37ff8dba1d8001709e9ac809dca07f73a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Jan 2023 08:35:13 -0800 Subject: [PATCH 19/61] Bump json5 from 1.0.1 to 1.0.2 (#8175) Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2. - [Release notes](https://github.com/json5/json5/releases) - [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md) - [Commits](https://github.com/json5/json5/compare/v1.0.1...v1.0.2) --- updated-dependencies: - dependency-name: json5 dependency-type: indirect ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index eeef42a72c..70fac43f0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3410,9 +3410,9 @@ "dev": true }, "node_modules/json5": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", - "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", + "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", "dev": true, "dependencies": { "minimist": "^1.2.0" @@ -7854,9 +7854,9 @@ "dev": true }, "json5": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", - "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", + "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", "dev": true, "requires": { "minimist": "^1.2.0" From f0dcf1416ccf3dbc53d0684df16ed4f79917b103 Mon Sep 17 00:00:00 2001 From: cunzaizhuyi <877824709@qq.com> Date: Tue, 10 Jan 2023 00:37:28 +0800 Subject: [PATCH 20/61] [chore] shorten import statement (#8178) --- src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts b/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts index 8dc8460e1d..6cd8820b87 100644 --- a/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts +++ b/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts @@ -1,4 +1,4 @@ -import { namespaces } from './../../../utils/namespaces'; +import { namespaces } from '../../../utils/namespaces'; import { b, x } from 'code-red'; import Renderer from '../Renderer'; import Block from '../Block'; From 7e6acbece31fbd68e2c07e37f3c849c405eb6983 Mon Sep 17 00:00:00 2001 From: Chris Reade Date: Tue, 10 Jan 2023 00:36:51 -0800 Subject: [PATCH 21/61] [fix] Adding part HTML attribute to typings (#8182) fixes #8181 --- elements/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/elements/index.d.ts b/elements/index.d.ts index 4668d190f9..d57d97ad28 100644 --- a/elements/index.d.ts +++ b/elements/index.d.ts @@ -478,6 +478,7 @@ export interface HTMLAttributes extends AriaAttributes, D hidden?: boolean | undefined | null; id?: string | undefined | null; lang?: string | undefined | null; + part?: string | undefined | null; placeholder?: string | undefined | null; slot?: string | undefined | null; spellcheck?: Booleanish | undefined | null; From be38cec3c10b83f76450c9125fa778c8af6453f7 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Tue, 10 Jan 2023 09:38:16 +0100 Subject: [PATCH 22/61] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c071d874f..4432fe446e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased * Add missing `submitter` property to `on:submit` event type +* Add missing typing for global `part` attribute ([#8181](https://github.com/sveltejs/svelte/issues/8181)) * Fix static `` optimization in production mode ([#7938](https://github.com/sveltejs/svelte/pull/7938)) * Fix `draw` transition with delay showing a dot at the beginning of transition ([#6816](https://github.com/sveltejs/svelte/issues/6816)) * Fix `svelte-ignore` comment breaks named slot ([#8075](https://github.com/sveltejs/svelte/issues/8075)) From aa98397440baa06743cead6a2955e98b75ee4515 Mon Sep 17 00:00:00 2001 From: Josh <44098505+josh-fnbtech@users.noreply.github.com> Date: Tue, 10 Jan 2023 02:38:47 -0600 Subject: [PATCH 23/61] [docs] fix typo (#8180) --- .../02-reactivity/04-updating-arrays-and-objects/text.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/content/tutorial/02-reactivity/04-updating-arrays-and-objects/text.md b/site/content/tutorial/02-reactivity/04-updating-arrays-and-objects/text.md index a298d1d1bb..bc8330206e 100644 --- a/site/content/tutorial/02-reactivity/04-updating-arrays-and-objects/text.md +++ b/site/content/tutorial/02-reactivity/04-updating-arrays-and-objects/text.md @@ -23,7 +23,7 @@ function addNumber() { } ``` -The same rule applies to array methods such as `pop`, `shift`, and `splice` and to objects methods such as `Map.set`, `Set.add`, etc. +The same rule applies to array methods such as `pop`, `shift`, and `splice` and to object methods such as `Map.set`, `Set.add`, etc. Assignments to *properties* of arrays and objects — e.g. `obj.foo += 1` or `array[i] = x` — work the same way as assignments to the values themselves. @@ -51,4 +51,4 @@ quox(obj); ...won't trigger reactivity on `obj.foo.bar`, unless you follow it up with `obj = obj`. -A simple rule of thumb: the updated variable must directly appear on the left hand side of the assignment. \ No newline at end of file +A simple rule of thumb: the updated variable must directly appear on the left hand side of the assignment. From b06e4356848ab3375797e634fd6c6114a9643252 Mon Sep 17 00:00:00 2001 From: Emil Tholin Date: Tue, 10 Jan 2023 09:39:50 +0100 Subject: [PATCH 24/61] [fix] Spread component props immutably during SSR (#8176) By passing an empty object literal as first argument to Object.assign we can avoid having objects spread as props on a component being mutated during SSR. Fixes #8171 --- .../render_ssr/handlers/InlineComponent.ts | 2 +- .../spread-component-immutable/Widget.svelte | 0 .../samples/spread-component-immutable/_config.js | 15 +++++++++++++++ .../spread-component-immutable/main.svelte | 7 +++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/spread-component-immutable/Widget.svelte create mode 100644 test/runtime/samples/spread-component-immutable/_config.js create mode 100644 test/runtime/samples/spread-component-immutable/main.svelte diff --git a/src/compiler/compile/render_ssr/handlers/InlineComponent.ts b/src/compiler/compile/render_ssr/handlers/InlineComponent.ts index 8287b46268..73d31940e2 100644 --- a/src/compiler/compile/render_ssr/handlers/InlineComponent.ts +++ b/src/compiler/compile/render_ssr/handlers/InlineComponent.ts @@ -36,7 +36,7 @@ export default function(node: InlineComponent, renderer: Renderer, options: Rend let props; if (uses_spread) { - props = x`@_Object.assign(${ + props = x`@_Object.assign({}, ${ node.attributes .map(attribute => { if (attribute.is_spread) { diff --git a/test/runtime/samples/spread-component-immutable/Widget.svelte b/test/runtime/samples/spread-component-immutable/Widget.svelte new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/runtime/samples/spread-component-immutable/_config.js b/test/runtime/samples/spread-component-immutable/_config.js new file mode 100644 index 0000000000..634fac24c1 --- /dev/null +++ b/test/runtime/samples/spread-component-immutable/_config.js @@ -0,0 +1,15 @@ +const obj = { + x: 1, + y: 2, + z: 3 +}; + +export default { + props: { + obj + }, + + test({ assert }) { + assert.deepEqual(obj, { x: 1, y: 2, z: 3 }); + } +}; diff --git a/test/runtime/samples/spread-component-immutable/main.svelte b/test/runtime/samples/spread-component-immutable/main.svelte new file mode 100644 index 0000000000..44e0954856 --- /dev/null +++ b/test/runtime/samples/spread-component-immutable/main.svelte @@ -0,0 +1,7 @@ + + + From 492d7d6f67ba3a065651f860fdcca477df0d1d04 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Tue, 10 Jan 2023 09:41:59 +0100 Subject: [PATCH 25/61] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4432fe446e..136927af52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Fix max call stack exceeded ([#7032](https://github.com/sveltejs/svelte/issues/7032)) * Revert to prevent running init binding unnecessarily ([#8103](https://github.com/sveltejs/svelte/issues/8103)) * Improve `is_promise` logic ([#8162](https://github.com/sveltejs/svelte/pull/8162)) +* Spread component props for immutably during SSR ([#8171](https://github.com/sveltejs/svelte/issues/8171)) ## 3.55.0 From 3b3e1c839c9991559547ca3e203d2282d4f90c36 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Tue, 10 Jan 2023 12:17:09 -0500 Subject: [PATCH 26/61] -> v3.55.1 --- CHANGELOG.md | 22 +++++++++++----------- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 136927af52..ce1e2a2621 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,17 @@ # Svelte changelog -## Unreleased - -* Add missing `submitter` property to `on:submit` event type +## 3.55.1 + +* Fix `draw` transition with delay showing a dot at the beginning of the path ([#6816](https://github.com/sveltejs/svelte/issues/6816)) +* Fix infinity runtime call stack when propagating bindings ([#7032](https://github.com/sveltejs/svelte/issues/7032)) +* Fix static `` optimization in production mode ([#7937](https://github.com/sveltejs/svelte/issues/7937)) +* Fix `svelte-ignore` comment breaking named slot ([#8075](https://github.com/sveltejs/svelte/issues/8075)) +* Revert change to prevent running init binding unnecessarily ([#8103](https://github.com/sveltejs/svelte/issues/8103)) +* Fix adding duplicate event listeners with `` ([#8129](https://github.com/sveltejs/svelte/issues/8129)) +* Improve detection of promises that are also functions ([#8162](https://github.com/sveltejs/svelte/pull/8162)) +* Avoid mutating spread component props during SSR ([#8171](https://github.com/sveltejs/svelte/issues/8171)) * Add missing typing for global `part` attribute ([#8181](https://github.com/sveltejs/svelte/issues/8181)) -* Fix static `` optimization in production mode ([#7938](https://github.com/sveltejs/svelte/pull/7938)) -* Fix `draw` transition with delay showing a dot at the beginning of transition ([#6816](https://github.com/sveltejs/svelte/issues/6816)) -* Fix `svelte-ignore` comment breaks named slot ([#8075](https://github.com/sveltejs/svelte/issues/8075)) -* Fix duplicate event listeners for `` ([#8129](https://github.com/sveltejs/svelte/issues/8129)) -* Fix max call stack exceeded ([#7032](https://github.com/sveltejs/svelte/issues/7032)) -* Revert to prevent running init binding unnecessarily ([#8103](https://github.com/sveltejs/svelte/issues/8103)) -* Improve `is_promise` logic ([#8162](https://github.com/sveltejs/svelte/pull/8162)) -* Spread component props for immutably during SSR ([#8171](https://github.com/sveltejs/svelte/issues/8171)) +* Add missing `submitter` property to `on:submit` event type ## 3.55.0 diff --git a/package-lock.json b/package-lock.json index 70fac43f0e..f993cad461 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "svelte", - "version": "3.55.0", + "version": "3.55.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "svelte", - "version": "3.55.0", + "version": "3.55.1", "license": "MIT", "devDependencies": { "@ampproject/remapping": "^0.3.0", diff --git a/package.json b/package.json index 8839b95c75..1efd4cb780 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.55.0", + "version": "3.55.1", "description": "Cybernetically enhanced web apps", "module": "index.mjs", "main": "index", From 967e9f51ff649f776fa034db8aba23a5a1546294 Mon Sep 17 00:00:00 2001 From: Yuichiro Yamashita Date: Thu, 12 Jan 2023 11:11:14 +0900 Subject: [PATCH 27/61] chore: add Node18 for CI (#8078) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e24f106477..1e0ce53864 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: timeout-minutes: 15 strategy: matrix: - node-version: [8, 10, 12, 14, 16] + node-version: [8, 10, 12, 14, 16, 18] os: [ubuntu-latest, windows-latest, macOS-latest] steps: - uses: actions/checkout@v3 From 79fa5b36a1b0d90407d1bf6b1d6b2504427f3f96 Mon Sep 17 00:00:00 2001 From: Gabriel Francisco Date: Fri, 27 Jan 2023 13:22:52 -0300 Subject: [PATCH 28/61] Update license year (#8227) --- LICENSE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.md b/LICENSE.md index cd8f94f4ca..aa74406768 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2016-22 [these people](https://github.com/sveltejs/svelte/graphs/contributors) +Copyright (c) 2016-23 [these people](https://github.com/sveltejs/svelte/graphs/contributors) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: From 4f42daeff78a98877d58dff49b6e05b3a4ae0f73 Mon Sep 17 00:00:00 2001 From: Jay Harris Date: Sat, 28 Jan 2023 13:25:04 +1300 Subject: [PATCH 29/61] feat: `trusted-types` CSP compatibility for Web Components (#8135) --- src/compiler/compile/render_dom/index.ts | 5 ++++- test/js/samples/css-shadow-dom-keyframes/expected.js | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index 44155f8464..58b7a8317b 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -531,7 +531,10 @@ export default function dom( constructor(options) { super(); - ${css.code && b`this.shadowRoot.innerHTML = \`\`;`} + ${css.code && b` + const style = document.createElement('style'); + style.textContent = \`${css.code.replace(regex_backslashes, '\\\\')}${css_sourcemap_enabled && options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}\` + this.shadowRoot.appendChild(style)`} @init(this, { target: this.shadowRoot, props: ${init_props}, customElement: true }, ${definition}, ${has_create_fragment ? 'create_fragment' : 'null'}, ${not_equal}, ${prop_indexes}, null, ${dirty}); diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js index 5d65949488..ba7ca9a667 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -34,7 +34,9 @@ function create_fragment(ctx) { class Component extends SvelteElement { constructor(options) { super(); - this.shadowRoot.innerHTML = ``; + const style = document.createElement('style'); + style.textContent = `div{animation:foo 1s}@keyframes foo{0%{opacity:0}100%{opacity:1}}`; + this.shadowRoot.appendChild(style); init( this, From eb90a15c2959d0d02ee27b4920dc1f197b77b70a Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 27 Jan 2023 16:27:19 -0800 Subject: [PATCH 30/61] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce1e2a2621..865ed07b53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Svelte changelog +## Unreleased + +* `trusted-types` CSP compatibility for Web Components ([#8134](https://github.com/sveltejs/svelte/issues/8134)) + ## 3.55.1 * Fix `draw` transition with delay showing a dot at the beginning of the path ([#6816](https://github.com/sveltejs/svelte/issues/6816)) From 34ae6aaf1f3279e2c0f0515f64db59d31ecb46f9 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sat, 28 Jan 2023 08:50:14 -0800 Subject: [PATCH 31/61] fix: make `noreferrer` warning less zealous (#8230) Co-authored-by: Yuichiro Yamashita --- src/compiler/compile/nodes/Element.ts | 17 +++++----- .../_config.js | 3 ++ .../input.svelte | 0 .../warnings.json | 0 .../input.svelte | 33 +++++++++++++++++++ .../warnings.json | 1 + 6 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 test/validator/samples/security-anchor-rel-noreferer-legacy/_config.js rename test/validator/samples/{security-anchor-rel-noreferrer => security-anchor-rel-noreferer-legacy}/input.svelte (100%) rename test/validator/samples/{security-anchor-rel-noreferrer => security-anchor-rel-noreferer-legacy}/warnings.json (100%) create mode 100644 test/validator/samples/security-anchor-rel-noreferer/input.svelte create mode 100644 test/validator/samples/security-anchor-rel-noreferer/warnings.json diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 06ef1ba9c1..0d3e8a01bd 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -621,22 +621,23 @@ export default class Element extends Node { const name_attribute = attribute_map.get('name'); const target_attribute = attribute_map.get('target'); - if (target_attribute && target_attribute.get_static_value() === '_blank' && href_attribute) { + // links with target="_blank" should have noopener or noreferrer: https://developer.chrome.com/docs/lighthouse/best-practices/external-anchors-use-rel-noopener/ + // modern browsers add noopener by default, so we only need to check legacy browsers + // legacy browsers don't support noopener so we only check for noreferrer there + if (component.compile_options.legacy && target_attribute && target_attribute.get_static_value() === '_blank' && href_attribute) { const href_static_value = href_attribute.get_static_value() ? href_attribute.get_static_value().toLowerCase() : null; if (href_static_value === null || href_static_value.match(/^(https?:)?\/\//i)) { const rel = attribute_map.get('rel'); if (rel == null || rel.is_static) { const rel_values = rel ? rel.get_static_value().split(regex_any_repeated_whitespaces) : []; - const expected_values = ['noreferrer']; - expected_values.forEach(expected_value => { - if (!rel || rel && rel_values.indexOf(expected_value) < 0) { + if (!rel || !rel_values.includes('noreferrer')) { component.warn(this, { - code: `security-anchor-rel-${expected_value}`, - message: `Security: Anchor with "target=_blank" should have rel attribute containing the value "${expected_value}"` + code: 'security-anchor-rel-noreferrer', + message: + 'Security: Anchor with "target=_blank" should have rel attribute containing the value "noreferrer"' }); - } - }); + } } } } diff --git a/test/validator/samples/security-anchor-rel-noreferer-legacy/_config.js b/test/validator/samples/security-anchor-rel-noreferer-legacy/_config.js new file mode 100644 index 0000000000..52f59c8767 --- /dev/null +++ b/test/validator/samples/security-anchor-rel-noreferer-legacy/_config.js @@ -0,0 +1,3 @@ +export default { + legacy: true +}; diff --git a/test/validator/samples/security-anchor-rel-noreferrer/input.svelte b/test/validator/samples/security-anchor-rel-noreferer-legacy/input.svelte similarity index 100% rename from test/validator/samples/security-anchor-rel-noreferrer/input.svelte rename to test/validator/samples/security-anchor-rel-noreferer-legacy/input.svelte diff --git a/test/validator/samples/security-anchor-rel-noreferrer/warnings.json b/test/validator/samples/security-anchor-rel-noreferer-legacy/warnings.json similarity index 100% rename from test/validator/samples/security-anchor-rel-noreferrer/warnings.json rename to test/validator/samples/security-anchor-rel-noreferer-legacy/warnings.json diff --git a/test/validator/samples/security-anchor-rel-noreferer/input.svelte b/test/validator/samples/security-anchor-rel-noreferer/input.svelte new file mode 100644 index 0000000000..f5361e5cfe --- /dev/null +++ b/test/validator/samples/security-anchor-rel-noreferer/input.svelte @@ -0,0 +1,33 @@ +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +svelte website (invalid) +Same host (valid) +Same host (valid) +Same host (valid) +svelte website (valid) +svelte website (valid) +svelte website (valid) +svelte website (valid) +svelte website (valid) +svelte website (valid) +svelte website (valid) +svelte website (valid) +svelte website (valid) +svelte website (valid) + +svelte website (valid) diff --git a/test/validator/samples/security-anchor-rel-noreferer/warnings.json b/test/validator/samples/security-anchor-rel-noreferer/warnings.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/test/validator/samples/security-anchor-rel-noreferer/warnings.json @@ -0,0 +1 @@ +[] From e875a76ad1675c21aea0911a8b32c8ad3abc070b Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sat, 28 Jan 2023 08:51:35 -0800 Subject: [PATCH 32/61] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 865ed07b53..fba777ad9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +* Make `noreferrer` warning less zealous ([#6289](https://github.com/sveltejs/svelte/issues/6289)) * `trusted-types` CSP compatibility for Web Components ([#8134](https://github.com/sveltejs/svelte/issues/8134)) ## 3.55.1 From cb972ecdba92326e67c6cc37f672c58b88fdc3a5 Mon Sep 17 00:00:00 2001 From: Tim McCabe Date: Sun, 5 Feb 2023 06:23:43 -0500 Subject: [PATCH 33/61] [chore] fix `a11y-no-nointeractive-tabindex` typo (#8252) --- .../input.svelte | 0 .../warnings.json | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename test/validator/samples/{a11y-no-nointeractive-tabindex => a11y-no-noninteractive-tabindex}/input.svelte (100%) rename test/validator/samples/{a11y-no-nointeractive-tabindex => a11y-no-noninteractive-tabindex}/warnings.json (100%) diff --git a/test/validator/samples/a11y-no-nointeractive-tabindex/input.svelte b/test/validator/samples/a11y-no-noninteractive-tabindex/input.svelte similarity index 100% rename from test/validator/samples/a11y-no-nointeractive-tabindex/input.svelte rename to test/validator/samples/a11y-no-noninteractive-tabindex/input.svelte diff --git a/test/validator/samples/a11y-no-nointeractive-tabindex/warnings.json b/test/validator/samples/a11y-no-noninteractive-tabindex/warnings.json similarity index 100% rename from test/validator/samples/a11y-no-nointeractive-tabindex/warnings.json rename to test/validator/samples/a11y-no-noninteractive-tabindex/warnings.json From 6ac24f1d5c9174b161bb6e27743c84c0a117ea7f Mon Sep 17 00:00:00 2001 From: Satvik Date: Sun, 5 Feb 2023 07:00:54 -0500 Subject: [PATCH 34/61] [docs] add missing semicolon (#8190) --- site/content/docs/02-component-format.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/content/docs/02-component-format.md b/site/content/docs/02-component-format.md index 268444ab7d..d9f7a35662 100644 --- a/site/content/docs/02-component-format.md +++ b/site/content/docs/02-component-format.md @@ -147,7 +147,7 @@ Any top-level statement (i.e. not inside a block or a function) can be made reac ```sv From d9253963f79d2066edd164580a684cd066042638 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 14 Feb 2023 09:05:19 -0800 Subject: [PATCH 40/61] Bump qs from 6.5.2 to 6.5.3 (#8090) Bumps [qs](https://github.com/ljharb/qs) from 6.5.2 to 6.5.3. - [Release notes](https://github.com/ljharb/qs/releases) - [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md) - [Commits](https://github.com/ljharb/qs/compare/v6.5.2...v6.5.3) --- updated-dependencies: - dependency-name: qs dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index f993cad461..5ab035cd2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4138,9 +4138,9 @@ } }, "node_modules/qs": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", - "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==", + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", + "integrity": "sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==", "dev": true, "engines": { "node": ">=0.6" @@ -8432,9 +8432,9 @@ } }, "qs": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", - "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==", + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", + "integrity": "sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==", "dev": true }, "queue-microtask": { From acba4b72e23c90939ca8c39a22aca185d588aa1b Mon Sep 17 00:00:00 2001 From: James Scott-Brown Date: Tue, 14 Feb 2023 18:04:49 +0000 Subject: [PATCH 41/61] docs: clarify bindings for `` value binding corresponds to the `value` property on the selected ` --- -A `` element behaves similarly to a checkbox group. The bound variable is an array with an entry corresponding to the `value` property of each selected `