🐛 Correct UI CSS export and test restore flow

Point the public CSS export to the generated file and test its build.
Clarify component restoration and cover the deleted-file path. Update
integration test documentation for the release bundle.

AI-assisted-by: gpt-6.1-terra
This commit is contained in:
Andrey Antukh 2026-11-24 11:17:48 +00:00
parent 2da9bddd05
commit 5fafca7665
9 changed files with 112 additions and 11 deletions

View File

@ -11,6 +11,7 @@
## Application and schema validation
- `process-changes` validates the change vector once by default, reduces it and then processes collected touched changes; `verify? false` is for callers that already validated. `:set` delegates to `ctn/set-shape-attr`, while `:assign` decodes attrs before per-attr sets. Component touched and copy rules are in `mem:common/components`.
- `:restore-component` restores only the component record: it removes `:objects` and `:deleted`, optionally updates the main instance page, and takes a variant's `:variant-id` from the existing main shape. `prepare-restore-component` generates separate `:add-obj` changes before it to restore the shape tree. Affected-file validation conservatively selects the referenced page for the restore operation itself.
- `shape-tree/add-shape` falls back invalid parents or frames to root and keeps parent `:shapes` a vector without duplicate IDs. `delete-shape` removes descendants from the objects map as well as unlinking the parent; render-wasm deletion has different undo internals.
- Page-object maps can carry metadata indexes. Rebuild them with `start-page-index` / `update-page-index` as appropriate; frontend commit application calls `ctst/update-object-indices` after page changes.
- `update-file` uses change-scoped schema validation: `touched-page-ids` selects pages while non-page data is checked whole. Register new change types as page-writing or file-level; unknown types fall back to the full schema check, which loads every page. Referential integrity and repair are in `mem:common/components`.

View File

@ -1,6 +1,6 @@
# Shared UI package
- `frontend/packages/ui` builds `@penpot/ui`, a React/Vite library separate from the CLJS Design System. Keep reusable primitives independent of the Penpot app store. React and ReactDOM are peers and must remain external to the library build.
- The Vite build emits ESM and type declarations and copies `dist/ui.css` to `frontend/resources/public/css/ui.css`. If shared styles are stale, check the package build and copy before debugging CLJS.
- The Vite build emits ESM and type declarations; the public `@penpot/ui/style.css` export resolves to `dist/ui.css`, which the build also copies to `frontend/resources/public/css/ui.css`. If shared styles are stale, check the package build and copy before debugging CLJS.
- From `frontend/packages/ui`, use `pnpm run build`, `pnpm run watch` or `pnpm run test`. From `frontend/`, `pnpm run build:app:libs` builds app-side packages; `pnpm run build:storybook`, `watch:storybook` and `test:storybook` cover Storybook. Validate changed exports in both the package and consuming app or Storybook.
- Other packages under `frontend/packages/` are workspace dependencies and need not implement behavior in CLJS. App components and the CLJS Design System are described in `mem:frontend/ui-cljs`; text editing is `mem:frontend/text-editor`.

View File

@ -953,9 +953,8 @@
:mod-page
(conj page-ids id)
;; restore-component resurrects a deleted component (touches the
;; component definition) and places its main instance on a page
;; (touches that page's shape tree)
;; Conservatively validate the referenced page as well as the
;; restored component. Separate add-obj changes restore shapes.
:restore-component
(conj page-ids page-id)

View File

@ -652,7 +652,9 @@
(ctkl/mark-component-deleted component-id)))))
(defn restore-component
"Recover a deleted component and all its shapes and put all this again in place."
"Restore a deleted component record, optionally updating its main instance page.
Remove the stored objects and, for a variant, take its variant id from the
existing main instance shape. This does not restore shapes to the page."
[file-data component-id page-id]
(let [update-page? (not (nil? page-id))
component (ctkl/get-component file-data component-id true)
@ -1382,4 +1384,4 @@
(get (:objects container) %2)))
refs
(:shapes shape)))
{})))
{})))

View File

