Skip to content

adds a polyfill for iterator-helpers#8877

Open
normanrz wants to merge 11 commits into
masterfrom
iterator-helper-polyfill
Open

adds a polyfill for iterator-helpers#8877
normanrz wants to merge 11 commits into
masterfrom
iterator-helper-polyfill

Conversation

@normanrz
Copy link
Copy Markdown
Member

Adds a polyfill for iterator-helpers, because some people haven't upgraded their browsers yet.

@normanrz normanrz requested a review from hotzenklotz August 26, 2025 13:11
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 26, 2025

📝 Walkthrough

Walkthrough

Adds two top-level polyfill imports for iterator helpers and Set methods to the frontend entry point and introduces core-js@^3.45.1 as a runtime dependency in package.json. No other code, exports, or configuration changes.

Changes

Cohort / File(s) Summary
Polyfill initialization
frontend/javascripts/main.tsx
Prepends import "core-js/actual/iterator"; and import "core-js/actual/set"; before existing imports to ensure iterator helpers and Set methods are available at module initialization. No other changes.
Dependencies update
package.json
Adds runtime dependency "core-js": "^3.45.1" to dependencies. No removals or other section edits.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

dependencies

Suggested reviewers

  • philippotto

Poem

I nibbled bits of polyfill hay,
Sprinkled helpers to smooth the way.
Sets and iterators now hum along,
I hop, I test, I sing a song.
Ship it softly — code grown strong. 🐰✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7ff0099 and 7679aae.

📒 Files selected for processing (1)
  • frontend/javascripts/main.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/javascripts/main.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: backend-tests
  • GitHub Check: build-smoketest-push
  • GitHub Check: frontend-tests
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch iterator-helper-polyfill

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hotzenklotz
Copy link
Copy Markdown
Member

How can we test this? Does webpack/esbuild not remove this immediately with our selected browser targets?

@hotzenklotz
Copy link
Copy Markdown
Member

... because some people haven't upgraded their browsers yet.

BTW, we have a browser check for the iterator helpers here:

Did those people at least see our warning to update their browser?

Base automatically changed from voxel-size-placeholder to master August 26, 2025 13:17
@normanrz
Copy link
Copy Markdown
Member Author

... because some people haven't upgraded their browsers yet.

BTW, we have a browser check for the iterator helpers here:

Did those people at least see our warning to update their browser?

It did show up. I don't think they would update their browser just for WK, though. Sometimes they can't do that on their own, because of IT policies.

@normanrz
Copy link
Copy Markdown
Member Author

How can we test this? Does webpack/esbuild not remove this immediately with our selected browser targets?

Maybe we should relax our browser targets. We don't rely on terribly new features apart for code convenience, no? Maybe we should switch to "defaults" and add the relevant polyfills.

@hotzenklotz
Copy link
Copy Markdown
Member

We don't rely on terribly new features apart for code convenience, no?

In case of the iterator helpers, it is a performance improvement more than code convenience. Not sure, what browser features we need for WebGL...

Maybe we should switch to "defaults"

defaults yields Chrome 109, which is from January 2023, more than 2.5 years ago. 🤔 Something like since 2024 has higher coverage and is easier to understand, but requires us to update it every so often.

... and add the relevant polyfills.

Isn't that the whole point of using browser list that the build tools automatically add polyfills?

@normanrz
Copy link
Copy Markdown
Member Author

We don't rely on terribly new features apart for code convenience, no?

In case of the iterator helpers, it is a performance improvement more than code convenience.

Well, a flatMap is pretty much

function* flatMap(it, func) {
    for (const value of it) {
        const mappedValues = func(value);
        yield* mappedValues;
    }
}

That is not a feature that just the runtime can implement, like a new data strucure or syntax. So, it falls in the code convienence category.

Not sure, what browser features we need for WebGL...

Nothing recent comes to mind.

Maybe we should switch to "defaults"

defaults yields Chrome 109, which is from January 2023, more than 2.5 years ago. 🤔 Something like since 2024 has higher coverage and is easier to understand, but requires us to update it every so often.

