[User Storage Service] browser client, React hooks, injection rendering#268312
Conversation
|
/ci |
|
/ci |
|
Pinging @elastic/appex-sharedux (Team:SharedUX) |
|
Back to draft to add more Scout tests |
Dosant
left a comment
There was a problem hiding this comment.
AI-generated review posted by @Dosant. I re-reviewed the updated PR after the recent fixes and focused on remaining behavioral/test issues. One additional note that I could not anchor directly: null currently acts as the server-side removal tombstone, but schemas can still allow null; if null is reserved for removal, registration/write validation should probably reject nullable schemas or the removal representation should change.
| }; | ||
|
|
||
| export const App = ({ userStorage }: { userStorage: IUserStorageClient }) => ( | ||
| <UserStorageProvider userStorage={userStorage}> |
There was a problem hiding this comment.
Maybe not necessarily in this PR - but I think we can include this provider into our core addContext thing so that apps can access the service without even requiring using the provider directly (similar to what we did to chrome service context)
There was a problem hiding this comment.
Wrote this as a note to myself. It would probably merit attention if it does come up as a request.
💛 Build succeeded, but was flaky
Failed CI Steps
Test Failures
Metrics [docs]Module Count
Async chunks
Page load bundle
History
|
…ng (elastic#268312) Epic: elastic/kibana-team#2769 ## Summary Adds the browser foundation for the Core User Storage service (Step 2 of the project; the server-side foundation landed in elastic#256912). Three pieces: **A. Server-rendered injection.** - RenderingService` pre-fetches the current user's stored values per request via `userStorage.asScoped(request).getAll()` and inlines them under a new `userStorage.values` field on `<kbn-injected-metadata>`. - Bounded by a 50ms timeout (mirroring the existing `clusterInfo` pattern at `rendering_service.tsx:234`) - skipped for anonymous pages and when `asScoped` returns `null` (no `profile_uid`). **B. Browser client.** - Three new packages in `src/core/packages/user-storage/`: 1. `@kbn/core-user-storage-browser` (public API: `IUserStorageClient`, `UserStorageProvider`, `useUserStorage`, `useUserStorageClient`) 2. `@kbn/core-user-storage-browser-internal` (`UserStorageService`, `UserStorageClient`, `UserStorageApi`) 3. `@kbn/core-user-storage-browser-mocks`. - The client seeds an in-memory cache from injected metadata at boot, so `get(key)` is synchronous at first paint. `set`/`remove` write through HTTP and refresh the cache on success. - Architectural diagram <img width="1295" height="631" alt="image" src="https://github.com/user-attachments/assets/0b3e9113-9ef1-47d7-8f7d-37bf8730e432" /> **C. React hook + provider.** - `useUserStorage(key, default)` returns `[value, setter]` with an Observable-backed subscription, and throws a helpful error when used outside `<UserStorageProvider>`. - `useUserStorageClient()` is the escape hatch for consumers that depend on `remove`, `getUpdate$`, and `getUpdateErrors$`. ## Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - ~[ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)~ - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - ~[ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~ - ~[ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations.~ - ~[ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed~ - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Anton Dosov <anton.dosov@elastic.co>
…ng (#268312) Epic: elastic/kibana-team#2769 ## Summary Adds the browser foundation for the Core User Storage service (Step 2 of the project; the server-side foundation landed in #256912). Three pieces: **A. Server-rendered injection.** - RenderingService` pre-fetches the current user's stored values per request via `userStorage.asScoped(request).getAll()` and inlines them under a new `userStorage.values` field on `<kbn-injected-metadata>`. - Bounded by a 50ms timeout (mirroring the existing `clusterInfo` pattern at `rendering_service.tsx:234`) - skipped for anonymous pages and when `asScoped` returns `null` (no `profile_uid`). **B. Browser client.** - Three new packages in `src/core/packages/user-storage/`: 1. `@kbn/core-user-storage-browser` (public API: `IUserStorageClient`, `UserStorageProvider`, `useUserStorage`, `useUserStorageClient`) 2. `@kbn/core-user-storage-browser-internal` (`UserStorageService`, `UserStorageClient`, `UserStorageApi`) 3. `@kbn/core-user-storage-browser-mocks`. - The client seeds an in-memory cache from injected metadata at boot, so `get(key)` is synchronous at first paint. `set`/`remove` write through HTTP and refresh the cache on success. - Architectural diagram <img width="1295" height="631" alt="image" src="https://github.com/user-attachments/assets/0b3e9113-9ef1-47d7-8f7d-37bf8730e432" /> **C. React hook + provider.** - `useUserStorage(key, default)` returns `[value, setter]` with an Observable-backed subscription, and throws a helpful error when used outside `<UserStorageProvider>`. - `useUserStorageClient()` is the escape hatch for consumers that depend on `remove`, `getUpdate$`, and `getUpdateErrors$`. ## Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - ~[ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)~ - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - ~[ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~ - ~[ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations.~ - ~[ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed~ - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Anton Dosov <anton.dosov@elastic.co>
Epic: https://github.com/elastic/kibana-team/issues/2769
Summary
Adds the browser foundation for the Core User Storage service (Step 2 of the project; the server-side foundation landed in #256912).
Three pieces:
A. Server-rendered injection.
pre-fetches the current user's stored values per request viauserStorage.asScoped(request).getAll()and inlines them under a newuserStorage.valuesfield on`.clusterInfopattern atrendering_service.tsx:234)asScopedreturnsnull(noprofile_uid).B. Browser client.
src/core/packages/user-storage/:@kbn/core-user-storage-browser(public API:IUserStorageClient,UserStorageProvider,useUserStorage,useUserStorageClient)@kbn/core-user-storage-browser-internal(UserStorageService,UserStorageClient,UserStorageApi)@kbn/core-user-storage-browser-mocks.get(key)is synchronous at first paint.set/removewrite through HTTP and refresh the cache on success.C. React hook + provider.
useUserStorage(key, default)returns[value, setter]with an Observable-backed subscription, and throws a helpful error when used outside<UserStorageProvider>.useUserStorageClient()is the escape hatch for consumers that depend onremove,getUpdate$, andgetUpdateErrors$.Checklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
[ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support[ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the docker list[ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. Therelease_note:breakinglabel should be applied in these situations.[ ] Flaky Test Runner was used on any tests changedrelease_note:*label is applied per the guidelinesbackport:*labels.