Add low-level suspense primitive
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 42/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- typescript
- Ambito
- frontend
Direzione di ricerca
Inizia leggendo il comportamento esistente di Suspense, in particolare getSuspenseContext e resumeEffects, e confrontalo con gli esempi createSuspense e suspense nell’issue. Traccia il modo in cui risorse, effetti, transizioni e callback onMount interagiscono nel caso di transizione collegato. Il lavoro è completato quando una primitiva di basso livello può sospendere gli effetti senza fallback né effetti collaterali sulle risorse negli scenari offscreen descritti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
A low-level suspense primitive would be useful for libraries to pause effects in "offscreen" branches.
Currently Suspense is not only a component-only primitive, but it is tied to resources, and by extend to routing, SSR, transitions, etc. It also assumes needing a fallback branch, which is not always needed.
Because of that it cannot be freely used in libraries, without affecting the rest of the app as a side effect.
For example in transition libraries like motionone and solid-transition-group, when we use <Transition> with mode="out-in", we need to wait for the previous element finish his exit animation, before the newly rendered element can be added to the DOM. But solid doesn't know that the new element is only kept in memory, and not yet appeared on the page, so the updates queue will proceed normally, calling all onMount callbacks, where we expect to deal with elements connected to the DOM.
An issue with more details: https://github.com/solidjs-community/solid-transition-group/issues/34
Also if we wish to keep some roots in memory—e.g. to avoid recreating the same elements when filtering a large array, or displaying search highlights, or implementing a root pool primitive—there is no way to simply prevent then from running some side effects.
If we tried to use <Suspense> to suspend those branches, any resource read under it will also trigger it, possibly breaking the intended behavior of the app—by not showing a fallback in an expected place, or causing a transition (transaction) to be exited sooner (<Transition> is commonly used for wrapping rendered routes).
Code
example createSuspense using Suspense:
https://playground.solidjs.com/anonymous/21cef751-8f37-4354-8a63-0aa475d54e64
createSuspense using Suspense:https://playground.solidjs.com/anonymous/21cef751-8f37-4354-8a63-0aa475d54e64
function createSuspense<T>(when: Accessor<boolean>, fn: () => T): T {
let value: T,
resolve = noop;
const [resource] = createResource(
() => when() || resolve(),
() => new Promise<void>((r) => (resolve = r)),
);
Suspense({
// @ts-expect-error children don't have to return anything
get children() {
createMemo(resource);
value = fn();
},
});
return value!;
}
In @fabiospampinato's oby this is solved by having a low-level suspense primitive that simply takes a function to suspend and a boolean signal to inform if the branch should be suspended or not, and returns the value directly, similar to createRoot.
When the condition signal is true, all effects will be suspended, while resources ignore it and keep the lookup for Suspense they can trigger.
Code
Something like this could maybe be implemented currently as this: (although I'm not sure if resources won't trigger it anyway)
function suspense<T>(when: Accessor<boolean>, fn: () => T): T {
const SuspenseContext = getSuspenseContext(),
store = {
effects: [] as Computation<unknown>[],
resolved: false,
inFallback: when
};
let result!: T;
SuspenseContext.Provider({
value: store,
get children() {
result = fn();
createMemo(() => {
if (!when()) {
store.resolved = true;
resumeEffects(store.effects);
}
return result;
});
return undefined;
}
}) as any;
return result;
}
- Lingua principale
- TypeScript
- Stelle
- 37k
- Fork
- 1.2k
- Merge medio
- 8h 43m
- PR unite (30g)
- 365
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di solidjs/solid
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
I maintainer di solito rispondono entro 1 giorno
-
[2.0.4] Nested `<Errored>`: the outer boundary stays on an error the inner one rethrew, after the next error is one the inner one handlesForse già presa @MilindChatrabhuji l’ha presa 2 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di solidjs/solid
Issue simili
-
agentscan:mixed-signals pending triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
vueuse/vueuse#5737 · 2 commenti ·
I maintainer di solito rispondono entro 9 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Marker-Inc-Korea/AutoRAG#2288 ·
I maintainer di solito rispondono entro 1 giorno
-
Resources: New templates of Guangzhou Metro Line 13Forse già presa @rmt-svc l’ha presa oggi. Apertaresources
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 76/100
railmapgen/rmg-templates#2730 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
web
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno