Subpath bundles duplicate PostContext, and the root import can't be tree-shaken
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- 説明が足りない
- 活発さ
- 活発
- 技術スタック
- react, rollup, typescript, webpack
- 領域
- build-system
調査の方向性
The build is configured in webpack.config.js and package.json; read those to see how entries are bundled and why no sideEffects field exists. Inspect dist/components/post-context/index.js and dist/components/post-title/index.js to confirm each creates its own context. Done means either an ESM build with sideEffects added, or cross-entry imports externalized so React context is shared across subpaths.
索引モデルが issue の本文から書いたものです。
説明
Follow-up to #97. The subpath exports it added help a lot, but two problems remain in 1.23.0. Together they force a choice between bundle size and correct behaviour.
1. The package root can't be tree-shaken
dist/index.js is one CommonJS webpack bundle, and package.json has no sideEffects field. A consumer that imports a single component from @10up/block-components gets the whole library and all of its dependencies (@tanstack/react-query, @dnd-kit/*, react-window, @leeoniya/ufuzzy, @emotion/* and so on).
On a large client site with about 60 custom blocks, each block's editor script that imported anything from the root was about 125 KB gzipped larger. Switching those imports to @10up/block-components/components/* and /hooks/* cut the editor JS from 4.8 MB to 2.5 MB gzipped, and most block scripts dropped from about 130 KB to 1–16 KB.
2. Subpath bundles each carry their own copy of shared internals
webpack.config.js builds every api/, components/, hooks/ and stores/ folder as a separate entry, and only @wordpress/* is externalized. Shared modules are therefore inlined into every entry that uses them. React context is where this breaks things. In dist/ (1.23.0):
$ grep -c createContext dist/components/post-context/index.js dist/components/post-title/index.js
dist/components/post-context/index.js:1
dist/components/post-title/index.js:1
post-title, post-featured-image, post-author, post-meta, hooks/use-post and hooks/use-primary-term each create their own copy of the post context. So this:
import { PostContext } from '@10up/block-components/components/post-context';
import { PostTitle } from '@10up/block-components/components/post-title';
<PostContext postId={ 123 } postType="post">
<PostTitle />
</PostContext>
wires PostTitle to a different context object than the provider. It never sees postId: 123, so it falls back to the context default. To stay correct, anything using PostContext has to import the whole family from the root, which brings back the full bundle from problem 1. In our case that meant 9 files (and their blocks) still ship the full library.
The icon store is fine: every copy runs select( 'tenup/icons' ) || register( store ), so all copies share one store by name. Module-level state that isn't keyed by a global name isn't shared.
Possible fixes
- Ship an unbundled ESM build (for example
tscoutput, or Rollup withpreserveModules) alongside the CommonJS one. Declare"sideEffects"limited to the store registration modules. Then root imports tree-shake, shared modules exist once, and the subpath exports keep working. - Or, keeping the current webpack build: externalize cross-entry imports so an entry
requires another entry instead of inlining it. For example,components/post-titlewould import@10up/block-components/components/post-contextat runtime. At minimum this matters for modules that hold React context.
Happy to help test either approach.
- 主要言語
- TypeScript
- スター
- 330
- フォーク
- 54
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
10up/block-components のほかの issue
-
Repeater with allowReordering logs React key and isDragging warnings対応中かも @s3rgiosan が 5 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
10up/block-components#419 · コメント 1 件 ·
-
ContentPicker SortableList logs a useSelect unstable value warning対応中かも @s3rgiosan が 5 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 42/100
10up/block-components#421 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
10up/block-components#413 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
10up/block-components#412 ·
-
ContentPicker: invalid html対応中かも @s3rgiosan が 5 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
10up/block-components#400 ·
10up/block-components の issue をすべて見る
似ている issue
-
db-d1-sqlite: upsert is aliased to updateOne, so payload.kv.set never inserts new keys対応中かも @pcbeingused333 が今日担当しました。 オープンBug db: d1-sqlite Payload OSS
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
payloadcms/payload#19766 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
device-management-toolkit/sample-web-ui#3711 ·
メンテナーはふだん 1 日以内に返信
-
bug impact:low Team: SecuritySolution Team:Defend Workflows v9.6.0
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
elastic/kibana#306401 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
agentes-chat/agentes-chat#927 ·
メンテナーはふだん 1 日以内に返信
-
Closing a pinned tab jumps to the Tabs section instead of the next open pinned tab対応中かも @seenimohamed が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ardia-browser/ardia#2769 ·
メンテナーはふだん 1 日以内に返信