Skip to content

Commit 5ca0636

Browse files
committed
perf(plugin-detail): publish a side-effect-free /core subpath from one ESM pass (wip)
Claude-Session: https://claude.ai/code/session_01FEkQ5kt9AD1TPLy7Y9oa9D Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9de80a7 commit 5ca0636

5 files changed

Lines changed: 69 additions & 4 deletions

File tree

‎ui/packages/app-shell/src/__tests__/pluginCoreSubpaths-33581.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import path from 'node:path';
3636
import { fileURLToPath } from 'node:url';
3737
import * as formCore from '@object-ui/plugin-form/core';
3838
import * as viewCore from '@object-ui/plugin-view/core';
39+
import * as detailCore from '@object-ui/plugin-detail/core';
3940
// @ts-expect-error — plain-JS shared helper, intentionally untyped (`allowJs: false`)
4041
import { maskComments } from '../../../../scripts/js-comment-mask.mjs';
4142

@@ -48,6 +49,9 @@ const CONSOLE_SRC = path.resolve(here, '../../../../apps/console/src');
4849
const ENTRIES = {
4950
'@object-ui/plugin-form': new Set(Object.keys(formCore)),
5051
'@object-ui/plugin-view': new Set(Object.keys(viewCore)),
52+
'@object-ui/plugin-detail': new Set(Object.keys(detailCore)),
53+
// No `/core` subpath: listed so the eager-module pin below sees its entry.
54+
'@object-ui/plugin-grid': new Set<string>(),
5155
} as const;
5256
type Entry = keyof typeof ENTRIES;
5357

‎ui/packages/app-shell/src/views/RecordDetailView.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
import { useState, useEffect, useLayoutEffect, useCallback, useContext, useMemo, useRef, type ReactElement } from 'react';
1212
import { useParams, useNavigate, useLocation, useSearchParams, Link } from 'react-router-dom';
13-
import { activityRowToFeedItem, buildCommentThreads, CommentsButton, RecordCommentsInPanelContext, composeImpersonatedActor, IMPERSONATED_ACTOR_FALLBACK, auditEntriesToFeedItems, bodyTableIdsOf, claimQueuedRecord, RECORD_PAGE_TIMELINE_PANEL, RECORD_TIMELINE_PANEL_MAX_ENTRIES, RecordFieldChangesContext, RecordFieldHistoryContext, RecordTimelineTotalContext, DefaultRecordPageContext, EMPTY_RELATED_ARRANGEMENT, InlineEditSaveBar, RECORD_PAGE_DETAILS_WIDTH, RecordBodyTablesContext, RecordMetaFooter, RecordPageColumns, buildDefaultPageColumns, buildDefaultPageSchema, extractMentions, isRefusedFeedRead, recordSitsInQueue, resolveTitleField, useQueueClaimOffered, useRecordEditable, useRecordPageTier } from '@object-ui/plugin-detail';
13+
import { activityRowToFeedItem, buildCommentThreads, CommentsButton, RecordCommentsInPanelContext, composeImpersonatedActor, IMPERSONATED_ACTOR_FALLBACK, auditEntriesToFeedItems, bodyTableIdsOf, claimQueuedRecord, RECORD_PAGE_TIMELINE_PANEL, RECORD_TIMELINE_PANEL_MAX_ENTRIES, RecordFieldChangesContext, RecordFieldHistoryContext, RecordTimelineTotalContext, DefaultRecordPageContext, EMPTY_RELATED_ARRANGEMENT, InlineEditSaveBar, RECORD_PAGE_DETAILS_WIDTH, RecordBodyTablesContext, RecordMetaFooter, RecordPageColumns, buildDefaultPageColumns, buildDefaultPageSchema, extractMentions, recordSitsInQueue, resolveTitleField, useQueueClaimOffered, useRecordEditable, useRecordPageTier } from '@object-ui/plugin-detail';
14+
import { isRefusedFeedRead } from '@object-ui/plugin-detail/core';
1415
// objectstack#36075 — the comment panel's unresolved count and the moderator's verdict.
1516
import { unresolvedThreadCount, useRecordVerdict } from '@object-ui/plugin-detail';
1617
import { Empty, EmptyTitle, EmptyDescription, Button, PageHeaderActions, PageHeaderPhoneContext, PageHeaderTrailingContext, PanelToggles, ObjectIconTile, RecordHeaderBarContext, RecordHeaderStateContext, RecordTopBar, RecordTopBarButton, cn, useRecordStepKeys, type PanelToggleItem, type RecordHeaderBar, type RecordHeaderGroupParts, type RecordHeaderState, type RecordTopBarStepper } from '@object-ui/components';

