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

fix(track): don't throw on revoked proxies @W-17739481 #5192

Merged
merged 1 commit into from
Feb 5, 2025
Merged
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
16 changes: 15 additions & 1 deletion packages/@lwc/engine-core/src/framework/mutation-logger.ts
Original file line number Diff line number Diff line change
@@ -60,6 +60,18 @@ function safelyCallGetter(target: any, key: PropertyKey) {
}
}

function isRevokedProxy(target: object) {
try {
// `str in obj` will never throw for normal objects or active proxies,
// but the operation is not allowed for revoked proxies
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
'' in target;
return false;
} catch (_) {
return true;
}
}

/**
* Flush all the logs we've written so far and return the current logs.
*/
@@ -126,7 +138,9 @@ export function trackTargetForMutationLogging(key: PropertyKey, target: any) {
// Guard against recursive objects - don't traverse forever
return;
}
if (isObject(target) && !isNull(target)) {

// Revoked proxies (e.g. window props in LWS sandboxes) throw an error if we try to track them
if (isObject(target) && !isNull(target) && !isRevokedProxy(target)) {
// only track non-primitives; others are invalid as WeakMap keys
targetsToPropertyKeys.set(target, key);

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<x-component>
<template shadowrootmode="open">
I should render!
</template>
</x-component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-component';
export { default } from 'x/component';
export * from 'x/component';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
I should render!
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { LightningElement, track } from 'lwc';
import tmpl from './component.html';

const { revoke, proxy } = Proxy.revocable({}, {});
revoke();

export default class Rehydration extends LightningElement {
// Doesn't need to be used, just needs to be tracked; see W-17739481
@track reactive = proxy;

connectedCallback() {
Promise.resolve().then(() => {
this.reactive = 1;
});
}

render() {
if (!this.rendered) {
this.rendered = true;
} else {
throw new Error('Reactivity should be disabled on SSR.');
}

return tmpl;
}
}