Skip to content

Commit 46b5eec

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 46b5eec

File tree

4 files changed

+124
-3
lines changed

4 files changed

+124
-3
lines changed

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

+3-2
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

+1-1
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

+86
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,80 @@ export function pipeToNodeWritable<T>(
8796
onCompleteAll?: () => void;
8897
}
8998
): void;
99+
100+
// client-only APIs
101+
102+
/** @deprecated not supported on the server side */
103+
export function classList(
104+
node: Element,
105+
value: { [k: string]: boolean },
106+
prev?: { [k: string]: boolean }
107+
): { [k: string]: boolean };
108+
109+
/** @deprecated not supported on the server side */
110+
export function style(
111+
node: Element,
112+
value: { [k: string]: string },
113+
prev?: { [k: string]: string }
114+
): void;
115+
116+
/** @deprecated not supported on the server side */
117+
export function insert<T>(
118+
parent: MountableElement,
119+
accessor: (() => T) | T,
120+
marker?: Node | null,
121+
init?: JSX.Element
122+
): JSX.Element;
123+
124+
/** @deprecated not supported on the server side */
125+
export function untrack<T>(fn: () => T): T;
126+
127+
/** @deprecated not supported on the server side */
128+
export function spread<T>(
129+
node: Element,
130+
accessor: (() => T) | T,
131+
isSVG?: Boolean,
132+
skipChildren?: Boolean
133+
): void;
134+
135+
/** @deprecated not supported on the server side */
136+
export function delegateEvents(eventNames: string[], d?: Document): void;
137+
/** @deprecated not supported on the server side */
138+
export function dynamicProperty(props: unknown, key: string): unknown;
139+
/** @deprecated not supported on the server side */
140+
export function setAttribute(node: Element, name: string, value: string): void;
141+
/** @deprecated not supported on the server side */
142+
export function setAttributeNS(node: Element, namespace: string, name: string, value: string): void;
143+
144+
/** @deprecated not supported on the server side */
145+
export function addEventListener(
146+
node: Element,
147+
name: string,
148+
handler: () => void,
149+
delegate: boolean
150+
): void;
151+
152+
/** @deprecated not supported on the server side */
153+
export function render(code: () => JSX.Element, element: MountableElement): () => void;
154+
/** @deprecated not supported on the server side */
155+
export function template(html: string, isCE?: boolean, isSVG?: boolean): () => Element;
156+
/** @deprecated not supported on the server side */
157+
export function setProperty(node: Element, name: string, value: any): void;
158+
/** @deprecated not supported on the server side */
159+
export function className(node: Element, value: string): void;
160+
/** @deprecated not supported on the server side */
161+
export function assign(node: Element, props: any, isSVG?: Boolean, skipChildren?: Boolean): void;
162+
163+
/** @deprecated not supported on the server side */
164+
export function hydrate(
165+
fn: () => JSX.Element,
166+
node: MountableElement,
167+
options?: { renderId?: string; owner?: unknown }
168+
): () => void;
169+
170+
/** @deprecated not supported on the server side */
171+
export function getNextElement(template?: HTMLTemplateElement): Element;
172+
/** @deprecated not supported on the server side */
173+
export function getNextMatch(start: Node, elementName: string): Element;
174+
/** @deprecated not supported on the server side */
175+
export function getNextMarker(start: Node): [Node, Array<Node>];

packages/dom-expressions/src/server.js

+34
Original file line numberDiff line numberDiff line change
@@ -685,3 +685,37 @@ export function ssrSpread(props, isSVG, skipChildren) {
685685
}
686686
return result;
687687
}
688+
689+
// client-only APIs
690+
691+
export {
692+
notSup as classList,
693+
notSup as style,
694+
notSup as effect,
695+
notSup as memo,
696+
notSup as insert,
697+
notSup as untrack,
698+
notSup as spread,
699+
notSup as getOwner,
700+
notSup as delegateEvents,
701+
notSup as dynamicProperty,
702+
notSup as setAttribute,
703+
notSup as setAttributeNS,
704+
notSup as addEventListener,
705+
notSup as render,
706+
notSup as template,
707+
notSup as setProperty,
708+
notSup as className,
709+
notSup as assign,
710+
notSup as hydrate,
711+
notSup as getNextElement,
712+
notSup as getNextMatch,
713+
notSup as getNextMarker,
714+
notSup as runHydrationEvents
715+
};
716+
717+
function notSup() {
718+
throw new Error(
719+
"Client-only API called on the server side. Run client-only code in onMount, or conditionally run client-only component with <Show>."
720+
);
721+
}

0 commit comments

Comments
 (0)