mirror of
https://github.com/langgenius/dify.git
synced 2026-09-03 15:27:49 +08:00
docs(frontend): clarify scoped route bridges
This commit is contained in:
parent
1dd3775dde
commit
9fa8838b0d
@ -31,8 +31,8 @@ Keep values out of the graph when they only affect one component's presentation,
|
||||
## Route And URL State
|
||||
|
||||
- Treat `useParams`, route arguments, and `nuqs` as the owners of URL identity and updates.
|
||||
- A single consumer should read the owner hook directly. Hydrate an unscoped primitive atom at the route or surface boundary only when several consumers, query atoms, or shared derived atoms require route identity. Keep URL writes in route and query-state APIs.
|
||||
- A route, framework, or permission bridge that must follow later owner changes should use `dangerouslyForceHydrate: true` at that controlled boundary so descendants observe one synchronous authoritative snapshot. This is the canonical exception to ordinary render-phase write guidance: do not flag the resulting React render-phase update warning as an ownership or architecture problem when the hydration tuples contain only those authoritative external inputs.
|
||||
- A single consumer should read the owner hook directly. When several consumers, query atoms, or shared derived atoms require route identity, first match the bridge lifetime to the route or surface instance. An unscoped primitive is safe only when the owning store cannot contain two live instances of that bridge; otherwise scope the route primitive by instance. Keep URL writes in route and query-state APIs.
|
||||
- A route, framework, or permission bridge that must follow later owner changes should use `dangerouslyForceHydrate: true` at that controlled boundary so descendants observe one synchronous authoritative snapshot. This is the canonical exception to ordinary render-phase write guidance when the hydration tuples contain only those authoritative external inputs and the target store or scope belongs to the current instance. The resulting React warning alone is not an ownership problem, but it must not be used to dismiss cross-instance sharing.
|
||||
- A scoped workflow input is different: initialize it once, key the scope by semantic identity when switching entities should reset it, and do not force later parent refreshes into an in-progress session. Never extend the bridge exception to feature-owned primitives, drafts, query or mutation atoms, or edit-session snapshots.
|
||||
- Within one route-owned feature, choose one route-identity source. Do not hydrate route identity into atoms while also threading the same ID through multiple component layers.
|
||||
- A route parameter may cross the route-to-feature entry edge once. After a route bridge exists, queries, facts, commands, and descendant surfaces must read that bridge instead of accepting the same ID as props.
|
||||
@ -57,7 +57,7 @@ Keep values out of the graph when they only affect one component's presentation,
|
||||
- Do not add a derived fact or write command to the scoped list merely because it reads or writes scoped primitives. When consumed inside the scope, an unlisted fact or command can resolve those selected primitive dependencies from the current scope while retaining access to unscoped parent atoms; listing it instead recursively privatizes its dependency closure.
|
||||
- Prefer `ScopeProvider` when an instance must isolate selected workflow atoms while retaining access to atoms in the parent application store. A nested `Provider` or `createStore` boundary cuts interoperability with every parent atom, not only `queryClientAtom`; injecting the current QueryClient repairs cache access but does not restore other global state. Use a fresh store only when full-store isolation is intentional, then inject every required external dependency explicitly.
|
||||
- Use parent-store interoperation as the boundary test: if descendants must observe application auth, workspace, permissions, cache, or any other parent atom, a fresh `Provider` is not an instance-scope mechanism. Choose it only when the surface intentionally owns a complete store and must not observe later parent-atom updates.
|
||||
- Hydrate an unscoped route or parent-input bridge before entering `ScopeProvider`. In React, call `useHydrateAtoms` in the boundary component that returns the scope, not in a descendant rendered inside it; hooks read the nearest provider available where that component itself renders.
|
||||
- For an intentionally unscoped route or parent-input bridge, call `useHydrateAtoms` in the boundary component that returns `ScopeProvider`; hooks read the nearest provider available where that component itself renders. When the bridge requires per-instance isolation, initialize its primitives through the `ScopeProvider` tuples instead. If later authoritative owner changes must follow, render a dedicated hydration bridge beneath that provider so `useHydrateAtoms` resolves the scoped primitives.
|
||||
- Use `atomWithLazy` or another non-null lazy primitive for required values injected by a scope provider; fail when the boundary forgot to provide them instead of inventing an empty ID.
|
||||
- Maintain the scoped primitive list explicitly. Use a semantic `key` when switching identity should create a fresh session; do not use forced hydration for an edit snapshot that must remain stable while an outer query refreshes.
|
||||
- Scope exists for per-instance isolation and natural reset, not as a general module boundary. A state file may be warranted even when its atoms remain unscoped.
|
||||
@ -73,7 +73,7 @@ Before implementation and again after the final slice, draw the actual graph in
|
||||
- write atoms and exported commands describe user or workflow intent;
|
||||
- scoped atoms are limited to primitives and snapshots with a documented reset boundary;
|
||||
- the scope still observes required parent/global atom updates, including the application's shared QueryClient;
|
||||
- two mounted instances do not share scoped workflow state, and a semantic identity change resets that state;
|
||||
- two simultaneously mounted route or surface instances with different identities or URL state do not overwrite each other's bridged primitives or scoped workflow state, and a semantic identity change resets the intended state;
|
||||
- no equivalent value remains available through both atoms and descendant props;
|
||||
- every exported atom has a real component, boundary, or state-module consumer.
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user