Skip to content
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

Issueid #0000 iframe height for fill in the blanks #188

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/views/Practice/Practice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,11 @@ const Practice = () => {
questions[currentQuestion]?.contentSourceData || [];
const stringLengths = contentSourceData.map((item) => item.text.length);
const length =
questions[currentQuestion]?.mechanics_data &&
(questions[currentQuestion]?.mechanics_data &&
questions[currentQuestion]?.mechanics_data[0]?.mechanics_id ===
"mechanic_2") ||
questions[currentQuestion]?.mechanics_data[0]?.mechanics_id ===
"mechanic_2"
"mechanic_1"
? 500
: stringLengths[0];
Comment on lines +719 to 725
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure safe access to mechanics_data to prevent potential errors

The condition accesses questions[currentQuestion]?.mechanics_data[0]?.mechanics_id without verifying that mechanics_data exists. This could lead to a TypeError if mechanics_data is undefined or null. Please add a null check before accessing mechanics_data[0] to ensure safe operation.

Apply this diff to fix the issue:

-              (questions[currentQuestion]?.mechanics_data &&
-                questions[currentQuestion]?.mechanics_data[0]?.mechanics_id ===
-                  "mechanic_2") ||
-              questions[currentQuestion]?.mechanics_data[0]?.mechanics_id ===
-                "mechanic_1"
+              (questions[currentQuestion]?.mechanics_data &&
+                (questions[currentQuestion]?.mechanics_data[0]?.mechanics_id ===
+                  "mechanic_2" ||
+                  questions[currentQuestion]?.mechanics_data[0]?.mechanics_id ===
+                  "mechanic_1"))

This adjustment ensures that mechanics_data is present before accessing mechanics_data[0], preventing potential runtime errors.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(questions[currentQuestion]?.mechanics_data &&
questions[currentQuestion]?.mechanics_data[0]?.mechanics_id ===
"mechanic_2") ||
questions[currentQuestion]?.mechanics_data[0]?.mechanics_id ===
"mechanic_2"
"mechanic_1"
? 500
: stringLengths[0];
(questions[currentQuestion]?.mechanics_data &&
(questions[currentQuestion]?.mechanics_data[0]?.mechanics_id ===
"mechanic_2" ||
questions[currentQuestion]?.mechanics_data[0]?.mechanics_id ===
"mechanic_1"))
? 500
: stringLengths[0];

window.parent.postMessage({ type: "stringLengths", length }, "*");
Expand Down