[PR #30702] refactor: marketplace state management #32935

Closed
opened 2026-02-21 20:52:21 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/30702

State: closed
Merged: Yes


[!IMPORTANT]

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Problems with the old implementation

  1. Duplicate state storage: Each state has both useState + useRef, requiring manual synchronization with lots of boilerplate code

  2. Imperative queries triggered in useEffect: Manually calling queryPlugins / queryPluginsWithDebounced / cancelQueryPluginsWithDebounced, triggered inside useEffect with complex dependencies prone to bugs, no standardized query keys

  3. Complex URL synchronization: Three layers of nested functions applyUrlFiltersdebouncedUpdateSearchParamshandleUpdateSearchParams

  4. SSR data not in cache: Server-side data passed via props, not entering TanStack Query cache, causing duplicate requests after client hydration

  5. No URL parameter prefetching: Server only fetches default data, prefetching is ineffective when users visit with URL parameters

  6. Props drilling: showSearchParams drilled through 4 component layers to reach PluginTypeSwitch

New approach

Jotai atomic state + nuqs URL binding + TanStack Query HydrationBoundary - declarative, single data source, no props drilling. URL parameter prefetching currently only supports category (collections data), search parameters are not prefetched yet.


Fixes #30699

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/30702 **State:** closed **Merged:** Yes --- > [\!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary ### Problems with the old implementation 1. **Duplicate state storage**: Each state has both `useState` + `useRef`, requiring manual synchronization with lots of boilerplate code 2. **Imperative queries triggered in useEffect**: Manually calling `queryPlugins` / `queryPluginsWithDebounced` / `cancelQueryPluginsWithDebounced`, triggered inside useEffect with complex dependencies prone to bugs, no standardized query keys 3. **Complex URL synchronization**: Three layers of nested functions `applyUrlFilters` → `debouncedUpdateSearchParams` → `handleUpdateSearchParams` 4. **SSR data not in cache**: Server-side data passed via props, not entering TanStack Query cache, causing duplicate requests after client hydration 5. **No URL parameter prefetching**: Server only fetches default data, prefetching is ineffective when users visit with URL parameters 6. **Props drilling**: `showSearchParams` drilled through 4 component layers to reach `PluginTypeSwitch` ### New approach Jotai atomic state + nuqs URL binding + TanStack Query HydrationBoundary - declarative, single data source, no props drilling. URL parameter prefetching currently only supports category (collections data), search parameters are not prefetched yet. --- Fixes #30699 ## Screenshots | Before | After | |--------|-------| | ... | ... | ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos\!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `make lint` and `make type-check` (backend) and `cd web && npx lint-staged` (frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:52:21 -05:00
yindo closed this issue 2026-02-21 20:52:21 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32935