Skip to content

Svelte 5: rendering a component with a global transition causes an error #416

Closed as not planned
@ivenuss

Description

@ivenuss

Problem

During migration from Svelte 4 to Svelte 5 I am getting error when I try to render component with global transition.

If I remove the global transition from <p in:slide|global> to <p in:slide>, it no longer throws any error.

Reproduction

Test

// MyComponent.test.ts
import { cleanup, render } from '@testing-library/svelte';
import { afterEach, describe, expect, it } from 'vitest';
import TestMyComponent from './MyComponent.test.svelte';

afterEach(() => {
  cleanup();
});

describe('FormErrorMessage', async () => {
  it('renders', async () => {
    const result = render(TestMyComponent);
    expect(() => result.getByText('message text')).not.toThrow();
  });
});

Components

<!-- TestMyComponent.svelte -->
<script lang="ts">
  import MyComponent from './MyComponent.svelte';
</script>

<MyComponent>message text</MyComponent>
<!-- MyComponent.svelte -->
<p in:slide|global>
  <slot />
</p>

Error log

TypeError: element.animate is not a function
   in MyComponent.svelte
   in MyComponent.test.svelte

 ❯ animate ../../node_modules/.pnpm/[email protected]/node_modules/svelte/src/internal/client/dom/elements/transitions.js:377:26
    375|   // for bidirectional transitions, we start from the current position,
    376|   // rather than doing a full intro/outro
    377|   var t1 = counterpart?.t() ?? 1 - t2;
       |                          ^
    378|   counterpart?.abort();

Package versions

"svelte": "^5.5.3",
"vitest": "^2.1.8",
"@testing-library/svelte": "^5.2.6",

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions