Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed May 6, 2024
1 parent 577a976 commit b5bcd7b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-kings-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'preact-render-to-string': minor
---

Introduce a streaming renderer which can be imported from `preact-render-to-string/stream` and `preact-render-to-string/stream-node`
2 changes: 2 additions & 0 deletions jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ export default function render(
context?: any,
options?: Options
): string;

export function shallowRender(vnode: VNode, context?: any): string;
5 changes: 1 addition & 4 deletions src/internal.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// import { VNode } from 'preact';

type VNode = import('preact').VNode;
type ComponentChildren = import('preact').ComponentChildren;
import { ComponentChildren, VNode } from 'preact';

interface Suspended {
id: string;
Expand Down
14 changes: 4 additions & 10 deletions src/pretty.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
VOID_ELEMENTS,
NAMESPACE_REPLACE_REGEX,
SVG_CAMEL_CASE,
HTML_LOWER_CASE
HTML_LOWER_CASE,
getContext
} from './lib/util.js';
import { COMMIT, DIFF, DIFFED, RENDER, SKIP_EFFECTS } from './lib/constants.js';
import { options, Fragment } from 'preact';
Expand Down Expand Up @@ -122,18 +123,11 @@ function _renderToStringPretty(

let renderHook = options[RENDER];

let cctx = context;
let cxType = nodeName.contextType;
if (cxType != null) {
let provider = context[cxType.__c];
cctx = provider ? provider.props.value : cxType.__;
}

if (
!nodeName.prototype ||
typeof nodeName.prototype.render !== 'function'
) {
// let cctx = getContext(nodeName, context);
let cctx = getContext(nodeName, context);

// If a hook invokes setState() to invalidate the component during rendering,
// re-render it up to 25 times to allow "settling" of memoized states.
Expand All @@ -150,7 +144,7 @@ function _renderToStringPretty(
rendered = nodeName.call(vnode.__c, props, cctx);
}
} else {
// let cctx = getContext(nodeName, context);
let cctx = getContext(nodeName, context);

// c = new nodeName(props, context);
c = vnode.__c = new nodeName(props, cctx);
Expand Down
1 change: 0 additions & 1 deletion src/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export function renderToReadableStream(vnode, context) {
controller.error(error);
allReady.reject(error);
});
// controller.enqueue(encoder.encode(shell));
}
});

Expand Down

0 comments on commit b5bcd7b

Please sign in to comment.