Skip to content

Commit

Permalink
Merge 97bdfa3 into d8e0e8e
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Sep 23, 2023
2 parents d8e0e8e + 97bdfa3 commit 2b64ea4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/solid/src/render/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,14 @@ export function createUniqueId(): string {
const ctx = sharedConfig.context;
return ctx ? `${ctx.id}${ctx.count++}` : `cl-${counter++}`;
}

export function createServerValue<T>(cb: () => T): T {
const ctx = sharedConfig.context;
if (ctx && sharedConfig.load) {
const id = `${ctx.id}${ctx.count++}`;
// TODO we should check if the value is actually serialized
// otherwise we fallback to `cb()`
return sharedConfig.load(id);
}
return cb();
}
9 changes: 9 additions & 0 deletions packages/solid/src/server/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ export function createUniqueId(): string {
return `${ctx.id}${ctx.count++}`;
}

export function createServerValue<T>(cb: () => T): T {
const ctx = sharedConfig.context;
const value = cb();
if (ctx) {
ctx.serialize(`${ctx.id}${ctx.count++}`, value, true);
}
return value;
}

export function createComponent<T>(Comp: (props: T) => JSX.Element, props: T): JSX.Element {
if (sharedConfig.context && !sharedConfig.context.noHydrate) {
const c = sharedConfig.context;
Expand Down

0 comments on commit 2b64ea4

Please sign in to comment.