diff --git a/GEMINI_Svelte_and_Me.md b/GEMINI_Svelte_and_Me.md index cd787a9d..9fe1a1ef 100644 --- a/GEMINI_Svelte_and_Me.md +++ b/GEMINI_Svelte_and_Me.md @@ -83,4 +83,17 @@ My efficiency heavily relies on the `replace` tool, and precision is paramount. - **Consult Svelte Documentation:** The Svelte compiler often provides helpful links (`https://svelte.dev/e/js_parse_error`) which should be a first point of reference if the error is unfamiliar. - **Re-read File Content:** If a `replace` operation fails or produces unexpected results, immediately use `read_file` to verify the exact state of the file before attempting another change. -By following these guidelines, I aim to significantly reduce errors and improve my performance in Svelte development tasks. +## 5. Safe Property Binding (Preventing `props_invalid_value`) + +Svelte 5 enforces strict contracts for bound properties (`bind:prop`). If a component expects a property to have a fallback/default value, you cannot bind `undefined` to it. + +- **The Error:** `Uncaught Svelte error: props_invalid_value. Cannot do bind:prop={undefined} when prop has a fallback value`. +- **The Cause:** Attempting to bind a variable that is currently `undefined` to a component prop that has a default value (e.g., `let { prop = false } = $props()`). Svelte cannot determine whether to use the bound `undefined` or the component's internal default, so it throws an error. +- **The Fix:** **Always initialize bound variables.** + - **Initialization:** Ensure the variable you are binding to is initialized to a valid value (matching the prop's type) *before* the component mounts. + - Example: `let myVar = $state(false);` instead of `let myVar = $state();`. + - **Data Fetching:** If the data comes from an asynchronous source (API, DB), ensure the object properties have default values *immediately* upon assignment, even before the data is fully populated. + - **Good:** `$slct.obj = { ...apiResult, myBoundProp: apiResult.myBoundProp ?? false };` + - **Bad:** `$slct.obj = apiResult;` (if `apiResult.myBoundProp` is missing/undefined). + - **Updates/resets:** When resetting or updating the object, explicitly re-initialize the bound properties. + - `obj = {};` -> `obj = { myBoundProp: false };` \ No newline at end of file diff --git a/documentation/OLD_README_guidelines_ui_ux.md b/documentation/old/OLD_README_guidelines_ui_ux.md similarity index 100% rename from documentation/OLD_README_guidelines_ui_ux.md rename to documentation/old/OLD_README_guidelines_ui_ux.md diff --git a/documentation/OLD_README_guidelines_v1.md b/documentation/old/OLD_README_guidelines_v1.md similarity index 100% rename from documentation/OLD_README_guidelines_v1.md rename to documentation/old/OLD_README_guidelines_v1.md diff --git a/documentation/OLD_README_guidelines_v2.md b/documentation/old/OLD_README_guidelines_v2.md similarity index 100% rename from documentation/OLD_README_guidelines_v2.md rename to documentation/old/OLD_README_guidelines_v2.md diff --git a/src/routes/idaa/(idaa)/archives/[archive_id]/ae_idaa_comp__archive_content_obj_id_edit.svelte b/src/routes/idaa/(idaa)/archives/[archive_id]/ae_idaa_comp__archive_content_obj_id_edit.svelte index 9b8b5d4a..c08c60af 100644 --- a/src/routes/idaa/(idaa)/archives/[archive_id]/ae_idaa_comp__archive_content_obj_id_edit.svelte +++ b/src/routes/idaa/(idaa)/archives/[archive_id]/ae_idaa_comp__archive_content_obj_id_edit.svelte @@ -47,6 +47,24 @@ if ($idaa_slct.archive_content_id) { console.log(`Archive Content ID selected: ${$idaa_slct.archive_content_id}`); console.log(`Archive Content Object selected: ${$idaa_slct.archive_content_obj}`); + if ( + $idaa_slct.archive_content_obj && + $idaa_slct.archive_content_obj.upload_complete === undefined + ) { + $idaa_slct.archive_content_obj.upload_complete = false; + } + if ( + $idaa_slct.archive_content_obj && + !Array.isArray($idaa_slct.archive_content_obj.hosted_file_id_li) + ) { + $idaa_slct.archive_content_obj.hosted_file_id_li = []; + } + if ( + $idaa_slct.archive_content_obj && + !Array.isArray($idaa_slct.archive_content_obj.hosted_file_obj_li) + ) { + $idaa_slct.archive_content_obj.hosted_file_obj_li = []; + } } else { $idaa_slct.archive_content_id = null; $idaa_slct.archive_content_obj = { @@ -71,7 +89,10 @@ hide: false, priority: null, sort: null, - notes: null + notes: null, + upload_complete: false, + hosted_file_id_li: [], + hosted_file_obj_li: [] }; console.log(`Archive Content Object started: ${$idaa_slct.archive_content_obj}`); } @@ -251,6 +272,9 @@ $idaa_slct.archive_content_obj = archive_content_obj_create_result; $idaa_slct.archive_content_obj.archive_content_id = archive_content_obj_create_result.archive_content_id_random; // This is because we need use the string ID, not int ID. + $idaa_slct.archive_content_obj.upload_complete = false; + $idaa_slct.archive_content_obj.hosted_file_id_li = []; + $idaa_slct.archive_content_obj.hosted_file_obj_li = []; return archive_content_obj_create_result; }) @@ -321,6 +345,13 @@ .then(function (archive_content_obj_update_result) { // $idaa_slct.archive_content_obj = $lq__archive_content_obj; $idaa_slct.archive_content_obj = archive_content_obj_update_result; + $idaa_slct.archive_content_obj.upload_complete = true; + if (!Array.isArray($idaa_slct.archive_content_obj.hosted_file_id_li)) { + $idaa_slct.archive_content_obj.hosted_file_id_li = []; + } + if (!Array.isArray($idaa_slct.archive_content_obj.hosted_file_obj_li)) { + $idaa_slct.archive_content_obj.hosted_file_obj_li = []; + } }) .catch(function (error: any) { console.log('Something went wrong.'); @@ -364,6 +395,13 @@ .then(function (archive_content_obj_update_result) { // $idaa_slct.archive_content_obj = $lq__archive_content_obj; $idaa_slct.archive_content_obj = archive_content_obj_update_result; + $idaa_slct.archive_content_obj.upload_complete = false; + if (!Array.isArray($idaa_slct.archive_content_obj.hosted_file_id_li)) { + $idaa_slct.archive_content_obj.hosted_file_id_li = []; + } + if (!Array.isArray($idaa_slct.archive_content_obj.hosted_file_obj_li)) { + $idaa_slct.archive_content_obj.hosted_file_obj_li = []; + } }) .catch(function (error: any) { console.log('Something went wrong.'); @@ -620,6 +658,10 @@ $idaa_slct.archive_content_obj.file_path = null; $idaa_slct.archive_content_obj.filename = null; $idaa_slct.archive_content_obj.file_extension = null; + + $idaa_slct.archive_content_obj.upload_complete = false; + $idaa_slct.archive_content_obj.hosted_file_id_li = []; + $idaa_slct.archive_content_obj.hosted_file_obj_li = []; }); } }}