Fix infinite hydration loop and stabilize global store synchronization
- Refactored layouts to derive account data from stable props instead of reactive stores. - Wrapped store updates in untrack() with deep equality guards to prevent infinite re-renders. - Resolved duplicate untrack declarations and missing imports across the project. - Added fetch safeguards to Element_data_store to prevent redundant API calls. - Standardized hydration patterns to break circular dependencies during initial load.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
let log_lvl: number = 2;
|
||||
|
||||
// *** Import Svelte specific
|
||||
@@ -29,8 +30,10 @@
|
||||
let { data, children }: Props = $props();
|
||||
|
||||
$effect(() => {
|
||||
$ae_loc.url_origin = data.url.origin;
|
||||
$ae_loc.params = data.params;
|
||||
untrack(() => {
|
||||
$ae_loc.url_origin = data.url.origin;
|
||||
$ae_loc.params = data.params;
|
||||
});
|
||||
|
||||
if (log_lvl > 1) {
|
||||
console.log(`+layout.svelte data:`, data);
|
||||
@@ -39,111 +42,113 @@
|
||||
|
||||
$effect(() => {
|
||||
if (browser) {
|
||||
if (data.url.searchParams.get('uuid')) {
|
||||
$idaa_loc.novi_uuid = data.url.searchParams.get('uuid'); // data.params.uuid;
|
||||
}
|
||||
if (data.url.searchParams.get('email')) {
|
||||
$idaa_loc.novi_email = decodeURIComponent(data.url.searchParams.get('email'));
|
||||
} else {
|
||||
$idaa_loc.novi_email = null;
|
||||
}
|
||||
if (data.url.searchParams.get('full_name')) {
|
||||
$idaa_loc.novi_full_name = decodeURIComponent(data.url.searchParams.get('full_name'));
|
||||
} else {
|
||||
$idaa_loc.novi_full_name = null;
|
||||
}
|
||||
$idaa_loc.novi_admin_li = $ae_loc.site_cfg_json?.novi_admin_li ?? [];
|
||||
$idaa_loc.novi_trusted_li = $ae_loc.site_cfg_json?.novi_trusted_li ?? [];
|
||||
// console.log(`$idaa_loc.novi_uuid:`, $idaa_loc.novi_uuid);
|
||||
// console.log(`$idaa_loc.novi_admin_li:`, $idaa_loc.novi_admin_li);
|
||||
untrack(() => {
|
||||
if (data.url.searchParams.get('uuid')) {
|
||||
$idaa_loc.novi_uuid = data.url.searchParams.get('uuid'); // data.params.uuid;
|
||||
}
|
||||
if (data.url.searchParams.get('email')) {
|
||||
$idaa_loc.novi_email = decodeURIComponent(data.url.searchParams.get('email'));
|
||||
} else {
|
||||
$idaa_loc.novi_email = null;
|
||||
}
|
||||
if (data.url.searchParams.get('full_name')) {
|
||||
$idaa_loc.novi_full_name = decodeURIComponent(data.url.searchParams.get('full_name'));
|
||||
} else {
|
||||
$idaa_loc.novi_full_name = null;
|
||||
}
|
||||
$idaa_loc.novi_admin_li = $ae_loc.site_cfg_json?.novi_admin_li ?? [];
|
||||
$idaa_loc.novi_trusted_li = $ae_loc.site_cfg_json?.novi_trusted_li ?? [];
|
||||
// console.log(`$idaa_loc.novi_uuid:`, $idaa_loc.novi_uuid);
|
||||
// console.log(`$idaa_loc.novi_admin_li:`, $idaa_loc.novi_admin_li);
|
||||
|
||||
// Reminder: super > manager > administrator > trusted > public > authenticated > anonymous
|
||||
// Reminder: super > manager > administrator > trusted > public > authenticated > anonymous
|
||||
|
||||
// NOTE: This is checking if they are in an iframe *and* have a Novi UUID. We ignore the iframe mode for trusted and above (administrators, managers, etc).
|
||||
if (
|
||||
$ae_loc?.iframe &&
|
||||
$idaa_loc?.novi_uuid?.length == 36 &&
|
||||
$idaa_loc?.novi_email?.length > 3 &&
|
||||
$idaa_loc?.novi_full_name?.length > 0
|
||||
) {
|
||||
$ae_loc.access_type = 'authenticated';
|
||||
$ae_loc.super_access = false;
|
||||
$ae_loc.manager_access = false;
|
||||
$ae_loc.administrator_access = false;
|
||||
$ae_loc.trusted_access = false;
|
||||
$ae_loc.public_access = false;
|
||||
$ae_loc.authenticated_access = true;
|
||||
$ae_loc.anonymous_access = true;
|
||||
// NOTE: This is checking if they are in an iframe *and* have a Novi UUID. We ignore the iframe mode for trusted and above (administrators, managers, etc).
|
||||
if (
|
||||
$ae_loc?.iframe &&
|
||||
$idaa_loc?.novi_uuid?.length == 36 &&
|
||||
$idaa_loc?.novi_email?.length > 3 &&
|
||||
$idaa_loc?.novi_full_name?.length > 0
|
||||
) {
|
||||
$ae_loc.access_type = 'authenticated';
|
||||
$ae_loc.super_access = false;
|
||||
$ae_loc.manager_access = false;
|
||||
$ae_loc.administrator_access = false;
|
||||
$ae_loc.trusted_access = false;
|
||||
$ae_loc.public_access = false;
|
||||
$ae_loc.authenticated_access = true;
|
||||
$ae_loc.anonymous_access = true;
|
||||
|
||||
// Resetting these just in case...
|
||||
$idaa_loc.bb.qry__hidden == 'not_hidden';
|
||||
$idaa_loc.bb.qry__enabled == 'enabled';
|
||||
// NOTE: This is sort of temporary while we work on getting Jisti working with IDAA's Novi site.
|
||||
} else if (
|
||||
$ae_loc?.iframe &&
|
||||
$idaa_loc?.novi_uuid?.length == 36
|
||||
) {
|
||||
$ae_loc.access_type = 'authenticated';
|
||||
$ae_loc.super_access = false;
|
||||
$ae_loc.manager_access = false;
|
||||
$ae_loc.administrator_access = false;
|
||||
$ae_loc.trusted_access = false;
|
||||
$ae_loc.public_access = false;
|
||||
$ae_loc.authenticated_access = true;
|
||||
$ae_loc.anonymous_access = true;
|
||||
// Resetting these just in case...
|
||||
$idaa_loc.bb.qry__hidden == 'not_hidden';
|
||||
$idaa_loc.bb.qry__enabled == 'enabled';
|
||||
// NOTE: This is sort of temporary while we work on getting Jisti working with IDAA's Novi site.
|
||||
} else if (
|
||||
$ae_loc?.iframe &&
|
||||
$idaa_loc?.novi_uuid?.length == 36
|
||||
) {
|
||||
$ae_loc.access_type = 'authenticated';
|
||||
$ae_loc.super_access = false;
|
||||
$ae_loc.manager_access = false;
|
||||
$ae_loc.administrator_access = false;
|
||||
$ae_loc.trusted_access = false;
|
||||
$ae_loc.public_access = false;
|
||||
$ae_loc.authenticated_access = true;
|
||||
$ae_loc.anonymous_access = true;
|
||||
|
||||
// Resetting these just in case...
|
||||
$idaa_loc.bb.qry__hidden == 'not_hidden';
|
||||
$idaa_loc.bb.qry__enabled == 'enabled';
|
||||
} else if ($ae_loc?.iframe) {
|
||||
$ae_loc.access_type = 'anonymous';
|
||||
$ae_loc.super_access = false;
|
||||
$ae_loc.manager_access = false;
|
||||
$ae_loc.administrator_access = false;
|
||||
$ae_loc.trusted_access = false;
|
||||
$ae_loc.public_access = false;
|
||||
$ae_loc.authenticated_access = false;
|
||||
$ae_loc.anonymous_access = true;
|
||||
// Resetting these just in case...
|
||||
$idaa_loc.bb.qry__hidden == 'not_hidden';
|
||||
$idaa_loc.bb.qry__enabled == 'enabled';
|
||||
} else if ($ae_loc?.iframe) {
|
||||
$ae_loc.access_type = 'anonymous';
|
||||
$ae_loc.super_access = false;
|
||||
$ae_loc.manager_access = false;
|
||||
$ae_loc.administrator_access = false;
|
||||
$ae_loc.trusted_access = false;
|
||||
$ae_loc.public_access = false;
|
||||
$ae_loc.authenticated_access = false;
|
||||
$ae_loc.anonymous_access = true;
|
||||
|
||||
// Resetting these just in case...
|
||||
$idaa_loc.bb.qry__hidden == 'not_hidden';
|
||||
$idaa_loc.bb.qry__enabled == 'enabled';
|
||||
}
|
||||
|
||||
if ($idaa_loc.novi_uuid) {
|
||||
let flag = false;
|
||||
// NOTE: Check if the novi_uuid is in the novi_admin_li list
|
||||
if ($idaa_loc.novi_admin_li) {
|
||||
if ($idaa_loc.novi_admin_li.includes($idaa_loc.novi_uuid)) {
|
||||
$ae_loc.access_type = 'administrator';
|
||||
$ae_loc.super_access = false;
|
||||
$ae_loc.manager_access = false;
|
||||
$ae_loc.administrator_access = true;
|
||||
$ae_loc.trusted_access = true;
|
||||
$ae_loc.public_access = true;
|
||||
$ae_loc.authenticated_access = true;
|
||||
$ae_loc.anonymous_access = true;
|
||||
|
||||
flag = true;
|
||||
}
|
||||
// Resetting these just in case...
|
||||
$idaa_loc.bb.qry__hidden == 'not_hidden';
|
||||
$idaa_loc.bb.qry__enabled == 'enabled';
|
||||
}
|
||||
|
||||
// NOTE: Check if the novi_uuid is in the novi_trusted_li list
|
||||
if ($idaa_loc.novi_trusted_li) {
|
||||
if ($idaa_loc.novi_trusted_li.includes($idaa_loc.novi_uuid)) {
|
||||
$ae_loc.access_type = 'trusted';
|
||||
$ae_loc.super_access = false;
|
||||
$ae_loc.manager_access = false;
|
||||
$ae_loc.administrator_access = false;
|
||||
$ae_loc.trusted_access = true;
|
||||
$ae_loc.public_access = true;
|
||||
$ae_loc.authenticated_access = true;
|
||||
$ae_loc.anonymous_access = true;
|
||||
if ($idaa_loc.novi_uuid) {
|
||||
let flag = false;
|
||||
// NOTE: Check if the novi_uuid is in the novi_admin_li list
|
||||
if ($idaa_loc.novi_admin_li) {
|
||||
if ($idaa_loc.novi_admin_li.includes($idaa_loc.novi_uuid)) {
|
||||
$ae_loc.access_type = 'administrator';
|
||||
$ae_loc.super_access = false;
|
||||
$ae_loc.manager_access = false;
|
||||
$ae_loc.administrator_access = true;
|
||||
$ae_loc.trusted_access = true;
|
||||
$ae_loc.public_access = true;
|
||||
$ae_loc.authenticated_access = true;
|
||||
$ae_loc.anonymous_access = true;
|
||||
|
||||
flag = true;
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Check if the novi_uuid is in the novi_trusted_li list
|
||||
if ($idaa_loc.novi_trusted_li) {
|
||||
if ($idaa_loc.novi_trusted_li.includes($idaa_loc.novi_uuid)) {
|
||||
$ae_loc.access_type = 'trusted';
|
||||
$ae_loc.super_access = false;
|
||||
$ae_loc.manager_access = false;
|
||||
$ae_loc.administrator_access = false;
|
||||
$ae_loc.trusted_access = true;
|
||||
$ae_loc.public_access = true;
|
||||
$ae_loc.authenticated_access = true;
|
||||
$ae_loc.anonymous_access = true;
|
||||
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user