Skip to content

fix(build): keep the DAV properties apart from the webdav client - #1792

Merged
susnux merged 1 commit into
mainfrom
fix/dav-properties-chunk
Oct 16, 2026
Merged

susnux merged 1 commit into
mainfrom
fix/dav-properties-chunk

Conversation

@skjnldsv

@skjnldsv skjnldsv commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Importing registerDavProperty from @nextcloud/files/dav brings the whole webdav client into the importing chunk. The properties and the client were built into one chunk, so an app that registers a property at startup and uses the client later, lazily, gets the client in the chunk its page loads at once.

Measured on the viewer's playground, registering nc:metadata-photos-size from its init:

@nextcloud/files Loaded up front webdav
now 309,506 bytes in it
sideEffects: false only 309,105 bytes in it
this PR 174,727 bytes in the lazy chunk

Each source module is now its own module (preserveModules, as susnux suggested), and the package says it has no side effects, so a bundler places each where it is used. Both are needed. The package ships no CSS, and its two module-level statements (the global scope and axiosRetry) sit in modules that are kept whenever their exports are used.

Unit tests pass locally, the integration ones need Docker and are left to CI.

👾 This pull request was assisted by Claude Code, commits carry an Assisted-by trailer.

@skjnldsv skjnldsv added type: bug 🐛 Something isn't working 3. to review 3️⃣ Waiting for reviews AI assisted This PR contains AI-assisted commits labels Oct 15, 2026
@skjnldsv skjnldsv self-assigned this Oct 15, 2026
@skjnldsv
skjnldsv requested a review from susnux October 15, 2026 13:45
@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.86%. Comparing base (071e831) to head (2f79583).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1792   +/-   ##
=======================================
  Coverage   89.86%   89.86%           
=======================================
  Files          44       44           
  Lines        1135     1135           
  Branches      285      285           
=======================================
  Hits         1020     1020           
  Misses         85       85           
  Partials       30       30           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@artonge artonge left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🐘

@skjnldsv

Copy link
Copy Markdown
Contributor Author

Waiting for @susnux

@susnux susnux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do not get this changes, this enforces a specific output files for dav properties.
But that will not change anything, because its not an entry chunk the apps bundler will still load everything else.

So tree shaking will be applied and everything not needed is dropped again.

The sideeffects part is ok, but the manual chunks part? Also why a plugin? There is a build option for it

@skjnldsv

skjnldsv commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Well, I tried a few things and discovered a mix of options that seemed to be needed together. as you can see in the table in the description.

Also why a plugin? There is a build option for it

I wasn't aware of an option for that directly. Searching I found this plugin 🙈🙈

The ultimate goal here is being able to use the registerDavThingy without the entire WebDAV code being added to the chunk.
Which it didn't seem to do when using in viewer. I don't think the tree shaking was working. Any clue or pointers?

Comment thread vite.config.ts Outdated
Comment on lines +16 to +28
// The DAV properties apart from the client, so an app that only
// registers a property does not bundle webdav where it does
name: 'dav-properties-chunk',
outputOptions(options) {
return {
...options,
manualChunks(id) {
if (id.includes('/lib/dav/davProperties.ts')) {
return 'davProperties'
}
},
}
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// The DAV properties apart from the client, so an app that only
// registers a property does not bundle webdav where it does
name: 'dav-properties-chunk',
outputOptions(options) {
return {
...options,
manualChunks(id) {
if (id.includes('/lib/dav/davProperties.ts')) {
return 'davProperties'
}
},
}
},
{
name: 'preserve-modules',
outputOptions: (output) => ({ ...output, preserveModules: true, preserveModulesRoot: 'lib' }),
},

I guess this is future proof as not bound to a specific input file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(alternatively we might also just drop vite here because this lib does not need to bundle things (e.g. Vue components) but only simply provides vanilla function, thus a Typescript build with ts 7 should be simpler and faster)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fine with any solution really :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let me try!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Seems like it's working!
Pushed the fix 😊

@skjnldsv

Copy link
Copy Markdown
Contributor Author

If you meant build.rollupOptions.output.manualChunks, I tried it first. But createLibConfig defines rollupOptions.output as an array (one entry per format), and Vite's mergeConfig appended my object as a second output instead of merging into it 😵‍💫

The DAV properties and the client were built into one module, which a
bundler can tree-shake but not split. An app registering a property at
init and using the client in a lazy chunk got the whole module, webdav
included, in a chunk its page loads at once.

Each source module is now a module of its own, and the package says it
has no side effects, so a bundler places each where it is used.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: John Molakvoæ <14975046+skjnldsv@users.noreply.github.com>
@skjnldsv
skjnldsv force-pushed the fix/dav-properties-chunk branch from b52c9f0 to 2f79583 Compare October 15, 2026 20:19
@skjnldsv
skjnldsv requested a review from susnux October 15, 2026 20:22
@susnux
susnux merged commit b550916 into main Oct 16, 2026
13 checks passed
@susnux
susnux deleted the fix/dav-properties-chunk branch October 16, 2026 13:53
@susnux

susnux commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

TODO for us:
Fix all other libs, we have the same problem with nextcloud/auth and nextcloud/logger!

@susnux

susnux commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

(while there partially they have sideeffects - we should look into fixing that to be sideeffect free)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review 3️⃣ Waiting for reviews AI assisted This PR contains AI-assisted commits type: bug 🐛 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants