Skip to content

Commit

Permalink
fix(venmo): window name (#443)
Browse files Browse the repository at this point in the history
* fix(venmo): window name

* chore(venmo): refactor
  • Loading branch information
mnicpt authored Oct 30, 2023
1 parent 3b6f24b commit 02bcaab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/child/child.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { normalizeChildProps } from "./props";
export type ChildExportsType<P> = {|
updateProps: CrossDomainFunctionType<[PropsType<P>], void>,
close: CrossDomainFunctionType<[], void>,
name: string,
|};

export type ChildHelpers<P, X> = {|
Expand Down Expand Up @@ -302,11 +303,13 @@ export function childComponent<P, X, C>(

const init = () => {
return ZalgoPromise.try(() => {
let updatedChildName = "";
if (isSameDomain(parentComponentWindow)) {
updateChildWindowNameWithRef({
componentName: options.name,
parentComponentWindow,
});
updatedChildName =
updateChildWindowNameWithRef({
componentName: options.name,
parentComponentWindow,
}) || "";
}

getGlobal(window).exports = options.exports({
Expand All @@ -317,7 +320,11 @@ export function childComponent<P, X, C>(
markWindowKnown(parentComponentWindow);
watchForClose();

return parentInit({ updateProps, close: destroy });
return parentInit({
name: updatedChildName,
updateProps,
close: destroy,
});
})
.then(() => {
return watchForResize();
Expand Down
7 changes: 5 additions & 2 deletions src/lib/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ type UpdateChildWindowNameWithRefOptions = {|
export function updateChildWindowNameWithRef({
componentName,
parentComponentWindow,
}: UpdateChildWindowNameWithRefOptions) {
}: UpdateChildWindowNameWithRefOptions): ?string {
const { serializedInitialPayload } = parseWindowName(window.name);

const { data, sender, reference, metaData } = crossDomainDeserialize({
Expand Down Expand Up @@ -217,9 +217,12 @@ export function updateChildWindowNameWithRef({
basic: true,
});

window.name = buildChildWindowName({
const childWindowName = buildChildWindowName({
name: componentName,
serializedPayload,
});

window.name = childWindowName;
return childWindowName;
}
}
1 change: 1 addition & 0 deletions src/parent/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ export function parentComponent<P, X, C>({
return ZalgoPromise.try(() => {
currentChildDomain = childDomain;
childComponent = childExports;
currentProxyWin?.setName(childExports?.name);
resolveInitPromise();
clean.register(() => childExports.close.fireAndForget().catch(noop));
});
Expand Down

0 comments on commit 02bcaab

Please sign in to comment.