Skip to content

Commit d41801c

Browse files
authored
feat: warn on using slide transition with invalid display styles (#14936)
* feat: warn on using `slide` transition with table elements * more generic * more generic
1 parent 4d2cb27 commit d41801c

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

.changeset/silver-humans-yawn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
feat: warn on using `slide` transition with table elements

documentation/docs/98-reference/.generated/client-warnings.md

+12
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,15 @@ Reactive `$state(...)` proxies and the values they proxy have different identiti
222222
```
223223
224224
To resolve this, ensure you're comparing values where both values were created with `$state(...)`, or neither were. Note that `$state.raw(...)` will _not_ create a state proxy.
225+
226+
### transition_slide_display
227+
228+
```
229+
The `slide` transition does not work correctly for elements with `display: %value%`
230+
```
231+
232+
The [slide](/docs/svelte/svelte-transition#slide) transition works by animating the `height` of the element, which requires a `display` style like `block`, `flex` or `grid`. It does not work for:
233+
234+
- `display: inline` (which is the default for elements like `<span>`), and its variants like `inline-block`, `inline-flex` and `inline-grid`
235+
- `display: table` and `table-[name]`, which are the defaults for elements like `<table>` and `<tr>`
236+
- `display: contents`

packages/svelte/messages/client-warnings/warnings.md

+10
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,13 @@ To fix it, either create callback props to communicate changes, or mark `person`
186186
```
187187
188188
To resolve this, ensure you're comparing values where both values were created with `$state(...)`, or neither were. Note that `$state.raw(...)` will _not_ create a state proxy.
189+
190+
## transition_slide_display
191+
192+
> The `slide` transition does not work correctly for elements with `display: %value%`
193+
194+
The [slide](/docs/svelte/svelte-transition#slide) transition works by animating the `height` of the element, which requires a `display` style like `block`, `flex` or `grid`. It does not work for:
195+
196+
- `display: inline` (which is the default for elements like `<span>`), and its variants like `inline-block`, `inline-flex` and `inline-grid`
197+
- `display: table` and `table-[name]`, which are the defaults for elements like `<table>` and `<tr>`
198+
- `display: contents`

packages/svelte/src/internal/client/warnings.js

+12
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,16 @@ export function state_proxy_equality_mismatch(operator) {
165165
} else {
166166
console.warn(`https://svelte.dev/e/state_proxy_equality_mismatch`);
167167
}
168+
}
169+
170+
/**
171+
* The `slide` transition does not work correctly for elements with `display: %value%`
172+
* @param {string} value
173+
*/
174+
export function transition_slide_display(value) {
175+
if (DEV) {
176+
console.warn(`%c[svelte] transition_slide_display\n%cThe \`slide\` transition does not work correctly for elements with \`display: ${value}\`\nhttps://svelte.dev/e/transition_slide_display`, bold, normal);
177+
} else {
178+
console.warn(`https://svelte.dev/e/transition_slide_display`);
179+
}
168180
}

packages/svelte/src/transition/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
/** @import { BlurParams, CrossfadeParams, DrawParams, FadeParams, FlyParams, ScaleParams, SlideParams, TransitionConfig } from './public' */
2+
3+
import { DEV } from 'esm-env';
4+
import * as w from '../internal/client/warnings.js';
5+
26
/** @param {number} x */
37
const linear = (x) => x;
48

@@ -92,6 +96,8 @@ export function fly(
9296
};
9397
}
9498

99+
var slide_warning = false;
100+
95101
/**
96102
* Slides an element in and out.
97103
*
@@ -101,6 +107,13 @@ export function fly(
101107
*/
102108
export function slide(node, { delay = 0, duration = 400, easing = cubic_out, axis = 'y' } = {}) {
103109
const style = getComputedStyle(node);
110+
111+
if (DEV && !slide_warning && /(contents|inline|table)/.test(style.display)) {
112+
slide_warning = true;
113+
Promise.resolve().then(() => (slide_warning = false));
114+
w.transition_slide_display(style.display);
115+
}
116+
104117
const opacity = +style.opacity;
105118
const primary_property = axis === 'y' ? 'height' : 'width';
106119
const primary_property_value = parseFloat(style[primary_property]);

0 commit comments

Comments
 (0)