Skip to content

Commit

Permalink
Merge branch 'main' into test-skipping-lifecycles-for-funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed May 23, 2024
2 parents 3141810 + 8d228d2 commit a0f1f7c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 27 deletions.
13 changes: 12 additions & 1 deletion compat/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ try {
);
}

var renderToPipeableStream;
try {
const mod = require('preact-render-to-string/stream-node');
renderToPipeableStream = mod.default || mod.renderToPipeableStream || mod;
} catch (e) {
throw Error(
'renderToPipeableStream() error: update "preact-render-to-string" dependency to at least 6.5.0.'
);
}

module.exports = {
renderToString: renderToString,
renderToStaticMarkup: renderToString
renderToStaticMarkup: renderToString,
renderToPipeableStream: renderToPipeableStream
};
5 changes: 4 additions & 1 deletion compat/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export {
renderToString as renderToStaticMarkup
} from 'preact-render-to-string';

export { renderToPipeableStream } from 'preact-render-to-string/stream-node'

export default {
renderToString,
renderToStaticMarkup: renderToString
renderToStaticMarkup: renderToString,
renderToPipeableStream
};
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
"npm-merge-driver-install": "^1.1.1",
"npm-run-all": "^4.0.0",
"oxlint": "^0.3.4",
"preact-render-to-string": "^5.2.5",
"preact-render-to-string": "^6.5.0",
"prop-types": "^15.7.2",
"sade": "^1.7.4",
"sinon": "^9.2.3",
Expand Down
24 changes: 8 additions & 16 deletions src/create-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,19 @@ export function createContext(defaultValue, contextId) {
/** @type {FunctionComponent} */
Provider(props) {
if (!this.getChildContext) {
/** @type {Component[]} */
/** @type {Component[] | null} */
let subs = [];
let ctx = {};
ctx[contextId] = this;

this.getChildContext = () => ctx;

this.componentWillUnmount = () => {
subs = null;
};

this.shouldComponentUpdate = function (_props) {
if (this.props.value !== _props.value) {
// I think the forced value propagation here was only needed when `options.debounceRendering` was being bypassed:
// https://github.com/preactjs/preact/commit/4d339fb803bea09e9f198abf38ca1bf8ea4b7771#diff-54682ce380935a717e41b8bfc54737f6R358
// In those cases though, even with the value corrected, we're double-rendering all nodes.
// It might be better to just tell folks not to use force-sync mode.
// Currently, using `useContext()` in a class component will overwrite its `this.context` value.
// subs.some(c => {
// c.context = _props.value;
// enqueueRender(c);
// });

// subs.some(c => {
// c.context[contextId] = _props.value;
// enqueueRender(c);
// });
subs.some(c => {
c._force = true;
enqueueRender(c);
Expand All @@ -52,7 +42,9 @@ export function createContext(defaultValue, contextId) {
subs.push(c);
let old = c.componentWillUnmount;
c.componentWillUnmount = () => {
subs.splice(subs.indexOf(c), 1);
if (subs) {
subs.splice(subs.indexOf(c), 1);
}
if (old) old.call(c);
};
};
Expand Down
3 changes: 2 additions & 1 deletion src/diff/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export function setProperty(dom, name, value, oldValue, namespace) {
name != 'rowSpan' &&
name != 'colSpan' &&
name != 'role' &&
name != 'popover' &&
name in dom
) {
try {
Expand All @@ -135,7 +136,7 @@ export function setProperty(dom, name, value, oldValue, namespace) {
if (typeof value == 'function') {
// never serialize functions as attribute values
} else if (value != null && (value !== false || name[4] === '-')) {
dom.setAttribute(name, value);
dom.setAttribute(name, name == 'popover' && value == true ? '' : value);
} else {
dom.removeAttribute(name);
}
Expand Down
15 changes: 15 additions & 0 deletions test/browser/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,21 @@ describe('render()', () => {
expect(scratch.firstChild.spellcheck).to.equal(false);
});

it('should support popover auto', () => {
render(<div popover="auto" />, scratch);
expect(scratch.innerHTML).to.equal("<div popover=\"auto\"></div>");
});

it('should support popover true boolean', () => {
render(<div popover />, scratch);
expect(scratch.innerHTML).to.equal("<div popover=\"\"></div>");
});

it('should support popover false boolean', () => {
render(<div popover={false} />, scratch);
expect(scratch.innerHTML).to.equal("<div></div>");
});

// Test for preactjs/preact#4340
it('should respect defaultValue in render', () => {
scratch.innerHTML = '<input value="foo">';
Expand Down

0 comments on commit a0f1f7c

Please sign in to comment.