async function get_navigation_result_from_branch()

in kit/svelteKitCustomClient/client.js [347:430]


	async function get_navigation_result_from_branch({
		url,
		params,
		branch,
		status,
		error,
		route,
		form,
	}) {
		/** @type {import('types').TrailingSlash} */
		let slash = "never";
		for (const node of branch) {
			if (node?.slash !== undefined) slash = node.slash;
		}
		url.pathname = normalize_path(url.pathname, slash);
		// eslint-disable-next-line
		url.search = url.search; // turn `/?` into `/`

		/** @type {import('./types').NavigationFinished} */
		const result = {
			type: "loaded",
			state: {
				url,
				params,
				branch,
				error,
				route,
			},
			props: {
				// @ts-ignore Somehow it's getting SvelteComponent and SvelteComponentDev mixed up
				constructors: compact(branch).map((branch_node) => branch_node.node.component),
			},
		};

		if (form !== undefined) {
			result.props.form = form;
		}

		let data = {};
		let data_changed = !page;

		let p = 0;

		for (let i = 0; i < Math.max(branch.length, current.branch.length); i += 1) {
			const node = branch[i];
			const prev = current.branch[i];

			if (node?.data !== prev?.data) data_changed = true;
			if (!node) continue;

			data = { ...data, ...node.data };

			// Only set props if the node actually updated. This prevents needless rerenders.
			if (data_changed) {
				result.props[`data_${p}`] = data;
			}

			p += 1;
		}

		const page_changed =
			!current.url ||
			url.href !== current.url.href ||
			current.error !== error ||
			(form !== undefined && form !== page.form) ||
			data_changed;

		if (page_changed) {
			result.props.page = {
				error,
				params,
				route: {
					id: route?.id ?? null,
				},
				status,
				url: new URL(url),
				form: form ?? null,
				// The whole page store is updated, but this way the object reference stays the same
				data: data_changed ? data : page.data,
			};
		}

		return result;
	}