Summary: | Lazy load api-client JS files | ||
---|---|---|---|
Product: | Koha | Reporter: | Jonathan Druart <jonathan.druart> |
Component: | Architecture, internals, and plumbing | Assignee: | Paul Derscheid <paul.derscheid> |
Status: | Passed QA --- | QA Contact: | Lisette Scheer <lisette> |
Severity: | enhancement | ||
Priority: | P5 - low | CC: | lisette, lucas, pedro.amorim |
Version: | unspecified | Keywords: | release-notes-needed |
Hardware: | All | ||
OS: | All | ||
See Also: | https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33024 | ||
GIT URL: | Change sponsored?: | --- | |
Patch complexity: | --- | Documentation contact: | |
Documentation submission: | Text to go in the release notes: | ||
Version(s) released in: | Circulation function: | ||
Attachments: |
Bug 36674: Lazy-load intranet API clients via proxy
Bug 36674: Lazy-load intranet API clients via proxy Bug 36674: Remove duplication Bug 36674: Remove duplication Bug 36674: Lazy-load intranet API clients via proxy Bug 36674: Remove duplication |
Description
Jonathan Druart
2024-04-23 09:52:08 UTC
Created attachment 186551 [details] [review] Bug 36674: Lazy-load intranet API clients via proxy Replaced the eager imports in the intranet APIClient aggregator with lazy proxies so individual client modules are only fetched the first time they are actually used. Documented the pattern in the createClientProxy JSDoc, and kept the legacy synchronous API intact by forwarding property access, method calls, and promise chaining. The Vue aggregator remains on static imports for now because the rspack bundles already would handle chunking (which we need to configure) and would require broader consumer changes. This is a bit hacky, but only touches the api-client itself, which I like. Otherwise we would have to adjust all consumers. Test plan: 1. Log in to the staff interface and visit Admin → System preferences. 2. Open DevTools, Network tab, and enable “Disable cache”. 3. Trigger an API call (e.g. edit a preference and click “Save”, or run await APIClient.sysprefs.sysprefs.update_all({}).catch(()=>{}); from the console). 4. Confirm a new request for js/fetch/system-preferences-api-client.js appears and the page still behaves as before. 5. Theoretically we would need to test all call sites.. 6. Sign-off Created attachment 186616 [details] [review] Bug 36674: Lazy-load intranet API clients via proxy Replaced the eager imports in the intranet APIClient aggregator with lazy proxies so individual client modules are only fetched the first time they are actually used. Documented the pattern in the createClientProxy JSDoc, and kept the legacy synchronous API intact by forwarding property access, method calls, and promise chaining. The Vue aggregator remains on static imports for now because the rspack bundles already would handle chunking (which we need to configure) and would require broader consumer changes. This is a bit hacky, but only touches the api-client itself, which I like. Otherwise we would have to adjust all consumers. Test plan: 1. Log in to the staff interface and visit Admin → System preferences. 2. Open DevTools, Network tab, and enable “Disable cache”. 3. Trigger an API call (e.g. edit a preference and click “Save”, or run await APIClient.sysprefs.sysprefs.update_all({}).catch(()=>{}); from the console). 4. Confirm a new request for js/fetch/system-preferences-api-client.js appears and the page still behaves as before. 5. Theoretically we would need to test all call sites.. 6. Sign-off Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Created attachment 186617 [details] [review] Bug 36674: Remove duplication Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> I have to admit I don't understand all what is doing the first patch but it's working very well! Created attachment 186994 [details] [review] Bug 36674: Remove duplication Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com> Created attachment 186995 [details] [review] Bug 36674: Lazy-load intranet API clients via proxy Replaced the eager imports in the intranet APIClient aggregator with lazy proxies so individual client modules are only fetched the first time they are actually used. Documented the pattern in the createClientProxy JSDoc, and kept the legacy synchronous API intact by forwarding property access, method calls, and promise chaining. The Vue aggregator remains on static imports for now because the rspack bundles already would handle chunking (which we need to configure) and would require broader consumer changes. This is a bit hacky, but only touches the api-client itself, which I like. Otherwise we would have to adjust all consumers. Test plan: 1. Log in to the staff interface and visit Admin → System preferences. 2. Open DevTools, Network tab, and enable “Disable cache”. 3. Trigger an API call (e.g. edit a preference and click “Save”, or run await APIClient.sysprefs.sysprefs.update_all({}).catch(()=>{}); from the console). 4. Confirm a new request for js/fetch/system-preferences-api-client.js appears and the page still behaves as before. 5. Theoretically we would need to test all call sites.. 6. Sign-off Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com> Thanks for all the notes in /koha-tmpl/intranet-tmpl/prog/js/fetch/api-client.js that'll be really helpful for future developers. We need a rebase here now. Created attachment 187826 [details] [review] Bug 36674: Remove duplication Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com> (In reply to Lucas Gass (lukeg) from comment #8) > We need a rebase here now. Patches were applied in reserve order. (In reply to Lucas Gass (lukeg) from comment #8) > We need a rebase here now. Patches were attached in reserve order. |