‎ui/packages/plugin-detail/package.json‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
"module": "dist/index.js",
1818
"types": "dist/index.d.ts",
1919
"sideEffects": [
20+
"./dist/core.js",
2021
"./dist/index.js",
2122
"./dist/index.umd.cjs",
2223
"./dist/queueClaim.js",
2324
"./dist/recordFieldAccess.js",
2425
"./dist/useRecordEditable.js",
26+
"./src/core.ts",
2527
"./src/index.tsx",
2628
"./src/queueClaim.ts",
2729
"./src/recordFieldAccess.tsx",
@@ -32,10 +34,14 @@
3234
"types": "./dist/index.d.ts",
3335
"import": "./dist/index.js",
3436
"require": "./dist/index.umd.cjs"
37+
},
38+
"./core": {
39+
"types": "./dist/core.d.ts",
40+
"import": "./dist/core.js"
3541
}
3642
},
3743
"scripts": {
38-
"build": "vite build",
44+
"build": "vite build && vite build --config vite.es.config.ts",
3945
"test": "vitest run --root ../.. packages/plugin-detail/",
4046
"test:watch": "vitest --root ../.. packages/plugin-detail/",
4147
"type-check": "tsc --noEmit && tsc -p tsconfig.test.json",

‎ui/packages/plugin-detail/vite.config.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ export default defineConfig({
6060
lib: {
6161
entry: resolve(__dirname, 'src/index.tsx'),
6262
name: 'ObjectUIPluginDetail',
63-
formats: ['es', 'umd'],
64-
fileName: (format) => `index.${format === 'es' ? 'js' : 'umd.cjs'}`,
63+
// The UMD build only. The ESM build (`dist/index.js`, `dist/core.js`)
64+
// is `vite.es.config.ts`, a second pass: a lib build with more than one
65+
// entry cannot emit UMD.
66+
formats: ['umd'],
67+
fileName: () => 'index.umd.cjs',
6568
},
6669
rollupOptions: {
6770
// IMPORTANT: do NOT inline @object-ui/* runtime packages.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
import { defineConfig } from 'vite';
10+
import react from '@vitejs/plugin-react';
11+
import { resolve } from 'path';
12+
13+
/**
14+
* Second build pass: the ESM build, `dist/index.js` (the package root) and
15+
* `dist/core.js` (the `@object-ui/plugin-detail/core` subpath, see
16+
* `src/core.ts`).
17+
*
18+
* Both entries come from ONE pass with `preserveModules`, so a module both
19+
* reach is one file both import. The record-page caches the `/core` seeds
20+
* write (`queueClaim`, `recordFieldAccess`, `useRecordEditable`) are module
21+
* state the root's hooks read; two bundles would each carry their own copy,
22+
* and a seed written through `/core` would never reach the root. One file per
23+
* source module is also the published spelling the `sideEffects` array names
24+
* (`./dist/queueClaim.js` beside `./src/queueClaim.ts`).
25+
*
26+
* The typings and the UMD build come from the main pass (`vite.config.ts`),
27+
* which runs first. ⛔ `emptyOutDir: false`: this pass must not delete them.
28+
*/
29+
export default defineConfig({
30+
plugins: [react()],
31+
build: {
32+
emptyOutDir: false,
33+
lib: {
34+
entry: {
35+
index: resolve(__dirname, 'src/index.tsx'),
36+
core: resolve(__dirname, 'src/core.ts'),
37+
},
38+
formats: ['es'],
39+
},
40+
rollupOptions: {
41+
// ⛔ Never inline the @object-ui/* runtime packages: every plugin shares
42+
// the one `ComponentRegistry` of `@object-ui/core` (see vite.config.ts).
43+
external: (id) => !/^[./]/.test(id) && !id.startsWith(__dirname),
44+
output: {
45+
preserveModules: true,
46+
preserveModulesRoot: resolve(__dirname, 'src'),
47+
entryFileNames: '[name].js',
48+
},
49+
},
50+
},
51+
});

0 commit comments

Comments
 (0)