From 6d288f983a14e7580050b4d08ca78d7b555f8ec4 Mon Sep 17 00:00:00 2001
From: Daniil Suvorov
Date: Fri, 14 Aug 2026 12:55:25 +0300
Subject: [PATCH] docs: handle challenge
---
packages/vkui/.storybook/challenge.ts | 40 ++++++++++++++++++++++
packages/vkui/.storybook/manager-head.html | 34 ++++++++++++++++++
packages/vkui/.storybook/preview.ts | 1 +
website/app/layout.tsx | 26 ++++++++++----
website/inline/challange.js | 30 ++++++++++++++++
website/{ => inline}/uwu.js | 0
6 files changed, 125 insertions(+), 6 deletions(-)
create mode 100644 packages/vkui/.storybook/challenge.ts
create mode 100644 packages/vkui/.storybook/manager-head.html
create mode 100644 website/inline/challange.js
rename website/{ => inline}/uwu.js (100%)
diff --git a/packages/vkui/.storybook/challenge.ts b/packages/vkui/.storybook/challenge.ts
new file mode 100644
index 00000000000..04f5f61e465
--- /dev/null
+++ b/packages/vkui/.storybook/challenge.ts
@@ -0,0 +1,40 @@
+declare global {
+ interface Window {
+ __challengeGuardInstalled?: boolean;
+ }
+}
+
+function install() {
+ if (window.__challengeGuardInstalled) {
+ return;
+ }
+ window.__challengeGuardInstalled = true;
+
+ const observer = new PerformanceObserver((list) => {
+ list.getEntries().forEach((entry) => {
+ if (!(entry instanceof PerformanceResourceTiming)) {
+ return;
+ }
+
+ entry.serverTiming.forEach((serverEntry) => {
+ if (serverEntry.name !== 'challenge') {
+ return;
+ }
+
+ const urlEntry = new URL(entry.name);
+
+ const redirect = window.location.pathname + window.location.search;
+ const challenge =
+ urlEntry.origin + serverEntry.description + '?redirect=' + encodeURIComponent(redirect);
+
+ window.location.href = challenge;
+ });
+ });
+ });
+
+ ['navigation', 'resource'].forEach((type) => observer.observe({ type, buffered: true }));
+}
+
+install();
+
+export {};
diff --git a/packages/vkui/.storybook/manager-head.html b/packages/vkui/.storybook/manager-head.html
new file mode 100644
index 00000000000..91940f3c83d
--- /dev/null
+++ b/packages/vkui/.storybook/manager-head.html
@@ -0,0 +1,34 @@
+
\ No newline at end of file
diff --git a/packages/vkui/.storybook/preview.ts b/packages/vkui/.storybook/preview.ts
index 0661691865a..508c889fc30 100644
--- a/packages/vkui/.storybook/preview.ts
+++ b/packages/vkui/.storybook/preview.ts
@@ -1,3 +1,4 @@
+import './challenge';
import { spyOn } from 'storybook/test';
import type { Preview } from '@storybook/react';
import { BREAKPOINTS } from '../src/lib/adaptivity';
diff --git a/website/app/layout.tsx b/website/app/layout.tsx
index a1349cbc297..fcd6b7561ae 100644
--- a/website/app/layout.tsx
+++ b/website/app/layout.tsx
@@ -13,10 +13,28 @@ import type { Metadata } from 'next';
import type { PageMapItem } from 'nextra';
import { getPageMap } from 'nextra/page-map';
import { PlaygroundStoreProvider } from '@/providers/playgroundStoreProvider';
-import uwuCode from '../uwu.js?raw';
+import challengeCode from '../inline/challange.js?raw';
+import uwuCode from '../inline/uwu.js?raw';
import { FooterLinks, RedirectHandler, Versions } from './_components';
import '@vkontakte/vkui-docs-theme/styles.css';
+const inlineCodeArray = [challengeCode, uwuCode];
+
+function InlineCode() {
+ return (
+ <>
+ {inlineCodeArray.map((code, index) => (
+
+ ))}
+ >
+ );
+}
+
export const metadata: Metadata = {
title: {
default: 'VKUI – React UI Kit',
@@ -84,11 +102,7 @@ const RootLayout: React.FC<{ children: React.ReactNode }> = async ({ children })
-
+
{
+ list.getEntries().forEach((entry) => {
+ if (!(entry instanceof PerformanceResourceTiming)) {
+ return;
+ }
+
+ entry.serverTiming.forEach((serverEntry) => {
+ if (serverEntry.name !== 'challenge') {
+ return;
+ }
+
+ const urlEntry = new URL(entry.name);
+
+ const redirect = window.location.pathname + window.location.search;
+ const challenge =
+ urlEntry.origin + serverEntry.description + '?redirect=' + encodeURIComponent(redirect);
+
+ window.location.href = challenge;
+ });
+ });
+ });
+
+ ['navigation', 'resource'].forEach((type) => observer.observe({ type, buffered: true }));
+})();
diff --git a/website/uwu.js b/website/inline/uwu.js
similarity index 100%
rename from website/uwu.js
rename to website/inline/uwu.js