Skip to content

Commit

Permalink
fix: only throw errors for major version changes (#425)
Browse files Browse the repository at this point in the history
Update existing error handling logic to only throw errors when the major version number
is different between the parent and child windows.

This assumes that minor and patch releases make no breaking changes to post message communication.
  • Loading branch information
oscarleonnogales authored and gregjopa committed Apr 25, 2023
1 parent a2b12c8 commit 57e8989
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/child/child.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ function destroy(): ZalgoPromise<void> {
});
}

// Compares the first numerical value of the parent and child versions of zoid,
// ensuring that an error is only thrown when major versions of Zoid do not match.
// Additionally, zoid version strings should be in snake_case format (10_1_0, 10_2_0, 11_0_0, etc.)
function versionCompatabilityCheck(
version1: string,
version2: string
): boolean {
if (!/_/.test(version1) || !/_/.test(version2)) {
throw new Error(
`Versions are in an invalid format (${version1}, ${version2})`
);
}

return version1.split("_")[0] === version2.split("_")[0];
}

export type ChildComponent<P, X> = {|
getProps: () => ChildPropsType<P, X>,
init: () => ZalgoPromise<void>,
Expand All @@ -100,7 +116,7 @@ export function childComponent<P, X, C>(
props: initialProps,
} = payload;

if (version !== __ZOID__.__VERSION__) {
if (!versionCompatabilityCheck(version, __ZOID__.__VERSION__)) {
throw new Error(
`Parent window has zoid version ${version}, child window has version ${__ZOID__.__VERSION__}`
);
Expand Down

0 comments on commit 57e8989

Please sign in to comment.