-
-
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
Fix access to undefined exception #4219
Conversation
📊 Tachometer Benchmark ResultsSummaryduration
usedJSHeapSize
Results02_replace1k
duration
usedJSHeapSize
run-warmup-0
run-warmup-1
run-warmup-2
run-warmup-3
run-warmup-4
run-final
03_update10th1k_x16
duration
usedJSHeapSize
07_create10k
duration
usedJSHeapSize
filter_list
duration
usedJSHeapSize
hydrate1k
duration
usedJSHeapSize
many_updates
duration
usedJSHeapSize
text_update
duration
usedJSHeapSize
todo
duration
usedJSHeapSize
|
I should note, I hit this on 10.18.1. I tried updating to 10.19.2 and the issue persisted. I identified the issue and verified the fix by adding the I opened on 'main' as I see the same code exists there, but I can backport if desired. |
Mind giving some way to reproduce this issue as props are defaulted to an object https://github.com/preactjs/preact/blob/main/src/create-element.js |
It was in the middle of a larger codebase and only happened sporadically, but I'll try and conjure up a minimal repo. I assumed it could be null as a few lines later (427) it seems to check if it could have been null on the old node (via |
A repro or test case would be needed either way so we can prevent regressions. The old node is indeed nullable, this is during the creation scenario but then the new one is still defined |
OK. Just narrowed it down and got a minimal repro. It's a bug in my app's code, but I believe it still shouldn't be throwing an unhandled exception here. Basically, in one scenario it was passing an object for what should have been a string which is rendered in a text node location. This renders without error first time through, but on the re-render on changing some state unrelated to the problematic node, it throws the error. Load the below on an empty document, and when you click the checkbox to cause the re-render you'll see the issue. As the commented line states, if data is a string instead of an object (as it was supposed to be), then it re-renders fine. import { render } from "preact";
import { useState } from "preact/hooks";
window.onload = () => {
// *** If data is a string, it works fine ***
const data = { a: 10, b: "hello" };
render(<ReproApp data={data} />, document.body);
};
function ReproApp({ data }: any) {
const [showDetail, setShowDetail] = useState(false);
const toggleDetail = () => {
setShowDetail(!showDetail);
};
return (
<>
<p>Check the box to cause the error</p>
<input type="checkbox" checked={showDetail} onClick={toggleDetail} />
<div>{data}</div>
</>
);
} |
Thanks for providing a minimal test reproduction! Took the liberty of updating the PR. The observed issue is a symptom of another cause in that recent refactors lead to invalid vnodes being passed to |
Great! Thanks for the 'correct' fix, and super-fast turnaround. I love the project and use it whenever I can, so thanks for your work on it. |
Moving to 10.19.3 as it has my picture on it. (For a reason - it fixes the issue I hit when developing the widgets, preactjs/preact#4219).
Running some code locally and I was regularly hitting an error
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'is')
. I tracked it down to the line fixed in this PR.It would appear that sometimes
newVNode.props
may be undefined, so guarding against that.