I think that would be much better than "last 3 versions".

... and add the relevant polyfills.

Isn't that the whole point of using browser list that the build tools automatically add polyfills?

Esbuild doesn't inject polyfills that and recommends the use of core-js. Since we are not using babel, I don't think we have any polyfills in there now.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
frontend/javascripts/main.tsx (1)

1-1: No explicit iterator-helper usage detected; reconsider this polyfill and its placement.

Our search across frontend/javascripts TS/TSX files found no direct calls to Iterator.from or any Iterator.prototype.* helpers. If your code isn’t actually using these iterator helpers, you may not need this import at all.

However, we did discover an additional entry point in frontend/javascripts/libs/DRACOLoader.ts (line 241) which spawns a web worker for DRACOWorker.worker.js. Polyfills loaded in main.tsx won’t apply inside that worker, potentially leading to runtime errors if the worker ever uses iterator helpers.

To ensure both correct feature detection and broad runtime support:

  • Consider removing the import entirely if iterator helpers aren’t in use.
  • Or centralize iterator polyfills in a shared polyfills.ts that’s imported before app initialization (and included in your worker bundles).
  • Alternatively, update libs/browser_feature_check to distinguish native vs. polyfilled support so that your “outdated browser” warning isn’t masked by a polyfill.

Let me know which approach you’d prefer.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 96a88c0 and 7ff0099.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • frontend/javascripts/main.tsx (1 hunks)
  • package.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: backend-tests
  • GitHub Check: build-smoketest-push

Comment thread package.json
"classnames": "^2.2.5",
"color-hash": "^2.0.1",
"comlink": "^4.3.0",
"core-js": "^3.45.1",
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.

💡 Verification agent

❓ Verification inconclusive

Runtime dep looks good; ensure the module path exists in this version.

Adding core-js as a production dependency is appropriate for runtime polyfills.

Run to verify the imported path resolves with the chosen version:


🏁 Script executed:

#!/bin/bash
# Confirm the iterator helpers entry exists in installed core-js
node -e "console.log(require.resolve('core-js/actual/iterator'))"

Length of output: 838


Invalid core-js import path requires correction

Running

node -e "console.log(require.resolve('core-js/actual/iterator'))"

on core-js@3.45.1 throws MODULE_NOT_FOUND, which means the entry point you’re importing doesn’t exist at runtime. You must update the import to a valid module path to avoid breaking your build.

• Locate every occurrence of

require('core-js/actual/iterator')

(or the equivalent ES module import) in your code.
• If you need the stage-3 iterator helpers proposal, replace it with:

-require('core-js/actual/iterator')
+require('core-js/proposals/iterator-helpers')

• If you only need core JS’s standard iterator polyfills, use one of the supported entry points, for example:

require('core-js/features/iterator');
// or
require('core-js/modules/es.array.iterator');

After updating, verify that the new path resolves correctly:

node -e "console.log(require.resolve('core-js/proposals/iterator-helpers'))"
🤖 Prompt for AI Agents
package.json around line 145: the project depends on core-js@3.45.1 but code
imports the non-existent entry point "core-js/actual/iterator", which causes
MODULE_NOT_FOUND at runtime; search the repo for any occurrences of
require('core-js/actual/iterator') or equivalent ESM imports and replace them
with a valid entry such as 'core-js/features/iterator' or
'core-js/modules/es.array.iterator' (or if you need the stage-3 proposal use
'core-js/proposals/iterator-helpers' and ensure that proposal package is
available), then run node -e "console.log(require.resolve('<chosen-path>'))" to
confirm resolution and update any build/config files accordingly.

