Skip to content

fix: prevent ownership warnings if the fallback of a bindable is used #15720

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 5 commits into from
Apr 10, 2025

Conversation

paoloricciuti
Copy link
Member

Closes #15717

I wonder if there's a better way to do this but i couldn't find one. This seems to work however and I'm not to worried about the weirdness because it's in dev only. WDYT?

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link
Contributor

github-actions bot commented Apr 9, 2025

Playground

pnpm add https://pkg.pr.new/svelte@15720

Copy link

changeset-bot bot commented Apr 9, 2025

🦋 Changeset detected

Latest commit: 24d4df3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

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

@svelte-docs-bot
Copy link

@Ocean-OS
Copy link
Contributor

Ocean-OS commented Apr 9, 2025

I think to avoid unexpected behavior like this, we should either use a (weak?)map of bindable fallback proxies instead of adding a property to each one, or omit the symbol from the proxy when using ownKeys.

@paoloricciuti
Copy link
Member Author

I think to avoid unexpected behavior like this, we should either use a (weak?)map of bindable fallback proxies instead of adding a property to each one, or omit the symbol from the proxy when using ownKeys.

Uh weird it should be non enumerable...this definitely needs fixing. Will do tomorrow

@Ocean-OS
Copy link
Contributor

Ocean-OS commented Apr 9, 2025

Making a property not enumerable doesn't omit it from Reflect.ownKeys (which retrieves all keys, regardless of enumerability or if they're a symbol), so we'd have to specifically remove it from the ownKeys proxy handler.

@dummdidumm
Copy link
Member

dummdidumm commented Apr 10, 2025

What if instead we check if the property is actually in $$props? If not then we can just ignore the warning. No need for any new code in the compiler nor symbols

@paoloricciuti
Copy link
Member Author

What if instead we check if the property is actually in $$props? If not then we can just ignore the warning. No need for any new code in the compiler nor symbols

Dang I knew there was a simpler solution...will fix later!

@paoloricciuti
Copy link
Member Author

@dummdidumm implemented your suggestion 😄

return (
!!get_descriptor(props, prop_name)?.set ||
(is_entry_props && prop_name in props) ||
!(prop_name in props)
Copy link
Member

Choose a reason for hiding this comment

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

While that's all correct the function name now is confusing because it no longer is what this check is about. is_bound_or_unset maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mmm yeah let me change that, even tho I read that as "if it's unset is automatically bound" but maybe it's better to rename it

@paoloricciuti paoloricciuti merged commit 6c97a78 into main Apr 10, 2025
13 checks passed
@paoloricciuti paoloricciuti deleted the ownership-binding-fallback-bindale branch April 10, 2025 11:29
@github-actions github-actions bot mentioned this pull request Apr 10, 2025
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.

From 5.25.9 I suddendly get ownership_invalid_binding warning
3 participants