-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for Context as JSX #4618
Allow for Context as JSX #4618
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
📊 Tachometer Benchmark ResultsSummaryduration
usedJSHeapSize
Resultscreate10kduration
usedJSHeapSize
filter-listduration
usedJSHeapSize
hydrate1kduration
usedJSHeapSize
many-updatesduration
usedJSHeapSize
replace1kduration
usedJSHeapSize
run-warmup-0
run-warmup-1
run-warmup-2
run-warmup-3
run-warmup-4
run-final
text-updateduration
usedJSHeapSize
tododuration
usedJSHeapSize
update10th1kduration
usedJSHeapSize
|
Size Change: +1 B (0%) Total Size: 62.4 kB
ℹ️ View Unchanged
|
bcb933b
to
1006fd9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 6 out of 8 changed files in this pull request and generated no comments.
Files not reviewed (2)
- compat/src/render.js: Evaluated as low risk
- compat/test/browser/render.test.js: Evaluated as low risk
bdc5f94
to
e471217
Compare
e471217
to
4163c13
Compare
I'm good with this, though I do wonder if we should just implement it in core. import { enqueueRender } from './component';
export let i = 0;
export function createContext(defaultValue) {
/** @type {import('./internal').FunctionComponent} */
function Context(props) {
if (!this.getChildContext) {
/** @type {Set<import('./internal').Component> | null} */
let subs = new Set();
let ctx = {};
ctx[Context._id] = this;
this.getChildContext = () => ctx;
this.componentWillUnmount = () => {
subs = null;
};
this.shouldComponentUpdate = function (_props) {
if (this.props.value !== _props.value) {
subs.forEach((c) => {
c._force = true;
enqueueRender(c);
});
}
};
this.sub = (c) => {
subs.add(c);
let old = c.componentWillUnmount;
c.componentWillUnmount = () => {
if (subs) {
subs.delete(c);
}
if (old) old.call(c);
};
};
}
return props.children;
}
Context._id = '__cC' + i++;
Context._defaultValue = defaultValue;
/** @type {import('./internal').FunctionComponent} */
Context.Consumer = (props, contextValue) => {
return props.children(contextValue);
};
// we could also get rid of _contextRef entirely
Context.Provider = Context._contextRef = Context.Consumer.contextType = Context;
return Context;
} |
+1 for core if the snippet @developit provided works |
b22f51d
to
d310b3a
Compare
@developit @marvinhagemeister added the suggestion |
d310b3a
to
75beb76
Compare
This PR adds another piece of React 19 functionality where we allow the result of
createContext
to act as aProvider
.Relates to #4613
Depends on preactjs/preact-devtools#493