Browse Source

feat: expose and trigger web ready announcement bridge for entry route navigation

master
mortezaei 1 week ago
parent
commit
ae9c42add0
  1. 6
      src/app/layout.tsx
  2. 9
      src/components/Componentes/entry-route-resolver.tsx
  3. 1
      src/types/window.d.ts

6
src/app/layout.tsx

@ -236,7 +236,7 @@ export default async function RootLayout({
root.dataset.webBootstrap = 'pending'; root.dataset.webBootstrap = 'pending';
} }
// 4. Instant web_ready Announcement
// 4. Instant web_ready Announcement Bridge
function announce() { function announce() {
if (window.__habibWebReadySent || !window.HabibApp || !window.HabibApp.postMessage) return false; if (window.__habibWebReadySent || !window.HabibApp || !window.HabibApp.postMessage) return false;
window.__habibWebReadySent = true; window.__habibWebReadySent = true;
@ -247,13 +247,15 @@ export default async function RootLayout({
return true; return true;
} }
window.__announceHabibWebReady = announce;
function tryAnnounce() { function tryAnnounce() {
if (!announce()) return false; if (!announce()) return false;
setTimeout(function() { setTimeout(function() {
if (root.dataset.webBootstrap === 'pending') { if (root.dataset.webBootstrap === 'pending') {
root.dataset.webBootstrap = 'ready'; root.dataset.webBootstrap = 'ready';
} }
}, 3000);
}, 2500);
return true; return true;
} }

9
src/components/Componentes/entry-route-resolver.tsx

@ -33,7 +33,14 @@ export default function EntryRouteResolver({
useEffect(() => { useEffect(() => {
let isActive = true; let isActive = true;
const announceReady = () => {
if (typeof window !== "undefined") {
window.__announceHabibWebReady?.();
}
};
const goToIntro = () => { const goToIntro = () => {
announceReady();
if (!anonymousEntryVisible) { if (!anonymousEntryVisible) {
router.replace(localizePath("/intro", locale)); router.replace(localizePath("/intro", locale));
} }
@ -49,6 +56,7 @@ export default function EntryRouteResolver({
const cachedEntryPath = getCachedMarriageEntryPath(); const cachedEntryPath = getCachedMarriageEntryPath();
if (cachedEntryPath) { if (cachedEntryPath) {
announceReady();
router.replace(localizePath(cachedEntryPath, locale)); router.replace(localizePath(cachedEntryPath, locale));
return; return;
} }
@ -67,6 +75,7 @@ export default function EntryRouteResolver({
return; return;
} }
announceReady();
router.replace(localizePath(getSubmitPath(profile), locale)); router.replace(localizePath(getSubmitPath(profile), locale));
} catch (error) { } catch (error) {
console.warn("Could not resolve entry route", error); console.warn("Could not resolve entry route", error);

1
src/types/window.d.ts

@ -87,6 +87,7 @@ declare global {
sendToFlutter?: (action: string, data?: Record<string, unknown>) => void; sendToFlutter?: (action: string, data?: Record<string, unknown>) => void;
__HABIB_BOOTSTRAP__?: NonNullable<FlutterResponseEvent["data"]>; __HABIB_BOOTSTRAP__?: NonNullable<FlutterResponseEvent["data"]>;
__habibWebReadySent?: boolean; __habibWebReadySent?: boolean;
__announceHabibWebReady?: () => boolean;
} }
} }

Loading…
Cancel
Save