Skip to content

chore: add Svelte 5 docs for prefer-destructured-store-props rule #1034

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

Merged
merged 2 commits into from
Jan 26, 2025

Conversation

baseballyama
Copy link
Member

No description provided.

@baseballyama baseballyama marked this pull request as ready for review January 19, 2025 02:55
Copy link

changeset-bot bot commented Jan 19, 2025

⚠️ No Changeset found

Latest commit: 2b69410

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

pkg-pr-new bot commented Jan 19, 2025

Open in Stackblitz

npm i https://pkg.pr.new/eslint-plugin-svelte@1034

commit: 2b69410

@marekdedic
Copy link
Contributor

Why this? You can still use stores with runes?

@baseballyama
Copy link
Member Author

baseballyama commented Jan 20, 2025

Does the performance differ depending on whether the GOOD or BAD syntax is used when Svelte 5 is run in runes mode?

<script>
  /* eslint svelte/prefer-destructured-store-props: "error" */
  import store from './store.js';
  $: ({ foo } = $store);
</script>

<!-- ✓ GOOD -->
{foo}

<!-- ✗ BAD -->
{$store.foo}

Also, since the $ syntax cannot be used in Svelte 5’s runes mode, wouldn’t it be difficult to rewrite to a GOOD form even if this rule reports something?

@marekdedic
Copy link
Contributor

See here, you can use the auto-subscription feature even with runes:
https://svelte.dev/playground/c63358bff2764b158ee7e1f76987cbed?version=5.19.0

As to the efficiency I can't say (I don't know enough of store internals), but if the rule doesn't make sense anymore, it should be disable on Svelte irrespective of whether runes are turned on, right?

@baseballyama
Copy link
Member Author

Further investigation confirmed that using code like the following for stores in Svelte 5 does provide better performance:

let foo = $derived($store.foo)

@baseballyama baseballyama changed the title chore: do not run prefer-destructured-store-props rule on Svelte 5 with runes chore: add Svelte 5 docs for prefer-destructured-store-props rule Jan 26, 2025
@baseballyama
Copy link
Member Author

So I updated the docs instead of changing the config.

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@ota-meshi ota-meshi merged commit cf91d4c into main Jan 26, 2025
18 checks passed
@ota-meshi ota-meshi deleted the chore/prefer-destructured-store-props branch January 26, 2025 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants