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: only throwing errors for major version changes #425

Merged
merged 6 commits into from
Apr 25, 2023
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
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];
}
gregjopa marked this conversation as resolved.
Show resolved Hide resolved

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