Skip to content

Fixes #5140 - clean code of unused embed with side-effects - #5141

Merged
leaanthony merged 5 commits into
wailsapp:masterfrom
symball:embed_import_dupes
May 31, 2026
Merged

leaanthony merged 5 commits into
wailsapp:masterfrom
symball:embed_import_dupes

Conversation

@symball

@symball symball commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Just a small code clean leaving instances where embed used to create []byte representation of single files alone.

Example of import with side-effects not to be touched

import _ "embed"

//go:embed runtime.js
var RuntimeJS []byte

Fixes #5140

How Has This Been Tested?

On MacOS, ran the test suite and things passed to the same level

Summary by CodeRabbit

  • Chores
    • Removed unnecessary internal imports across the codebase to improve code cleanliness and maintainability.

@coderabbitai

coderabbitai Bot commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request removes unnecessary blank identifier imports (_ "embed") from 59 Go files across examples, internal tools, test cases, and templates. The blank imports are redundant since these files already import the embed package normally. A changelog entry documents this cleanup.

Changes

Cohort / File(s) Summary
Changelog
v3/UNRELEASED_CHANGELOG.md
Updated the Changed section to document removal of unnecessary _ "embed" imports for code tidying.
Example applications
v3/examples/android/main.go, v3/examples/badge*/main.go, v3/examples/build/main.go, v3/examples/clipboard/main.go, v3/examples/contextmenus/main.go, v3/examples/custom-protocol-example/main.go, v3/examples/dev/main.go, v3/examples/dialogs/main.go, v3/examples/dock/main.go, v3/examples/environment/main.go, v3/examples/events*/main.go, v3/examples/file-association/main.go, v3/examples/frameless/main.go, v3/examples/hide-window/main.go, v3/examples/ios/main.go, v3/examples/keybindings/main.go, v3/examples/notifications/main.go, v3/examples/plain/main.go, v3/examples/raw-message/main.go, v3/examples/show-macos-toolbar/main.go, v3/examples/systray*.../main.go, v3/examples/video/main.go, v3/examples/window-menu/main.go, v3/examples/wml/main.go
Removed redundant blank _ "embed" imports from import blocks while retaining functional embed imports.
Internal assetserver
v3/internal/assetserver/build_dev.go
Removed unnecessary blank embed import.
Internal commands
v3/internal/commands/appimage_testfiles/main.go, v3/internal/commands/build-assets.go, v3/internal/commands/version.go
Removed blank embed imports; minor reformatting in one getter method.
Internal generator
v3/internal/generator/collect/events.go, v3/internal/generator/testcases/.../main.go (20+ test case files)
Removed redundant _ "embed" imports from generator test case files.
Template
v3/internal/templates/_common/main.go.tmpl
Removed blank embed import from template; asset embedding directive preserved.
Logging service
v3/pkg/services/log/log.go
Removed unnecessary blank embed import.
Test files
v3/test/4769-menu/main.go, v3/test/manual/systray/.../main.go (5 systray test files)
Removed redundant blank embed imports from test and manual test applications.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • #4049: Related cleanup of blank embed imports in the assetserver module with similar code tidying objectives.

Suggested labels

Implemented in v3, v3-alpha, templates, size:XL

Suggested reviewers

  • leaanthony

Poem

🐰 Hopping through imports with a keen eye so bright,
Removing unused blanks, making code just right,
Embed without underscore, the cleanup is done,
Tidy repositories are ever such fun! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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
Title check ✅ Passed The title clearly and concisely summarizes the main change: removing unused embed imports with side-effects to clean up code.
Description check ✅ Passed The PR description explains the purpose (removing unnecessary _ "embed" imports), provides a clear example of what should be left alone, references the linked issue #5140, and includes testing information.
Linked Issues check ✅ Passed The PR fully addresses issue #5140 by removing redundant _ "embed" imports throughout the codebase while preserving imports used with //go:embed directives.
Out of Scope Changes check ✅ Passed All changes are in-scope: removing unused _ "embed" imports from 55+ files, with minor formatting fixes in a few files (plain/main.go, build-assets.go, variable_single_from_function/main.go, templates/_common/main.go.tmpl). These are directly related to the cleanup objective.

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

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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.17.0)
v3/examples/android/main.go

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

�[1m Loading rules from local config...�[0m

v3/examples/badge/main.go

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

�[1m Loading rules from local config...�[0m

v3/examples/contextmenus/main.go

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

�[1m Loading rules from local config...�[0m

  • 20 others

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
v3/UNRELEASED_CHANGELOG.md (1)

22-22: Consider tightening the changelog wording and linking the issue.

This reads a bit informal; using a direct phrasing with issue reference improves release-note clarity.

✏️ Proposed wording
-- Remove some unnecessary `_ "embed"` imports tidying the code a little
+- Remove unnecessary `_ "embed"` imports to tidy the codebase (`#5140`)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@v3/UNRELEASED_CHANGELOG.md` at line 22, Update the informal changelog entry
"Remove some unnecessary `_ \"embed\"` imports tidying the code a little" to a
tighter, release-note style sentence such as "Remove unnecessary `_ \"embed\"`
imports" and append a reference to the related issue or PR (e.g. "(`#1234`)" or a
full issue/PR URL) so the change is clear and traceable; ensure the `_ "embed"`
token is preserved exactly as shown and the change appears in
v3/UNRELEASED_CHANGELOG.md.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@v3/UNRELEASED_CHANGELOG.md`:
- Line 22: Update the informal changelog entry "Remove some unnecessary `_
\"embed\"` imports tidying the code a little" to a tighter, release-note style
sentence such as "Remove unnecessary `_ \"embed\"` imports" and append a
reference to the related issue or PR (e.g. "(`#1234`)" or a full issue/PR URL) so
the change is clear and traceable; ensure the `_ "embed"` token is preserved
exactly as shown and the change appears in v3/UNRELEASED_CHANGELOG.md.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6bb10e2a-2500-411b-a37a-963efc9e96cf

📥 Commits

Reviewing files that changed from the base of the PR and between bb4fbf9 and b839d13.

📒 Files selected for processing (71)
  • v3/UNRELEASED_CHANGELOG.md
  • v3/examples/android/main.go
  • v3/examples/badge-custom/main.go
  • v3/examples/badge/main.go
  • v3/examples/build/main.go
  • v3/examples/clipboard/main.go
  • v3/examples/contextmenus/main.go
  • v3/examples/custom-protocol-example/main.go
  • v3/examples/dev/main.go
  • v3/examples/dialogs/main.go
  • v3/examples/dock/main.go
  • v3/examples/environment/main.go
  • v3/examples/events-bug/main.go
  • v3/examples/events/main.go
  • v3/examples/file-association/main.go
  • v3/examples/frameless/main.go
  • v3/examples/hide-window/main.go
  • v3/examples/ios/main.go
  • v3/examples/keybindings/main.go
  • v3/examples/notifications/main.go
  • v3/examples/plain/main.go
  • v3/examples/raw-message/main.go
  • v3/examples/show-macos-toolbar/main.go
  • v3/examples/systray-basic/main.go
  • v3/examples/systray-custom/main.go
  • v3/examples/video/main.go
  • v3/examples/window-menu/main.go
  • v3/examples/wml/main.go
  • v3/internal/assetserver/build_dev.go
  • v3/internal/commands/appimage_testfiles/main.go
  • v3/internal/commands/build-assets.go
  • v3/internal/commands/version.go
  • v3/internal/generator/collect/events.go
  • v3/internal/generator/testcases/aliases/main.go
  • v3/internal/generator/testcases/complex_expressions/main.go
  • v3/internal/generator/testcases/complex_instantiations/main.go
  • v3/internal/generator/testcases/complex_json/main.go
  • v3/internal/generator/testcases/complex_method/main.go
  • v3/internal/generator/testcases/cyclic_imports/main.go
  • v3/internal/generator/testcases/cyclic_types/main.go
  • v3/internal/generator/testcases/directives/main.go
  • v3/internal/generator/testcases/enum/main.go
  • v3/internal/generator/testcases/enum_from_imported_package/main.go
  • v3/internal/generator/testcases/enum_map_keys/main.go
  • v3/internal/generator/testcases/function_from_imported_package/main.go
  • v3/internal/generator/testcases/function_from_nested_imported_package/main.go
  • v3/internal/generator/testcases/function_multiple_files/greet.go
  • v3/internal/generator/testcases/function_multiple_files/main.go
  • v3/internal/generator/testcases/function_single/main.go
  • v3/internal/generator/testcases/function_single_context/main.go
  • v3/internal/generator/testcases/function_single_internal/main.go
  • v3/internal/generator/testcases/map_keys/main.go
  • v3/internal/generator/testcases/marshalers/main.go
  • v3/internal/generator/testcases/out_of_tree/main.go
  • v3/internal/generator/testcases/struct_literal_multiple/main.go
  • v3/internal/generator/testcases/struct_literal_multiple_files/greet.go
  • v3/internal/generator/testcases/struct_literal_multiple_files/main.go
  • v3/internal/generator/testcases/struct_literal_multiple_other/main.go
  • v3/internal/generator/testcases/struct_literal_non_pointer_single/main.go
  • v3/internal/generator/testcases/struct_literal_single/main.go
  • v3/internal/generator/testcases/variable_single/main.go
  • v3/internal/generator/testcases/variable_single_from_function/main.go
  • v3/internal/generator/testcases/variable_single_from_other_function/main.go
  • v3/internal/templates/_common/main.go.tmpl
  • v3/pkg/services/log/log.go
  • v3/test/4769-menu/main.go
  • v3/test/manual/systray/custom-handlers/main.go
  • v3/test/manual/systray/hide-options/main.go
  • v3/test/manual/systray/menu-only/main.go
  • v3/test/manual/systray/window-menu/main.go
  • v3/test/manual/systray/window-only/main.go
💤 Files with no reviewable changes (46)
  • v3/examples/hide-window/main.go
  • v3/examples/build/main.go
  • v3/examples/clipboard/main.go
  • v3/examples/dialogs/main.go
  • v3/examples/video/main.go
  • v3/internal/generator/testcases/enum_from_imported_package/main.go
  • v3/examples/keybindings/main.go
  • v3/internal/generator/testcases/struct_literal_multiple_other/main.go
  • v3/examples/systray-custom/main.go
  • v3/internal/generator/testcases/variable_single/main.go
  • v3/internal/assetserver/build_dev.go
  • v3/internal/generator/testcases/complex_instantiations/main.go
  • v3/internal/generator/testcases/struct_literal_multiple_files/main.go
  • v3/internal/generator/testcases/function_multiple_files/main.go
  • v3/internal/generator/testcases/complex_expressions/main.go
  • v3/internal/generator/testcases/complex_method/main.go
  • v3/internal/commands/appimage_testfiles/main.go
  • v3/internal/generator/collect/events.go
  • v3/internal/generator/testcases/cyclic_imports/main.go
  • v3/internal/generator/testcases/variable_single_from_other_function/main.go
  • v3/internal/generator/testcases/marshalers/main.go
  • v3/internal/generator/testcases/cyclic_types/main.go
  • v3/examples/show-macos-toolbar/main.go
  • v3/examples/systray-basic/main.go
  • v3/internal/generator/testcases/function_single/main.go
  • v3/internal/generator/testcases/complex_json/main.go
  • v3/internal/generator/testcases/directives/main.go
  • v3/internal/generator/testcases/struct_literal_single/main.go
  • v3/internal/generator/testcases/function_from_nested_imported_package/main.go
  • v3/internal/commands/version.go
  • v3/internal/generator/testcases/function_multiple_files/greet.go
  • v3/internal/generator/testcases/struct_literal_multiple_files/greet.go
  • v3/internal/generator/testcases/struct_literal_non_pointer_single/main.go
  • v3/internal/generator/testcases/struct_literal_multiple/main.go
  • v3/test/manual/systray/custom-handlers/main.go
  • v3/internal/generator/testcases/out_of_tree/main.go
  • v3/test/manual/systray/window-only/main.go
  • v3/test/manual/systray/hide-options/main.go
  • v3/test/manual/systray/window-menu/main.go
  • v3/internal/generator/testcases/enum_map_keys/main.go
  • v3/internal/generator/testcases/function_from_imported_package/main.go
  • v3/test/manual/systray/menu-only/main.go
  • v3/internal/generator/testcases/map_keys/main.go
  • v3/internal/generator/testcases/enum/main.go
  • v3/examples/events-bug/main.go
  • v3/internal/generator/testcases/aliases/main.go

@leaanthony

leaanthony commented Apr 14, 2026 •

Copy link
Copy Markdown
Member

The macOS test failure isn't a build issue — it's a golden file mismatch in the binding generator tests. The test expects line 212 but gets 211 in the warning output for /testcases/marshalers/main.go. Removing the duplicate import shifted the line numbers in the test fixture.

To fix, delete the outdated golden warnings.log files from v3/internal/generator/testdata/output/ and re-run the tests — they will be recreated automatically with the correct line numbers:

find v3/internal/generator/testdata/output -name 'warnings.log' -delete
cd v3/internal/generator && go test ./...

Then commit the regenerated files.

@leaanthony
leaanthony changed the base branch from v3-alpha to master April 29, 2026 13:08
@leaanthony

Copy link
Copy Markdown
Member

✅ Triaged by Wails PR Reviewer

This PR has been reviewed and accepted.

Head Ref OID: c6a657d6fd11a907028b20e7f71b864d2747ef9f


This comment serves as a signature that this PR has been triaged. Future runs will skip this PR based on the headRefOid.

@leaanthony leaanthony added this to the v3.0.0-beta.1 milestone May 20, 2026
leaanthony
leaanthony previously approved these changes May 20, 2026

@leaanthony leaanthony left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM — careful removal of redundant _ "embed" imports. Each file that lost the blank import either retains a real "embed" import for its //go:embed directives, or has no embed directives at all. The build-tag-guarded file in internal/assetserver/build_dev.go was also checked and the removal is safe there too. Good cleanup.

@leaanthony
leaanthony dismissed their stale review May 20, 2026 13:24

Dismissing approval — PR has merge conflicts and CI failures (Windows + macOS Go tests) from April. Needs to be rebased against v3-alpha before it can be merged.

@leaanthony

Copy link
Copy Markdown
Member

The code change itself is correct, but this PR can't be merged as-is:

  • Merge conflicts — it has drifted from v3-alpha since April and is now conflicting
  • CI failures — Go tests failing on Windows and macOS (runs from April 14)

@symball — please rebase against v3-alpha, resolve conflicts, and push to trigger a fresh CI run. Happy to re-approve once it's green.

@leaanthony

Copy link
Copy Markdown
Member

Changelog wording noted — the suggestion to tighten "Remove some unnecessary..." to "Remove unnecessary..." and add the issue reference is a good improvement. Applied/accepted as-is since the PR is already approved (LGTM from maintainer). Will pick up in the merge commit message if needed.

@leaanthony

Copy link
Copy Markdown
Member

Hi @symball — this PR has a merge conflict (most likely in v3/UNRELEASED_CHANGELOG.md, which changes frequently with each alpha release). Could you rebase onto current master?

git fetch upstream
git rebase upstream/master
# if there's a conflict in UNRELEASED_CHANGELOG.md, just keep master's version and re-add your entry
git push --force-with-lease

The change itself is already approved (LGTM) — just needs the rebase to clear the conflict.

@leaanthony
leaanthony force-pushed the embed_import_dupes branch from c6a657d to 47e79e1 Compare May 31, 2026 03:20
… import removal

Removing `_ "embed"` from complex_json/main.go and marshalers/main.go shifted
line numbers by 1, invalidating the golden warning log snapshots.
@leaanthony

Copy link
Copy Markdown
Member

Fixed the CI failure — pushed directly to the branch.

Root cause: Removing _ "embed" from testcases/complex_json/main.go and testcases/marshalers/main.go shifted line numbers by 1, so the golden warnings.log snapshots were stale. Updated all 8 golden files:

  • complex_json/main.go:127 → :126
  • marshalers/main.go:212 → :211
  • marshalers/main.go:214 → :213

The TestDebouncing_RapidCallsOnlyLastFires failure is a pre-existing timing flake in the newly-introduced debounce package (landed in #5508) — not caused by this PR.

Windows OS timer granularity is ~15ms so time.Sleep(1ms) can actually
sleep 15ms, exceeding the 5ms debounce window and causing the timer to
fire mid-loop. Raise debounceAfter to 100ms and inter-call sleep to 5ms
so the ratio holds even on loaded CI runners.
@leaanthony

Copy link
Copy Markdown
Member

Pushed one more fix — the TestDebouncing_RapidCallsOnlyLastFires failure is also real (not just a flake):

Root cause: Windows OS timer granularity is ~15ms, so time.Sleep(1ms) can actually sleep 15ms — longer than the 5ms debounce window. The timer fired mid-loop, causing 2 callbacks instead of 1.

Fix (db8d299): Raised debounceAfter to 100ms and inter-call sleep to 5ms. The 20× ratio holds on any OS timer granularity. Verified passing 3× locally.

@leaanthony
leaanthony merged commit b802c17 into wailsapp:master May 31, 2026
11 of 12 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Wails Release Train Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

Remove unnecessary embed imports

2 participants