Skip to content

Fix blank Query Tool screen caused by a malformed runtime locale (#7596)#10066

Open
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix/issue-7596-query-history-locale
Open

Fix blank Query Tool screen caused by a malformed runtime locale (#7596)#10066
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix/issue-7596-query-history-locale

Conversation

@dpage

@dpage dpage commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

The Query History panel formats entry dates/times with
Date.prototype.toLocaleDateString() / toLocaleTimeString() (called with no
arguments, i.e. using the runtime's default locale). On runtimes whose default
locale — derived from the OS/Electron environment — is malformed, V8 throws:

RangeError: Incorrect locale information provided

These helpers run during render (getGroupsgetGroupHeader
getDatePrefixisDaysBefore), so the uncaught exception unmounts the entire
SQL editor React tree. The user is left with a blank white screen and loses
any unsaved query work — the symptom reported in #7596 (and matching the 9.2
stack trace posted there).

This change guards both helpers and falls back to a moment-based format
(moment is already imported here and uses its own locale data, independent of
the broken Intl default), so the editor keeps working instead of crashing.

Scope note

#7596 is a long-running catch-all whose comments conflate several distinct
failures (an Object Explorer scroll crash reported fixed in 9.0, transient
network 500s, and this locale crash). This PR targets the locale RangeError
specifically — the most concrete, currently-reproducible cause.

Test plan

Closes #7596

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed an issue where the Query Tool would render a blank white screen when the system's runtime locale is malformed. Date and time formatting now gracefully handles locale errors.
  • Tests

    • Added test coverage for Query History date/time formatting with locale error handling.

The Query History panel formats entry dates/times with
Date.prototype.toLocaleDateString()/toLocaleTimeString(). On runtimes
whose default locale (derived from the OS/environment) is malformed,
these throw "RangeError: Incorrect locale information provided".

Because getDateFormatted()/getTimeFormatted() are called during render
(via getGroups/getGroupHeader/getDatePrefix), the uncaught exception
unmounts the whole SQL editor React tree, leaving the user with a blank
white screen and losing any unsaved query work.

Guard both helpers and fall back to a moment-based format (moment uses
its own locale data and does not depend on the broken Intl default) so
the editor keeps working instead of crashing.

Closes pgadmin-org#7596
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 99cc0949-255c-40ef-b9db-9cb455f5819f

📥 Commits

Reviewing files that changed from the base of the PR and between 04fa05c and 9e3b97e.

📒 Files selected for processing (3)
  • docs/en_US/release_notes_9_16.rst
  • web/pgadmin/tools/sqleditor/static/js/components/sections/QueryHistory.jsx
  • web/regression/javascript/sqleditor/QueryHistory.spec.js

Walkthrough

This PR fixes a blank-screen crash in the Query Tool by adding defensive error handling to Query History date/time formatting. When the runtime OS/Intl locale is malformed, Date.prototype.toLocaleDateString() and toLocaleTimeString() throw RangeError, causing an uncaught exception that unmounts the SQL editor. The fix wraps these calls in try/catch with moment.js fallback, prevents the crash, and includes full test coverage with a regression case.

Changes

Query Tool locale resilience

Layer / File(s) Summary
Locale-safe date/time formatting
web/pgadmin/tools/sqleditor/static/js/components/sections/QueryHistory.jsx
getDateFormatted and getTimeFormatted now export defensive implementations that catch RangeError from malformed locale methods and fall back to moment.js formatting with format('L') and format('LTS') respectively.
Query history formatting tests
web/regression/javascript/sqleditor/QueryHistory.spec.js
Jest test suite with mocks validates normal-case locale formatting and includes regression test ensuring helper functions don't propagate RangeError and return non-empty fallback strings when locale methods fail.
Release documentation
docs/en_US/release_notes_9_16.rst
Bug fixes entry for Issue #7596 documents the Query Tool blank-screen fix via guarded Query History date/time formatting.

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title directly and specifically describes the main fix: addressing a blank Query Tool screen caused by a malformed runtime locale, with issue reference.
Linked Issues check ✅ Passed The PR successfully addresses the root cause of issue #7596 by adding error handling for malformed locale formatting to prevent the RangeError from unmounting the SQL editor.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the malformed locale issue: enhanced date/time formatting helpers with try/catch, corresponding tests, and release notes documentation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Guards Query History date/time formatting in the SQL editor against RangeError: Incorrect locale information provided (malformed runtime locale) to prevent a render-time crash that blanks the Query Tool UI.

Changes:

  • Wrap toLocaleDateString() / toLocaleTimeString() in try/catch and fall back to moment formatting.
  • Add Jest regression coverage for both normal formatting and the RangeError fallback scenario.
  • Document the fix in the 9.16 release notes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
web/pgadmin/tools/sqleditor/static/js/components/sections/QueryHistory.jsx Adds guarded locale formatting with moment fallback to avoid render-time crashes.
web/regression/javascript/sqleditor/QueryHistory.spec.js Adds regression tests ensuring formatting does not throw when toLocale*String raises RangeError.
docs/en_US/release_notes_9_16.rst Adds a bug-fix entry for issue #7596.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +134 to 140
export function getDateFormatted(date) {
try {
return date.toLocaleDateString();
} catch {
return moment(date).format('L');
}
}
Comment on lines +142 to 148
export function getTimeFormatted(time) {
try {
return time.toLocaleTimeString();
} catch {
return moment(time).format('LTS');
}
}
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2025, The pgAdmin Development Team
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.

Screen goes white and unusable, losing all query progress as no ability to save

2 participants