Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking: rename legacy.componentApi to compatibility.legacyComponent #12295

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sour-tomatoes-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

breaking: rename `legacy.componentApi` to `compatibility.legacyComponent`
2 changes: 1 addition & 1 deletion packages/svelte/messages/client-errors/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

## component_api_invalid_new

> Attempted to instantiate %component% with `new %name%`, which is no longer valid in Svelte 5. If this component is not under your control, set the `legacy.componentApi` compiler option to keep it working. See https://svelte-5-preview.vercel.app/docs/breaking-changes#components-are-no-longer-classes for more information
> Attempted to instantiate %component% with `new %name%`, which is no longer valid in Svelte 5. If this component is not under your control, set the `compatibility.legacyComponent` compiler option to keep it working. See https://svelte-5-preview.vercel.app/docs/breaking-changes#components-are-no-longer-classes for more information

## each_key_duplicate

Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export function analyze_component(root, source, options) {
? true
: (runes ? false : !!options.accessors) ||
// because $set method needs accessors
!!options.legacy?.componentApi,
!!options.compatibility?.legacyComponent,
reactive_statements: new Map(),
binding_groups: new Map(),
slot_names: new Map(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export function client_component(source, analysis, options) {
}
}

if (options.legacy.componentApi) {
if (options.compatibility.legacyComponent) {
component_returned_object.push(
b.init('$set', b.id('$.update_legacy_props')),
b.init(
Expand Down Expand Up @@ -450,7 +450,7 @@ export function client_component(source, analysis, options) {
body.unshift(b.imports([], 'svelte/internal/disclose-version'));
}

if (options.legacy.componentApi) {
if (options.compatibility.legacyComponent) {
body.unshift(b.imports([['createClassComponent', '$$_createClassComponent']], 'svelte/legacy'));
component_block.body.unshift(
b.if(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,7 @@ export function server_component(analysis, options) {
should_inject_props ? [b.id('$$payload'), b.id('$$props')] : [b.id('$$payload')],
component_block
);
if (options.legacy.componentApi) {
if (options.compatibility.legacyComponent) {
body.unshift(b.imports([['render', '$$_render']], 'svelte/server'));
body.push(
component_function,
Expand Down
8 changes: 4 additions & 4 deletions packages/svelte/src/compiler/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ export interface CompileOptions extends ModuleCompileOptions {
/**
* @deprecated Use these only as a temporary solution before migrating your code
*/
legacy?: {
compatibility?: {
/**
* Applies a transformation so that the default export of Svelte files can still be instantiated the same way as in Svelte 4 —
* as a class when compiling for the browser (as though using `createClassComponent(MyComponent, {...})` from `svelte/legacy`)
* or as an object with a `.render(...)` method when compiling for the server
* @default false
*/
componentApi?: boolean;
legacyComponent?: boolean;
};
/**
* An initial sourcemap that will be merged into the final output sourcemap.
Expand Down Expand Up @@ -234,7 +234,7 @@ export type ValidatedCompileOptions = ValidatedModuleCompileOptions &
Required<CompileOptions>,
| keyof ModuleCompileOptions
| 'name'
| 'legacy'
| 'compatibility'
| 'outputFilename'
| 'cssOutputFilename'
| 'sourcemap'
Expand All @@ -244,7 +244,7 @@ export type ValidatedCompileOptions = ValidatedModuleCompileOptions &
outputFilename: CompileOptions['outputFilename'];
cssOutputFilename: CompileOptions['cssOutputFilename'];
sourcemap: CompileOptions['sourcemap'];
legacy: Required<Required<CompileOptions>['legacy']>;
compatibility: Required<Required<CompileOptions>['compatibility']>;
runes: CompileOptions['runes'];
customElementOptions: SvelteOptions['customElement'];
hmr: CompileOptions['hmr'];
Expand Down
8 changes: 6 additions & 2 deletions packages/svelte/src/compiler/validate-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ export const validate_component_options =

immutable: deprecate(w.options_deprecated_immutable, boolean(false)),

legacy: object({
componentApi: boolean(false)
legacy: removed(
'The legacy option has been removed. If you are using this because of legacy.componentApi, use compatibility.legacyComponent instead'
),

compatibility: object({
legacyComponent: boolean(false)
}),

loopGuardTimeout: warn_removed(w.options_removed_loop_guard_timeout),
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte/src/internal/client/dom/legacy/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function bubble_event($$props, event) {
}

/**
* Used to simulate `$on` on a component instance when `legacy.componentApi` is `true`
* Used to simulate `$on` on a component instance when `compatibility.legacyComponent` is `true`
* @param {Record<string, any>} $$props
* @param {string} event_name
* @param {Function} event_callback
Expand All @@ -53,7 +53,7 @@ export function add_legacy_event_listener($$props, event_name, event_callback) {
}

/**
* Used to simulate `$set` on a component instance when `legacy.componentApi` is `true`.
* Used to simulate `$set` on a component instance when `compatibility.legacyComponent` is `true`.
* Needs component accessors so that it can call the setter of the prop. Therefore doesn't
* work for updating props in `$$props` or `$$restProps`.
* @this {Record<string, any>}
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte/src/internal/client/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ export function component_api_changed(parent, method, component) {
}

/**
* Attempted to instantiate %component% with `new %name%`, which is no longer valid in Svelte 5. If this component is not under your control, set the `legacy.componentApi` compiler option to keep it working. See https://svelte-5-preview.vercel.app/docs/breaking-changes#components-are-no-longer-classes for more information
* Attempted to instantiate %component% with `new %name%`, which is no longer valid in Svelte 5. If this component is not under your control, set the `compatibility.legacyComponent` compiler option to keep it working. See https://svelte-5-preview.vercel.app/docs/breaking-changes#components-are-no-longer-classes for more information
* @param {string} component
* @param {string} name
* @returns {never}
*/
export function component_api_invalid_new(component, name) {
if (DEV) {
const error = new Error(`component_api_invalid_new\nAttempted to instantiate ${component} with \`new ${name}\`, which is no longer valid in Svelte 5. If this component is not under your control, set the \`legacy.componentApi\` compiler option to keep it working. See https://svelte-5-preview.vercel.app/docs/breaking-changes#components-are-no-longer-classes for more information`);
const error = new Error(`component_api_invalid_new\nAttempted to instantiate ${component} with \`new ${name}\`, which is no longer valid in Svelte 5. If this component is not under your control, set the \`compatibility.legacyComponent\` compiler option to keep it working. See https://svelte-5-preview.vercel.app/docs/breaking-changes#components-are-no-longer-classes for more information`);

error.name = 'Svelte error';
throw error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { test } from '../../test';

export default test({
compileOptions: {
legacy: {
componentApi: true
compatibility: {
legacyComponent: true
}
},
html: '<button>0</button>',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { test } from '../../test';

export default test({
compileOptions: {
legacy: {
componentApi: true
compatibility: {
legacyComponent: true
}
},

Expand Down
8 changes: 4 additions & 4 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,14 +808,14 @@ declare module 'svelte/compiler' {
/**
* @deprecated Use these only as a temporary solution before migrating your code
*/
legacy?: {
compatibility?: {
/**
* Applies a transformation so that the default export of Svelte files can still be instantiated the same way as in Svelte 4 —
* as a class when compiling for the browser (as though using `createClassComponent(MyComponent, {...})` from `svelte/legacy`)
* or as an object with a `.render(...)` method when compiling for the server
* @default false
*/
componentApi?: boolean;
legacyComponent?: boolean;
};
/**
* An initial sourcemap that will be merged into the final output sourcemap.
Expand Down Expand Up @@ -2631,14 +2631,14 @@ declare module 'svelte/types/compiler/interfaces' {
/**
* @deprecated Use these only as a temporary solution before migrating your code
*/
legacy?: {
compatibility?: {
/**
* Applies a transformation so that the default export of Svelte files can still be instantiated the same way as in Svelte 4 —
* as a class when compiling for the browser (as though using `createClassComponent(MyComponent, {...})` from `svelte/legacy`)
* or as an object with a `.render(...)` method when compiling for the server
* @default false
*/
componentApi?: boolean;
legacyComponent?: boolean;
};
/**
* An initial sourcemap that will be merged into the final output sourcemap.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ import App from './App.svelte'
export default app;
```

If this component is not under your control, you can use the `legacy.componentApi` compiler option for auto-applied backwards compatibility, which means code using `new Component(...)` keeps working without adjustments (note that this adds a bit of overhead to each component). This will also add `$set` and `$on` methods for all component instances you get through `bind:this`.
If this component is not under your control, you can use the `compatibility.legacyComponent` compiler option for auto-applied backwards compatibility, which means code using `new Component(...)` keeps working without adjustments (note that this adds a bit of overhead to each component). This will also add `$set` and `$on` methods for all component instances you get through `bind:this`.

```js
/// svelte.config.js
export default {
compilerOptions: {
legacy: { componentApi: true }
compatibility: { legacyComponent: true }
}
};
```
Expand Down
4 changes: 2 additions & 2 deletions sites/svelte-5-preview/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import adapter from '@sveltejs/adapter-vercel';
/** @type {import('@sveltejs/kit').Config} */
export default {
compilerOptions: {
legacy: {
compatibility: {
// site-kit manually instantiates components inside an action
componentApi: true
legacyComponent: true
}
},
kit: {
Expand Down
Loading