Skip to content

Fix no-Worker search fallback postMessage handling - #4114

Open
Vinayak1337 wants to merge 4 commits into
mkdocs:masterfrom
Vinayak1337:fix/search-fallback-postmessage
Open

Vinayak1337 wants to merge 4 commits into
mkdocs:masterfrom
Vinayak1337:fix/search-fallback-postmessage

Conversation

@Vinayak1337

@Vinayak1337 Vinayak1337 commented May 14, 2026 •

Copy link
Copy Markdown

Fixes #4106.

Summary

  • avoid replacing the browser's global window.postMessage in the no-Worker search fallback
  • route search worker messages through a small sendMessage helper so worker and main-thread fallback modes keep the same message path
  • remove the fallback's jQuery script-loader dependency so current generated MkDocs pages can initialize search when Worker is unavailable
  • add regression coverage for the fallback script behavior

Tests

  • uv run --python 3.12 --with '.[i18n]' python -m unittest discover -s mkdocs -p '*tests.py'
  • uv run --python 3.12 --with '.[i18n]' --with pymdown-extensions --with markdown-callouts --with mdx-gh-links --with mkdocs-autorefs --with mkdocs-click --with mkdocs-literate-nav --with mkdocs-redirects --with mkdocstrings --with mkdocstrings-python python -m mkdocs.tests.integration
  • npm exec --yes -- jshint mkdocs/
  • uv run --python 3.12 --with-requirements requirements/requirements-style.txt ruff check mkdocs/tests/search_tests.py
  • uv run --python 3.12 --with-requirements requirements/requirements-style.txt black -q --check --diff mkdocs/tests/search_tests.py
  • uv run --python 3.12 --with isort isort --check-only --diff mkdocs/tests/search_tests.py
  • git diff --check

Manual validation

  • built a temporary MkDocs site from this branch and confirmed the generated search/main.js and search/worker.js no longer contain window.postMessage = or $.getScript
  • served the generated site locally and confirmed the normal Web Worker search UI returns visible results for postmessageprobe
  • served a second copy with window.Worker disabled before search/main.js loads; confirmed search initializes, no console errors occur, window.postMessage remains unchanged, native postMessage still delivers messages, and the visible search UI returns the expected Search Target result

This branch has not been deployed

No deployments
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.

Built-in search overrides global window.postMessage in no-Worker fallback

1 participant