@hotzenklotz hotzenklotz mentioned this pull request Jan 13, 2026
11 tasks
hotzenklotz added a commit that referenced this pull request Feb 25, 2026
High-level overview:
- Replace the `webpack` frontend builds with `vite`
- Internally, [Typescript and JSX
compilation](https://vite.dev/guide/features#typescript) are still
handled through `esbuild`
- Internally, JS bundling is handled by `rollup`(soon to be replace with
it's Rust re-write 'rolldown')
- Internally, CSS/LESS compilation is handled by
[PostCSS](https://github.com/postcss/postcss)
- Updated `vitest` test runners to use the base `vite` config. In other
words, tests and production build should use the same plugins, settings,
transformations (e.g. protobuf handling), package versions, etc.
- `vite` treats the `index.html` file as the main starting point. I
moved the `index.html.scala` out of the `Play` into a separate
`<root>/index.html` file, without backend templating.
- Added a small, custom vite plugin for handling `protobuf` files.
Essentially, it does the same protobuf-to-JSON conversions as previously
provided by `global_mocks.ts`.
- `vite` is configured to a [broader baseline of Browser
version](https://vite.dev/guide/build#browser-compatibility) for JS
compatibility. (related to #8877 ) It does not, however, include
polyfills:
  ```
  Chrome >=107
  Edge >=107
  Firefox >=104
  Safari >=16
  ```
- added a new `<FailedToLoadView>` React view, when WK is unable to
initialized. Most often this is the case, when the backend is still
compiling and not yet responding. Inspired by `proxy.js` waiting/error
page.

### Asset Management
- All static frontend assets (images, wasm-files) have been moved from
`/public` to `/frontend/assets`. In other words, frontend asset handling
was moved from `Play framework` to `vite`.
- During the build process, vite copies all managed assets together with
the bundled JS in the `/public` folder. Play will then serve them as
static files.
- Ideally, one could import every image in the frontend code, e.g.
import MyImage from "images/my_image.png`. This would guarantee that
files are checked to named correctly/available. I have not YET done that
in this PR. I configured vite configured `vite? to use frontend/assets
as an asset directory. Another use case,
   
- ### Dev Environment
  - `vite` ships with a builtin dev server incl. hot reloading
- In dev mode, JS is is not bundled but rather served as raw ES modules
- Frontend asset, ie. JS, images, wasm are all served by the vite dev
server
- the vite dev server has a built-in proxy to forward API calls to the
backend
- Updated the `yarn start` commands to launch WK backend, fossildb and
vite dev server simultaneously

- ### Production Builds
- `vite build` does the JS compilation, bundling and asset copying to
`/public`.
- `Play` serves all assets from the `public` directory (incl.
`index.html`)
- `Play` inserts `Airbrake` credentials, `OpenGraph` metadata etc into
`index.html` as before


### URL of deployed dev instance (used for testing):
- https://vite.webknossos.xyz

### Steps to test:
- Run `yarn install` and `yarn start` to test dev mode
- Run a full vite build (`yarn build`). Enable `vite-build-analyzer`
(see commented out analyzer in`vite.config.js`) and inspect bundle
splits.
- Visit https://vite.webknossos.xyz to test production mode
- Verify web workers being initialized

### TODOs:
- [x] Fix type errors
- [x] Fix unit tests
- [x] Fix all the backend template stuff from index.html.scala that is
not available in `index.html`
- [ ] ~~Add DB migration of organization logo URI~~

### Issues:
- fixes #9186 

------
(Please delete unneeded items, merge only when none are left open)
- [x] Added changelog entry (create a `$PR_NUMBER.md` file in
`unreleased_changes` or use `./tools/create-changelog-entry.py`)
- [ ] Added migration guide entry if applicable (edit the same file as
for the changelog)
- [ ] Updated [documentation](../blob/master/docs) if applicable
- [ ] Adapted [wk-libs python
client](https://github.com/scalableminds/webknossos-libs/tree/master/webknossos/webknossos/client)
if relevant API parts change
- [ ] Removed dev-only changes like prints and application.conf edits
- [ ] Considered [common edge
cases](../blob/master/.github/common_edge_cases.md)
- [ ] Needs datastore update after deployment

---------

Co-authored-by: Florian M <florian@scm.io>
Co-authored-by: Philipp Otto <philippotto@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants