uikit-v1.6.2-appheader-remote-build-fixed-complete
This commit is contained in:
parent
a47bd58379
commit
b4a828434e
@ -8,8 +8,9 @@ and not embedded as Base64 inside `AppHeader.js`.
|
||||
|
||||
The remote module source `src/remote/ui/AppHeader/AppHeader.remote.jsx`
|
||||
references the original via `new URL("../../../assets/bi-logo.webp", import.meta.url)`.
|
||||
The standard `vite build --mode remote` emits this original image as a
|
||||
separate asset and rewrites that URL to the emitted asset path.
|
||||
That original Vite source reference actually became Base64 in a library build.
|
||||
**Fixed in v1.6.2:** `build:remote` now runs `scripts/build-app-header-remote.mjs`
|
||||
after Vite and writes a separate original `bi-logo.webp` beside the output JS.
|
||||
|
||||
For **prebuilt files in this ZIP**, the original image is copied byte-for-byte to
|
||||
`dist/remote/bi-logo.webp` and the prebuilt JS points to that same-directory file.
|
||||
@ -20,8 +21,8 @@ AppHeader.js
|
||||
bi-logo.webp
|
||||
```
|
||||
|
||||
If rebuilding with Vite, deploy the asset path emitted by Vite instead
|
||||
(`dist/remote/assets/...webp`), alongside the remote module.
|
||||
For v1.6.2 and later, running `build:remote` produces these same two
|
||||
files automatically. Deploy them together.
|
||||
|
||||
## Behavior
|
||||
|
||||
|
||||
33
APPHEADER_REMOTE_BUILD_FIX_1.6.2.md
Normal file
33
APPHEADER_REMOTE_BUILD_FIX_1.6.2.md
Normal file
@ -0,0 +1,33 @@
|
||||
# UI Kit v1.6.2 — Fix AppHeader Remote production build
|
||||
|
||||
## Root cause
|
||||
|
||||
Vite's library mode (`build.lib`) inlines static image assets even when
|
||||
`assetsInlineLimit` is lower than the asset size. Consequently, the standard
|
||||
`vite build --mode remote` in v1.6.1 replaced the small prebuilt AppHeader.js
|
||||
with a ~95 KiB JS module embedding the 64,536-byte original BI image as Base64.
|
||||
The compiled JS had the new `biLogoOptimize` logic, but the large embedded
|
||||
image was downloaded before the header could run. This was a build defect,
|
||||
not necessarily a stale CDN cache or outdated destination project.
|
||||
|
||||
## Fix
|
||||
|
||||
- `build:remote` now ends by invoking `scripts/build-app-header-remote.mjs`.
|
||||
- The script combines the existing standalone AppHeader source with the unchanged
|
||||
`processImage` function, so the published remote JS needs no shared JS chunk.
|
||||
- It copies the **exact original** `src/assets/bi-logo.webp` to
|
||||
`dist/remote/bi-logo.webp`; no thumbnail or recompression is involved.
|
||||
- The default logo URL resolves relative to the remote JS file at runtime.
|
||||
- The script checks both for accidental Base64 embedding and asset identity.
|
||||
- The optional BI `optimize` and fallback behaviors remain unchanged.
|
||||
|
||||
## Deploy both files
|
||||
|
||||
```text
|
||||
dist/remote/AppHeader.js
|
||||
dist/remote/bi-logo.webp
|
||||
```
|
||||
|
||||
After `npm run build:remote`, validate that the JS is small and contains no
|
||||
`data:image/webp;base64`; then deploy **both files** and invalidate cached JS.
|
||||
The new patch release is `1.6.2`. No host component API changes are required.
|
||||
@ -1453,7 +1453,7 @@ function ExampleAppHeader() {
|
||||
|
||||
**UI Kit v1.6.0 — بهینهسازی لوگوی BI:** حالا `AppHeader.Bi` نیز پراپ اختیاری `optimize` دارد. همانند `AppHeader.Logo`، در مرورگر URL تصویر را (در صورت نیاز با origin سامانه مقصد) کامل میکند، ابعاد نمایش را با `ResizeObserver` اندازه میگیرد و تصویر کوچکشده WebP را از `https://img.d.aiengines.ir` درخواست میکند. در صورت خطای سرویس، تصویر اصلی نمایش داده میشود. اگر `optimize` پاس داده نشود، هیچ تبدیلی روی URL انجام نمیشود. API مستقیم `biLogoOptimize` نیز پشتیبانی میشود: `<AppHeader biLogoOptimize biLogoSrc="..." />`.
|
||||
|
||||
**اصلاح v1.6.1 — لوگوی اصلی، بدون Thumbnail:** تصویر BI از همان سورس اصلی `src/assets/bi-logo.webp` با ابعاد ۵۰۰×۵۰۰ استفاده میکند؛ فایل ۱۹۲×۱۹۲ `bi-logo-header.webp` حذف شده است. در حالت `<AppHeader.Bi optimize />`، درست مانند `<AppHeader.Logo optimize />`، تصویر اصلی به سرویس `processImage` ارسال میشود و نسخه متناسب با اندازه نمایش (`q:100` و WebP) در لحظه درخواست میشود. در صورت خطا، همان تصویر اصلی بهعنوان Fallback نمایش داده میشود. اگر `optimize` نباشد، تصویر اصلی بدون کوچکسازی درخواست میشود. فایل `AppHeader.js` همچنان تصویر را Base64 نمیکند و سبک باقی میماند. برای استقرار نسخه پیشساخته، فایلهای `dist/remote/AppHeader.js` و `dist/remote/bi-logo.webp` را کنار هم روی سرور Remote منتشر کنید؛ با Build رسمی Vite، فایل اصلی بهعنوان Asset هشدار خروجی تولید میشود و باید همراه خروجی JS منتشر شود. تعویض پکیج بدون انتشار فایل Remote کافی نیست.
|
||||
**اصلاح v1.6.1 — لوگوی اصلی، بدون Thumbnail:** تصویر BI از همان سورس اصلی `src/assets/bi-logo.webp` با ابعاد ۵۰۰×۵۰۰ استفاده میکند؛ فایل ۱۹۲×۱۹۲ `bi-logo-header.webp` حذف شده است. در حالت `<AppHeader.Bi optimize />`، درست مانند `<AppHeader.Logo optimize />`، تصویر اصلی به سرویس `processImage` ارسال میشود و نسخه متناسب با اندازه نمایش (`q:100` و WebP) در لحظه درخواست میشود. در صورت خطا، همان تصویر اصلی بهعنوان Fallback نمایش داده میشود. اگر `optimize` نباشد، تصویر اصلی بدون کوچکسازی درخواست میشود. فایل `AppHeader.js` همچنان تصویر را Base64 نمیکند و سبک باقی میماند. برای استقرار نسخه پیشساخته، فایلهای `dist/remote/AppHeader.js` و `dist/remote/bi-logo.webp` را کنار هم روی سرور Remote منتشر کنید؛ در نسخه 1.6.2، خروجی نهایی `build:remote` با مرحله اختصاصی `build-app-header-remote.mjs` ساخته میشود و فایل اصلی `bi-logo.webp` بدون تغییر کنار `AppHeader.js` کپی میشود؛ Vite بهتنهایی در حالت Library فایل تصویر را Base64 میکند. تعویض پکیج بدون انتشار فایل Remote کافی نیست.
|
||||
|
||||
نمونه استفاده: `<AppHeader.Bi optimize />` برای لوگوی پیشفرض یا `<AppHeader.Bi src="/bi.svg" optimize />` برای تصویر سفارشی. در `AppHeader.Bi` بدون optimize و در `AppHeader.Logo` بدون optimize هیچ تغییری در منطق بهینهسازی اعمال نشده است. مقایسه در دمو: `dist/remote/AppHeader-demo.html`.
|
||||
|
||||
@ -1820,3 +1820,8 @@ function Application({ getAccessToken, currentUserId }) {
|
||||
شناسه کاربر باید در پاسخ `my_user` در `response.id` بهشکل UUID معتبر باشد. الگوریتم Codec و الگوی Canvas از SDK ارسالی حفظ شدهاند. این ابزار آزمایشی و قابل حذف با DevTools است؛ اطلاعات UUID از اسکرینشات قابل بازیابیاند و واترمارک اثبات نمیکند چه کسی تصویر را گرفته یا منتشر کرده است. برخی حالتهای fullscreen/iframe، crop، فشردهسازی و عکس از نمایشگر ممکن است بازیابی را مختل کنند. در هر سامانه یک Watermark نصب کنید؛ استفاده از چند Canvas موازی توصیه نمیشود.
|
||||
|
||||
**انتشار:** ماژول داخل خود پکیج `uikit/watermark` قرار دارد و به انتشار فایل روی سرور Remote UI نیاز ندارد. بعد از انتشار تگ `v1.5.0` و نصب در سامانه مقصد، از این مسیر import کنید.
|
||||
|
||||
|
||||
### اصلاح v1.6.2 — جلوگیری از Base64 در Build واقعی AppHeader
|
||||
|
||||
در حالت `build.lib` در Vite، حتی با `assetsInlineLimit: 8192` نیز تصویر BI در JavaScript جاسازی میشد و حجم `AppHeader.js` بعد از `build:remote` دوباره به حدود ۹۵ کیلوبایت میرسید. اکنون `build:remote` در انتها اسکریپت `scripts/build-app-header-remote.mjs` را اجرا میکند تا خود هدر بهصورت Remote مستقل از سورس ساخته شود و فایل اصلی `src/assets/bi-logo.webp` بایتبهبایت به `dist/remote/bi-logo.webp` منتقل شود. خروجی نهایی به Image Base64 وابسته نیست. برای انتشار باید **هم** `dist/remote/AppHeader.js` **و هم** `dist/remote/bi-logo.webp` روی سرور قرار گیرند.
|
||||
|
||||
344
dist/remote/AppHeader.js
vendored
344
dist/remote/AppHeader.js
vendored
File diff suppressed because one or more lines are too long
BIN
dist/remote/bi-logo.webp
vendored
Normal file
BIN
dist/remote/bi-logo.webp
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 63 KiB |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "uikit",
|
||||
"version": "1.5.0",
|
||||
"version": "1.6.2",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.js",
|
||||
@ -152,7 +152,7 @@
|
||||
"dev:header": "vite",
|
||||
"build": "yarn build:lib && yarn build:remote && yarn build:demo && yarn copy-types",
|
||||
"build:lib": "vite build && node scripts/mark-provider-client.mjs",
|
||||
"build:remote": "vite build --mode remote && node scripts/build-bi-image-remote.mjs",
|
||||
"build:remote": "vite build --mode remote && node scripts/build-bi-image-remote.mjs && node scripts/build-app-header-remote.mjs",
|
||||
"build:demo": "vite build --mode demo",
|
||||
"copy-types": "yarn copy-index-types && yarn copy-utils-types && yarn copy-core-types && yarn copy-layout-types && yarn copy-remote-ui-types && yarn copy-remote-ui-app-header-types && yarn copy-remote-ui-app-sidebar-types && yarn copy-remote-ui-segmented-selector-types && node scripts/copy-provider-types.mjs && yarn copy-remote-ui-bi-image-types",
|
||||
"copy-index-types": "cp src/index.d.ts dist/index.d.ts",
|
||||
|
||||
46
scripts/build-app-header-remote.mjs
Normal file
46
scripts/build-app-header-remote.mjs
Normal file
@ -0,0 +1,46 @@
|
||||
import { copyFile, mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
// Vite library mode inlines images regardless of assetsInlineLimit. Always
|
||||
// regenerate the final remote AppHeader after Vite using its canonical source,
|
||||
// and ship the original BI image as a separate file next to AppHeader.js.
|
||||
const root = fileURLToPath(new URL("../", import.meta.url));
|
||||
const sourcePath = join(root, "src/remote/ui/AppHeader/AppHeader.remote.jsx");
|
||||
const utilityPath = join(root, "src/utils/images.js");
|
||||
const originalLogoPath = join(root, "src/assets/bi-logo.webp");
|
||||
const outputDir = join(root, "dist/remote");
|
||||
const outputJsPath = join(outputDir, "AppHeader.js");
|
||||
const outputLogoPath = join(outputDir, "bi-logo.webp");
|
||||
|
||||
const source = await readFile(sourcePath, "utf8");
|
||||
const utility = await readFile(utilityPath, "utf8");
|
||||
const utilityImport = 'import { processImage } from "../../../utils/images.js";';
|
||||
const utilityExport = "export const processImage =";
|
||||
const runtimeLogoPath = 'new URL(DEFAULT_BI_LOGO_FILE, import.meta.url).href';
|
||||
|
||||
if (source.split(utilityImport).length !== 2 || !utility.includes(utilityExport)) {
|
||||
throw new Error("AppHeader or images utility changed: update its remote builder.");
|
||||
}
|
||||
if (!source.includes(runtimeLogoPath) || !source.includes('const DEFAULT_BI_LOGO_FILE = "bi-logo.webp";')) {
|
||||
throw new Error("AppHeader must resolve the original BI logo beside its remote module.");
|
||||
}
|
||||
if (/\bimport\s+(?!\()/m.test(source.replace(utilityImport, ""))) {
|
||||
throw new Error("AppHeader gained an additional import: update the remote builder.");
|
||||
}
|
||||
|
||||
const js = `${utility.replace(utilityExport, "const processImage =").trim()}\n\n${source.replace(utilityImport, "").trim()}\n`;
|
||||
if (/data:image\/[^;]+;base64/i.test(js)) {
|
||||
throw new Error("AppHeader output unexpectedly contains an embedded image.");
|
||||
}
|
||||
|
||||
await mkdir(outputDir, { recursive: true });
|
||||
await copyFile(originalLogoPath, outputLogoPath);
|
||||
await writeFile(outputJsPath, js, "utf8");
|
||||
|
||||
const original = await readFile(originalLogoPath);
|
||||
const shipped = await readFile(outputLogoPath);
|
||||
if (!original.equals(shipped)) {
|
||||
throw new Error("Remote BI logo differs from the canonical source asset.");
|
||||
}
|
||||
console.log(`AppHeader Remote ready: ${Buffer.byteLength(js)} JS bytes, ${shipped.length} original logo bytes`);
|
||||
@ -5,10 +5,11 @@ import { processImage } from "../../../utils/images.js";
|
||||
// Font family is inherited from the host application; all other visual styles stay isolated.
|
||||
// The component is rendered as an isolated Web Component with Shadow DOM.
|
||||
|
||||
// Always optimize from the original 500×500 BI logo, never from a resized thumbnail.
|
||||
// Vite emits this asset separately and rewrites the URL relative to the remote bundle.
|
||||
// The source of truth is src/assets/bi-logo.webp (also used by the local demo).
|
||||
const DEFAULT_BI_LOGO = new URL("../../../assets/bi-logo.webp", import.meta.url).href;
|
||||
// Use the original 500×500 src/assets/bi-logo.webp, never a thumbnail.
|
||||
// Keep the filename indirect: Vite library builds inline otherwise static new URL() assets.
|
||||
// The AppHeader post-build script copies the original next to the remote module.
|
||||
const DEFAULT_BI_LOGO_FILE = "bi-logo.webp";
|
||||
const DEFAULT_BI_LOGO = new URL(DEFAULT_BI_LOGO_FILE, import.meta.url).href;
|
||||
|
||||
const DEFAULT_BI_TEXT =
|
||||
"موسسه تولید سیستم های خبره و هوشمند اسلامی باقرالعلوم(ع)";
|
||||
|
||||
@ -110,8 +110,12 @@ test('default BI logo ships as the exact original 500×500 image, not Base64 or
|
||||
assert.equal(source.length, 64_536);
|
||||
assert.equal(fs.existsSync(path.join(root, 'dist/remote/bi-logo-header.webp')), false, 'thumbnail must not ship');
|
||||
const remoteSource = fs.readFileSync(path.join(root, 'src/remote/ui/AppHeader/AppHeader.remote.jsx'), 'utf8');
|
||||
assert.match(remoteSource, /new URL\("\.\.\/\.\.\/\.\.\/assets\/bi-logo\.webp", import\.meta\.url\)/);
|
||||
assert.match(fs.readFileSync(path.join(root, 'dist/remote/AppHeader.js'), 'utf8'), /new URL\("\.\/bi-logo\.webp", import\.meta\.url\)/);
|
||||
assert.match(remoteSource, /new URL\(DEFAULT_BI_LOGO_FILE, import\.meta\.url\)/);
|
||||
assert.match(remoteSource, /const DEFAULT_BI_LOGO_FILE = "bi-logo\.webp"/);
|
||||
const shippedJs = fs.readFileSync(path.join(root, 'dist/remote/AppHeader.js'), 'utf8');
|
||||
assert.match(shippedJs, /new URL\(DEFAULT_BI_LOGO_FILE, import\.meta\.url\)/);
|
||||
assert.doesNotMatch(shippedJs, /data:image\/[^;]+;base64/);
|
||||
assert.doesNotMatch(shippedJs, /^import\s/m, 'AppHeader remote should remain self-contained');
|
||||
assert.ok(fs.statSync(path.join(root,'dist/remote/AppHeader.js')).size < 20_000);
|
||||
header.disconnectedCallback();
|
||||
});
|
||||
@ -166,3 +170,15 @@ test('default BI optimize selects original file as its input and keeps remote fi
|
||||
assert.doesNotMatch(bi.src, /bi-logo-header|data:image/);
|
||||
header.disconnectedCallback();
|
||||
});
|
||||
|
||||
|
||||
test('regular build:remote always rebuilds AppHeader from source and copies its original logo', () => {
|
||||
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
||||
assert.match(pkg.scripts['build:remote'], /vite build --mode remote.*build-app-header-remote\.mjs/);
|
||||
assert.equal(pkg.version, '1.6.2');
|
||||
const builder = fs.readFileSync(path.join(root, 'scripts/build-app-header-remote.mjs'), 'utf8');
|
||||
assert.match(builder, /src\/assets\/bi-logo\.webp/);
|
||||
assert.match(builder, /dist\/remote/);
|
||||
assert.match(builder, /copyFile\(originalLogoPath, outputLogoPath\)/);
|
||||
assert.match(builder, /writeFile\(outputJsPath, js/);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user