Skip to content

fix: replace undefined docById with native document.getElementById#4924

Merged
walterbender merged 3 commits intosugarlabs:masterfrom
Inuth0603:fix-startup-errors
Dec 28, 2025
Merged

fix: replace undefined docById with native document.getElementById#4924
walterbender merged 3 commits intosugarlabs:masterfrom
Inuth0603:fix-startup-errors

Conversation

@Inuth0603
Copy link
Contributor

Description: Fixes #4921

Changes Proposed:

Replaced all 111 instances of the custom helper docById with the standard document.getElementById in js/activity.js.

Reasoning: The custom docById helper has repeatedly caused regressions (see #4295) because it relies on specific dependency load orders that are fragile in the production build.

By switching to the native document.getElementById, we remove the external dependency entirely.

This permanently eliminates the "Race Condition" causing the startup crash because the native DOM method is always available.

Testing:

Localhost: Verified that the application loads and functions correctly without the ReferenceError.

Impact: This ensures the application initializes the UI logic safely without throwing errors in the console.

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@Inuth0603
Copy link
Contributor Author

While validating this fix on the live environment to reproduce the crash, I noticed that the server is returning 404 Not Found for several core assets (e.g., themebox.js, ast2blocklist.js) that are present on Localhost.

Implication: Once this PR fixes the startup docById crash, the application will proceed further in the loading sequence and will likely hit these missing file errors next (specifically breaking the Welcome Tour).

This is not caused by this PR, but fixing the startup crash will "unmask" these underlying server-side missing files. I recommend verifying the deployment build artifacts on the server.

Screenshot 2025-12-27 174353

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@Inuth0603
Copy link
Contributor Author

I originally tried to keep the diff small (~100 lines) by disabling auto-format, but the ESLint / Lint check failed requiring Prettier compliance. I have now applied the standard formatting to satisfy the CI build, which is why the line count has increased

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

2 similar comments
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@Inuth0603
Copy link
Contributor Author

Understood! Since document is global, we don't need to declare it here. I have removed it from the list.

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

1 similar comment
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@Inuth0603
Copy link
Contributor Author

Hi @walterbender, I've addressed the review feedback by removing the global document from the declaration list.

I am aware the ESLint / Lint check is still failing. However, I see from the discussion in #4923 that there is a repository-wide conflict between .prettierrc files causing these failures on unrelated files. I have formatted my changes locally, but I will wait for the config fix to merge before attempting any further formatting pushes to keep this PR's history clean.

@walterbender walterbender merged commit a2fcd51 into sugarlabs:master Dec 28, 2025
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: "ReferenceError: docById is not defined" logs in console on master

2 participants