Skip to content

breaking: overhaul proxies, remove $state.is #12916

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 22 commits into from
Aug 20, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
tweak
  • Loading branch information
Rich-Harris committed Aug 20, 2024
commit f914df732e7a47cafef1ce9c52c690af812d7306
13 changes: 5 additions & 8 deletions packages/svelte/src/internal/client/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ export function proxy(value, parent = null, prev) {
e.state_descriptors_fixed();
Copy link
Member

Choose a reason for hiding this comment

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

would be good to have a comment here explaining why we have this restriction

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the comment - reading up on the invariants, can we relax/change this validation? IIUC we only need to disallow non-configurable properties, because they need to appear as such on the target, too. On the other hand, we cannot allow it at all if the target is no extensible and doesn't contain this property

Copy link
Contributor

Choose a reason for hiding this comment

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

The invariant is correct. We also can’t support non enumerable properties or non-writable because then we need extra overhead to store the extra descriptor info per lookup. See the pr that this came from for context.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough - for future reference, this is where it original came up: #12847 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for that, was on mobile earlier so couldn't link it.

}

var value = descriptor.value;

var s = sources.get(prop);

if (s === undefined) {
s = source(value);
s = source(descriptor.value);
sources.set(prop, s);
} else {
set(s, proxy(value, metadata));
set(s, proxy(descriptor.value, metadata));
}

return true;
Expand Down Expand Up @@ -132,10 +131,7 @@ export function proxy(value, parent = null, prev) {

if (descriptor && 'value' in descriptor) {
var s = sources.get(prop);

if (s) {
descriptor.value = get(s);
}
if (s) descriptor.value = get(s);
} else if (descriptor === undefined) {
var source = sources.get(prop);
var value = source?.v;
Expand Down Expand Up @@ -173,6 +169,7 @@ export function proxy(value, parent = null, prev) {
s = source(has ? proxy(target[prop], metadata) : UNINITIALIZED);
sources.set(prop, s);
}

var value = get(s);
if (value === UNINITIALIZED) {
return false;
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy