Skip to content

chore(build): share assets across the three web targets#3908

Merged
rezk2ll merged 1 commit into
masterfrom
chore/share-build-assets
Jun 16, 2026
Merged

chore(build): share assets across the three web targets#3908
rezk2ll merged 1 commit into
masterfrom
chore/share-build-assets

Conversation

@rezk2ll

@rezk2ll rezk2ll commented Jun 11, 2026

Copy link
Copy Markdown
Member

Problem

The main, public and intents targets are three separate rspack compilations, so React, the cozy libraries and the editors are re-bundled into each target's own static tree. The registry tarball pays for every shared module up to three times: it sits at 18MB against the 20MB limit, and every new editor or heavy dependency multiplies its cost by the number of targets that use it. That pressure is what previously forced the PDF editor out of the public build.

Solution

The three targets become entries of a single compilation. Shared modules are emitted once under build/static, exposed through a new public /static route so share pages can load them without auth, and each target keeps its own index.html (the / route now points at /main). The react-pdf alias moves to the webpack5 entry so the pdf.js worker lands under static/ instead of the build root, where only the private route could serve it. The tarball drops from 18MB to 10.8MB and stays flat when a dependency is added to more targets.

Since the editor chunks are now shipped once regardless, the PDF editor is restored on shared links. It is also loaded lazily, keeping it out of the initial payload of both the public page and the logged-in app (about 1MB less each).

Worth knowing

All JS becomes publicly fetchable through /static, including chunks only used by the logged-in app. The code is AGPL and already published, so nothing sensitive changes hands.

Summary by CodeRabbit

  • New Features

    • PDF editing capability is now available in shared and public file views.
  • Performance

    • PDF viewer components now load on-demand, improving initial application performance.

The main, public and intents targets were three separate rspack
compilations, each re-bundling React, the cozy libraries and the
editors into its own static tree. The registry tarball paid for every
shared module up to three times (18MB, against a 20MB limit) and grew
with every editor added.

The three targets are now entries of a single compilation: shared
modules are emitted once under build/static, served by a new public
/static route so the share pages can load them without auth. Each
target keeps its own index.html and the / route now points at /main.
The tarball drops from 18MB to 10.8MB.

Sharing the assets makes the PDF editor free for the public target
(its chunks were already shipped for the logged-in app), so the
editor is restored on shared links. It is now loaded lazily, which
also drops it from the logged-in app's initial payload.
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR restructures the Twake Drive build pipeline to use a unified web environment bundling main, public, and intents entries with a shared chunk graph. Asset paths are consolidated under /static/, Excalidraw fonts are self-hosted, and the manifest routes root requests to /main. PDF view components are wrapped in lazy loading with Suspense boundaries. Public/shared file viewers gain PDF editor capability via pdfOpener callbacks that navigate to dynamically-registered PDF routes when isPdfEditorEnabled() is true.

Possibly related PRs

  • linagora/twake-drive#3879: Modifies the Excalidraw font copying logic in rsbuild.config.mjs to exclude the Xiaolai CJK font from static/fonts output.
  • linagora/twake-drive#3905: Removes PDF editor from public builds by disabling viewers and omitting public PDF editor routes, whereas this PR enables them—directly related at the same code points.
  • linagora/twake-drive#3880: Updates src/modules/views/Excalidraw/setupAssetPath.js to change window.EXCALIDRAW_ASSET_PATH and __webpack_public_path__ configuration for public builds.

Suggested labels

e2e

Suggested reviewers

  • doubleface
  • lethemanh
  • zatteo
  • JF-Cozy
  • codescene-delta-analysis
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main architectural change: consolidating three separate builds into one shared build with assets accessed via a new /static route.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/share-build-assets

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our agent can fix these. Install it.

Gates Passed
3 Quality Gates Passed

Quality Gate Profile: The Bare Minimum
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

@bundlemon

bundlemon Bot commented Jun 11, 2026

Copy link
Copy Markdown

BundleMon

Files added (9)
Status Path Size Limits
static/resource/(hash).js
+336.09KB -
static/js/lib-polyfill.(hash).js
+22.77KB -
static/js/public.(hash).js
+19.48KB -
static/js/intents.(hash).js
+9.2KB -
static/js/async/(chunkId).(hash).js
+7.5KB -
static/css/public.(hash).css
+2.33KB -
main/index.html
+769B -
public/index.html
+706B -
intents/index.html
+646B -
Files removed (10)
Status Path Size Limits
public/static/js/(chunkId).(hash).js
-1.4MB -
public/static/js/cozy.(hash).js
-779.75KB -
(hash).js
-336.11KB -
public/(hash).js
-336.11KB -
public/static/js/public.(hash).js
-150.55KB -
public/static/js/lib-react.(hash).js
-43.88KB -
public/static/css/cozy.(hash).css
-31.42KB -
public/static/js/lib-router.(hash).js
-21.86KB -
public/static/css/public.(hash).css
-6.76KB -
index.html
-714B -
Files updated (5)
Status Path Size Limits
static/js/cozy.(hash).js
927.46KB (+7.91KB +0.86%) -
static/css/main.(hash).css
13.55KB (+2.49KB +22.52%) -
manifest.webapp
3.09KB (+12B +0.38%) -
static/js/main.(hash).js
47.63KB (-130.22KB -73.22%) -
static/js/(chunkId).(hash).js
8.6KB (-1.73MB -99.52%) -
Unchanged files (6)
Status Path Size Limits
services/qualificationMigration.js
283.23KB -
services/dacc.js
262.97KB -
static/js/lib-react.(hash).js
43.88KB -
static/css/cozy.(hash).css
31.42KB -
static/js/lib-router.(hash).js
21.86KB -
assets/manifest.json
185B -

Total files change -4.52MB -69.39%

Groups updated (3)
Status Path Size Limits
**/*.{png,svg,ico}
2.16MB (-33.04KB -1.47%) -
**/*.css
78.68KB (-84.74KB -51.86%) -
**/*.js
5.98MB (-6.63MB -52.58%) -

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/targets/public/components/AppRouter.jsx`:
- Around line 38-39: AppRouter currently calls getPublicPdfRoutes({ isReadOnly
}) but doesn't pass isReadOnly into the viewer components; update AppRouter to
pass the isReadOnly prop into LightFileViewer and PublicFileViewer (the
components returned by getPublicPdfRoutes). Then modify LightFileViewer.jsx
(around the CTA logic) and PublicFileViewer.jsx (around the PDF edit CTA) to
gate the editor CTA with both the feature flag and the read-only state—replace
checks like isPdfEditorEnabled() with isPdfEditorEnabled() && !isReadOnly (using
the isReadOnly prop passed in) so the edit CTA is disabled on read-only shares.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1a78b070-bbaa-4dc0-b34a-103de18868f8

📥 Commits

Reviewing files that changed from the base of the PR and between 88397e5 and ae0c20d.

📒 Files selected for processing (8)
  • .bundlemonrc
  • manifest.webapp
  • rsbuild.config.mjs
  • src/modules/public/LightFileViewer.jsx
  • src/modules/views/Excalidraw/setupAssetPath.js
  • src/modules/views/Pdf/routes.jsx
  • src/modules/views/Public/PublicFileViewer.jsx
  • src/targets/public/components/AppRouter.jsx

Comment thread src/targets/public/components/AppRouter.jsx
@rezk2ll rezk2ll requested a review from Crash-- June 11, 2026 14:28
@rezk2ll

rezk2ll commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

@Crash-- -69.39%

@zatteo zatteo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting!

  1. Did you properly tested local dev (yarn start and yarn watch) with HMR, Excalidraw viewer & PDF viewer, public links, etc ?

  2. I propose to try 1 or 2 weeks with Drive and then move to rsbuild-config-cozy-app what is common with other app.

@rezk2ll

rezk2ll commented Jun 15, 2026

Copy link
Copy Markdown
Member Author

Interesting!

  1. Did you properly tested local dev (yarn start and yarn watch) with HMR, Excalidraw viewer & PDF viewer, public links, etc ?
  2. I propose to try 1 or 2 weeks with Drive and then move to rsbuild-config-cozy-app what is common with other app.

yes HMR is intact and the viewers also work fine in public and normal views ( while sharing assets of the editos ).

i'm not merging this PR yet until the new release of drive.

and yes the idea is to test it on drive and then bring it to the other apps via the shared build config

@rezk2ll rezk2ll added the e2e Run the E2E suite on this PR label Jun 16, 2026
@rezk2ll

rezk2ll commented Jun 16, 2026

Copy link
Copy Markdown
Member Author

E2E tests pass, locally also. i'll merge it and see how it goes @Crash-- @zatteo

@rezk2ll rezk2ll merged commit 6677402 into master Jun 16, 2026
7 checks passed
@rezk2ll rezk2ll deleted the chore/share-build-assets branch June 16, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e Run the E2E suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants