Fix TypeError in switchActiveLanguage on pages without primary LSB#1490
Open
GasparSukk wants to merge 1 commit into
Open
Fix TypeError in switchActiveLanguage on pages without primary LSB#1490GasparSukk wants to merge 1 commit into
GasparSukk wants to merge 1 commit into
Conversation
switchActiveLanguage() reads _tabSwitchElements[_activeLanguage] and
iterates its .length at two spots. On admin pages that do not render
the primary LSB meta-box (ACF options pages, for example), the key is
never populated and the access throws:
TypeError: undefined is not an object (evaluating 'a.length')
Guard both reads with '|| []' so the function no-ops when there are
no primary LSBs to update — per-field/editor LSBs and the rest of the
switchActiveLanguage flow continue normally.
Regression introduced in 3.16.0 via the JS hooks refactor (qtranslate#1464 /
qtranslate#1469); 3.15.x did not touch _tabSwitchElements in this path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
switchActiveLanguage()throwsTypeError: undefined is not an object (evaluating 'a.length')on admin pages that do not render the primary LSB meta-box — ACF options pages are the most common case, but any page that only renders per-field/editor LSBs (noqtranxs-meta-box-lsb) is affected.Root cause
js/core/hooks/handlers.jsline 888 and 900:_tabSwitchElementsis populated only bycreateSetOfLSB()(the primary meta-box LSB). On pages that don't use it,_tabSwitchElements[_activeLanguage]isundefinedand.lengththrows. The crash aborts the language switch, so nothing updates.This is a regression introduced in 3.16.0 via the JS hooks refactor (#1464 / #1469). 3.15.x did not touch
_tabSwitchElementsinsideswitchActiveLanguage.Fix
Guard both reads with
|| []so the loop no-ops when there are no primary LSBs to update. Per-field/editor LSBs and the rest of theswitchActiveLanguageflow (wp.hooks actions,_onLoadLanguage, etc.) continue normally.Applied at both call sites in
switchActiveLanguage.Test plan