Skip to content

Commit

Permalink
remove document getter caching
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Oct 5, 2021
1 parent 09f65ba commit 100aa5c
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 32 deletions.
2 changes: 0 additions & 2 deletions scripts/minify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ function managlePropsPlugin(): Plugin {
$currentScriptUrl$: '',
$data$: '',
$documentCompatMode$: '',
$documentCookie$: '',
$documentReadyState$: '',
$documentReferrer$: '',
$documentTitle$: '',
$errors$: '',
$firstScriptId$: '',
$forward$: '',
Expand Down
2 changes: 0 additions & 2 deletions src/lib/sandbox/messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ export const onMessageFromWebWorker = (
$parentWinId$: winCtx.$parentWinId$,
$config$: winCtx.$config$ || {},
$documentCompatMode$: doc.compatMode,
$documentCookie$: doc.cookie,
$documentReadyState$: doc.readyState,
$documentReferrer$: doc.referrer,
$documentTitle$: doc.title,
$firstScriptId$: getAndSetInstanceId(winCtx, doc.querySelector('script')),
$htmlConstructors$: Object.getOwnPropertyNames(win).filter((c) => c.startsWith('HTML')),
$interfaces$: readMainInterfaces(win, doc),
Expand Down
2 changes: 0 additions & 2 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ export interface InitWebWorkerData {
$parentWinId$: number;
$config$: PartytownConfig;
$documentCompatMode$: string;
$documentCookie$: string;
$documentReadyState$: string;
$documentReferrer$: string;
$documentTitle$: string;
$firstScriptId$: number;
$htmlConstructors$: string[];
$interfaces$: InterfaceInfo[];
Expand Down
9 changes: 2 additions & 7 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ export const logWorker = (msg: string) => {
}
};

export const logWorkerGetter = (
target: any,
memberPath: string[],
rtn: any,
isCached?: boolean
) => {
export const logWorkerGetter = (target: any, memberPath: string[], rtn: any) => {
if (debug && webWorkerCtx.$config$.logGetters) {
try {
if (target && target[WinIdKey] !== webWorkerCtx.$winId$) {
Expand All @@ -72,7 +67,7 @@ export const logWorkerGetter = (
`Get ${logTargetProp(target, AccessType.Get, memberPath)}, returned: ${logValue(
memberPath,
rtn
)}${isCached ? ' (cached)' : ''}`
)} `
);
} catch (e) {}
}
Expand Down
22 changes: 3 additions & 19 deletions src/lib/web-worker/worker-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ export class HTMLDocument extends HTMLElement {
return webWorkerCtx.$documentCompatMode$;
}

get cookie() {
logWorkerGetter(this, ['cookie'], webWorkerCtx.$documentCookie$, true);
return webWorkerCtx.$documentCookie$;
}
set cookie(cookie: string) {
setter(this, ['cookie'], (webWorkerCtx.$documentCookie$ = cookie));
}

createElement(tagName: string) {
tagName = toUpper(tagName);

Expand Down Expand Up @@ -116,7 +108,7 @@ export class HTMLDocument extends HTMLElement {
}

get location() {
logWorkerGetter(this, ['location'], webWorkerCtx.$location$, true);
logWorkerGetter(this, ['location'], webWorkerCtx.$location$);
return webWorkerCtx.$location$;
}
set location(url: any) {
Expand All @@ -136,23 +128,15 @@ export class HTMLDocument extends HTMLElement {
if (webWorkerCtx.$documentReadyState$ !== 'complete') {
webWorkerCtx.$documentReadyState$ = getter(this, ['readyState']);
} else {
logWorkerGetter(this, ['readyState'], webWorkerCtx.$documentReadyState$, true);
logWorkerGetter(this, ['readyState'], webWorkerCtx.$documentReadyState$);
}
return webWorkerCtx.$documentReadyState$;
}

get referrer() {
logWorkerGetter(this, ['referrer'], webWorkerCtx.$documentReferrer$, true);
logWorkerGetter(this, ['referrer'], webWorkerCtx.$documentReferrer$);
return webWorkerCtx.$documentReferrer$;
}

get title() {
logWorkerGetter(this, ['title'], webWorkerCtx.$documentTitle$, true);
return webWorkerCtx.$documentTitle$;
}
set title(value: string) {
setter(this, ['title'], (webWorkerCtx.$documentTitle$ = value));
}
}

export class WorkerDocumentElementChild extends HTMLElement {
Expand Down

1 comment on commit 100aa5c

@vercel
Copy link

@vercel vercel bot commented on 100aa5c Oct 5, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.