Skip to content

Commit 523c89b

Browse files
committed
export functions from dom-expressions server.js to match client.js exports, and make client-only functions throw on the serverside
1 parent ab2d670 commit 523c89b

File tree

4 files changed

+121
-4
lines changed

4 files changed

+121
-4
lines changed

packages/dom-expressions/src/client.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function dynamicProperty(props: unknown, key: string): unknown;
5757
export function hydrate(
5858
fn: () => JSX.Element,
5959
node: MountableElement,
60-
options?: { renderId?: string, owner?: unknown }
60+
options?: { renderId?: string; owner?: unknown }
6161
): () => void;
6262
export function getHydrationKey(): string;
6363
export function getNextElement(template?: HTMLTemplateElement): Element;
@@ -74,4 +74,5 @@ export interface RequestEvent {
7474
request: Request;
7575
}
7676
export declare const RequestContext: unique symbol;
77-
export function getRequestEvent(): RequestEvent | undefined;
77+
export function getRequestEvent(): RequestEvent | undefined;
78+
export function runHydrationEvents(): void;

packages/dom-expressions/src/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
466466
if (marker === undefined) return (current = [...parent.childNodes]);
467467
let node = array[0];
468468
if (node.parentNode !== parent) return current;
469-
const nodes = [node]
469+
const nodes = [node];
470470
while ((node = node.nextSibling) !== marker) nodes.push(node);
471471
return (current = nodes);
472472
}

packages/dom-expressions/src/server.d.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
export const Aliases: Record<string, string>;
2+
export const Properties: Set<string>;
3+
export const ChildProperties: Set<string>;
4+
export const DelegatedEvents: Set<string>;
5+
export const DOMElements: Set<string>;
6+
export const SVGElements: Set<string>;
7+
export const SVGNamespace: Record<string, string>;
8+
export function getPropAlias(prop: string, tagName: string): string | undefined;
9+
110
export function renderToString<T>(
211
fn: () => T,
312
options?: {
@@ -87,3 +96,79 @@ export function pipeToNodeWritable<T>(
8796
onCompleteAll?: () => void;
8897
}
8998
): void;
99+
100+
export function untrack<T>(fn: () => T): T;
101+
102+
// client-only APIs
103+
104+
/** @deprecated not supported on the server side */
105+
export function classList(
106+
node: Element,
107+
value: { [k: string]: boolean },
108+
prev?: { [k: string]: boolean }
109+
): { [k: string]: boolean };
110+
111+
/** @deprecated not supported on the server side */
112+
export function style(
113+
node: Element,
114+
value: { [k: string]: string },
115+
prev?: { [k: string]: string }
116+
): void;
117+
118+
/** @deprecated not supported on the server side */
119+
export function insert<T>(
120+
parent: MountableElement,
121+
accessor: (() => T) | T,
122+
marker?: Node | null,
123+
init?: JSX.Element
124+
): JSX.Element;
125+
126+
/** @deprecated not supported on the server side */
127+
export function spread<T>(
128+
node: Element,
129+
accessor: (() => T) | T,
130+
isSVG?: Boolean,
131+
skipChildren?: Boolean
132+
): void;
133+
134+
/** @deprecated not supported on the server side */
135+
export function delegateEvents(eventNames: string[], d?: Document): void;
136+
/** @deprecated not supported on the server side */
137+
export function dynamicProperty(props: unknown, key: string): unknown;
138+
/** @deprecated not supported on the server side */
139+
export function setAttribute(node: Element, name: string, value: string): void;
140+
/** @deprecated not supported on the server side */
141+
export function setAttributeNS(node: Element, namespace: string, name: string, value: string): void;
142+
143+
/** @deprecated not supported on the server side */
144+
export function addEventListener(
145+
node: Element,
146+
name: string,
147+
handler: () => void,
148+
delegate: boolean
149+
): void;
150+
151+
/** @deprecated not supported on the server side */
152+
export function render(code: () => JSX.Element, element: MountableElement): () => void;
153+
/** @deprecated not supported on the server side */
154+
export function template(html: string, isCE?: boolean, isSVG?: boolean): () => Element;
155+
/** @deprecated not supported on the server side */
156+
export function setProperty(node: Element, name: string, value: any): void;
157+
/** @deprecated not supported on the server side */
158+
export function className(node: Element, value: string): void;
159+
/** @deprecated not supported on the server side */
160+
export function assign(node: Element, props: any, isSVG?: Boolean, skipChildren?: Boolean): void;
161+
162+
/** @deprecated not supported on the server side */
163+
export function hydrate(
164+
fn: () => JSX.Element,
165+
node: MountableElement,
166+
options?: { renderId?: string; owner?: unknown }
167+
): () => void;
168+
169+
/** @deprecated not supported on the server side */
170+
export function getNextElement(template?: HTMLTemplateElement): Element;
171+
/** @deprecated not supported on the server side */
172+
export function getNextMatch(start: Node, elementName: string): Element;
173+
/** @deprecated not supported on the server side */
174+
export function getNextMarker(start: Node): [Node, Array<Node>];

packages/dom-expressions/src/server.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Aliases, BooleanAttributes, ChildProperties } from "./constants";
22
import { sharedConfig, root } from "rxcore";
33
import { createSerializer, getLocalHeaderScript } from "./serializer";
4-
export { createComponent } from "rxcore";
4+
5+
export { getOwner, createComponent, effect, memo, untrack } from "rxcore";
56

67
export {
78
Properties,
@@ -685,3 +686,33 @@ export function ssrSpread(props, isSVG, skipChildren) {
685686
}
686687
return result;
687688
}
689+
690+
// client-only APIs
691+
692+
export {
693+
notSup as classList,
694+
notSup as style,
695+
notSup as insert,
696+
notSup as spread,
697+
notSup as delegateEvents,
698+
notSup as dynamicProperty,
699+
notSup as setAttribute,
700+
notSup as setAttributeNS,
701+
notSup as addEventListener,
702+
notSup as render,
703+
notSup as template,
704+
notSup as setProperty,
705+
notSup as className,
706+
notSup as assign,
707+
notSup as hydrate,
708+
notSup as getNextElement,
709+
notSup as getNextMatch,
710+
notSup as getNextMarker,
711+
notSup as runHydrationEvents
712+
};
713+
714+
function notSup() {
715+
throw new Error(
716+
"Client-only API called on the server side. Run client-only code in onMount, or conditionally run client-only component with <Show>."
717+
);
718+
}

0 commit comments

Comments
 (0)