@ -172,6 +172,20 @@
:child-id child-id
:component-id component-id}))
(t/deftest restore-component-alone-does-not-restore-shapes
(let [{:keys [data page-id main-id child-id component-id]} (make-deleted-component)
deleted (ch/process-changes data [{:type :del-obj :id main-id :page-id page-id}])
restored (ch/process-changes deleted [{:type :restore-component
:id component-id :page-id page-id}])
component (get-in restored [:components component-id])]
(t/is (true? (get-in deleted [:components component-id :deleted])))
(t/is (some? (get-in deleted [:components component-id :objects main-id])))
(t/is (not (contains? component :deleted)))
(t/is (not (contains? component :objects)))
(t/is (= page-id (:main-instance-page component)))
(t/is (nil? (get-in restored [:pages-index page-id :objects main-id])))
(t/is (nil? (get-in restored [:pages-index page-id :objects child-id])))))
(t/deftest update-component-does-not-carry-the-objects-map
(let [{:keys [data component-id]} (make-deleted-component)
changes (pcb/update-component (pcb/with-library-data (pcb/empty-changes nil) data)

View File

@ -471,7 +471,7 @@
page-deleted
(:objects page-deleted))
file' (thf/apply-changes file changes)
file' (thf/apply-changes file-deleted changes)
;; ==== Get
component1' (thc/get-component file' :component1 :include-deleted? false)
@ -483,12 +483,20 @@
saved-objects' (:objects component1')]
;; ==== Check
(t/is (true? (:deleted (thc/get-component file-deleted :component1 :include-deleted? true))))
(t/is (nil? (ths/get-shape file-deleted :main1-root)))
(t/is (nil? (ths/get-shape file-deleted :main1-child)))
(t/is (some? component1'))
(t/is (nil? (:deleted component1')))
(t/is (some? copy1-root'))
(t/is (some? main1-root'))
(t/is (some? main1-child'))
(t/is (ctk/main-instance? main1-root'))
(t/is (ctk/main-instance-of? (:id main1-root') (:id page) component1'))
(t/is (= (:id main1-root') (:parent-id main1-child')))
(t/is (some #{(:id main1-child')} (:shapes main1-root')))
(t/is (some #{(:id main1-root')}
(:shapes (get-in (thf/current-page file') [:objects (:parent-id main1-root')]))))
(t/is (nil? saved-objects'))))
(t/deftest test-instantiate-component

View File

@ -303,15 +303,15 @@ Ensure your development environment docker image is up to date.
**NOTE** You can learn more about how to set up, start and stop our development environment [here](/technical-guide/developer/devenv)
#### Release mode
#### Build the frontend
This is not required, but it may be convenient to compile Penpot in release mode before running the tests. This way they will be much quicker and stable. For this, go to the frontend window in the tmux session (<code class="language-bash">Ctrl + b 1</code>), interrupt the watch process with <code class="language-bash">Ctrl + C</code> and type:
Playwright serves the release bundle from <code class="language-bash">frontend/resources/public</code>, not the live sources. Before running the tests, build the frontend from the frontend window in the tmux session (<code class="language-bash">Ctrl + b 1</code>). Interrupt the watch process with <code class="language-bash">Ctrl + C</code> and run:
```bash
./scripts/build
```
Obviously, in this mode if you make changes to the source code, you will need to repeat the build manually each time. It may be useful to use wath mode when debugging a single test, and use release mode to run all the suite.
Rebuild after product code or asset changes, or after switching to a branch with different sources or assets. Changes only to integration specs do not require a rebuild. Watch mode does not replace the release build for these tests.
### Running the integration tests

View File

@ -16,7 +16,7 @@
"import": "./dist/menu.js",
"types": "./dist/menu.d.ts"
},
"./style.css": "./dist/style.css"
"./style.css": "./dist/ui.css"
},
"scripts": {
"watch": "vite build --watch",

View File

@ -0,0 +1,77 @@
import {
cpSync,
mkdtempSync,
mkdirSync,
readFileSync,
rmSync,
symlinkSync,
} from "node:fs";
import { createRequire } from "node:module";
import os from "node:os";
import path from "node:path";
import { spawnSync } from "node:child_process";
import { expect, it } from "vitest";
it("exports the built CSS and copies it to the app", () => {
const packageDir = path.resolve(import.meta.dirname, "..");
const frontendDir = path.resolve(packageDir, "../..");
const temporaryDir = mkdtempSync(path.join(os.tmpdir(), "penpot-ui-build-"));
const isolatedFrontend = path.join(temporaryDir, "frontend");
const isolatedPackage = path.join(isolatedFrontend, "packages", "ui");
try {
mkdirSync(isolatedPackage, { recursive: true });
for (const entry of [
"src",
"package.json",
"vite.config.mts",
"tsconfig.json",
"tsconfig.lib.json",
"tsconfig.spec.json",
"tsconfig.storybook.json",
".babelrc",
]) {
cpSync(path.join(packageDir, entry), path.join(isolatedPackage, entry), {
recursive: true,
});
}
symlinkSync(
path.join(packageDir, "node_modules"),
path.join(isolatedPackage, "node_modules"),
);
symlinkSync(
path.join(frontendDir, "node_modules"),
path.join(isolatedFrontend, "node_modules"),
);
symlinkSync(
path.join(frontendDir, "src"),
path.join(isolatedFrontend, "src"),
);
const build = spawnSync(
process.execPath,
[
path.join(frontendDir, "node_modules/vite/bin/vite.js"),
"build",
"--configLoader",
"runner",
],
{ cwd: isolatedPackage, encoding: "utf8" },
);
expect(build.status, `${build.stdout}\n${build.stderr}`).toBe(0);
const resolve = createRequire(
path.join(isolatedPackage, "package.json"),
).resolve;
const exportedCss = resolve("@penpot/ui/style.css");
const css = readFileSync(exportedCss, "utf8");
const copiedCss = readFileSync(
path.join(isolatedFrontend, "resources/public/css/ui.css"),
"utf8",
);
expect(css.length).toBeGreaterThan(0);
expect(copiedCss).toBe(css);
} finally {
rmSync(temporaryDir, { recursive: true, force: true });
}
}, 120_000);