Skip to content

Backport code from @vitejs/plugin-legacy to vite_plugin_legacy#296

Open
Antti wants to merge 5 commits into
ElMassimo:mainfrom
fetlife:add-id-to-legacy-import
Open

Backport code from @vitejs/plugin-legacy to vite_plugin_legacy#296
Antti wants to merge 5 commits into
ElMassimo:mainfrom
fetlife:add-id-to-legacy-import

Conversation

@Antti

@Antti Antti commented Nov 3, 2022

Copy link
Copy Markdown

Description 📖

Backport most of the logic from @vitejs/plugin-legacy to vite_plugin_legacy

This is currently used in production for over a year to support a wide variety of legacy browsers.

Background 📜

@vitejs/plugin-legacy does a lot of magic to support legacy browsers by rewriting index.html,
we're mostly interested in:

  • Safari 10 nomodule fix
  • A workaround for browsers that support modules, but do not support dynamic import:
    • script has type module, so only browsers which support modules would load it
    • if the dynamic import works - nothing happens
    • if the dynamic import fails - loads polyfills legacy
    • when polyfills legacy is loaded - it will then execute the entrypoint

@alexookah

Copy link
Copy Markdown

@ElMassimo Can we review and merge this?

@ElMassimo ElMassimo force-pushed the main branch 2 times, most recently from d55cc92 to ebe50b8 Compare July 17, 2024 14:43
@ElMassimo ElMassimo force-pushed the main branch 2 times, most recently from d66f582 to c7bbad9 Compare January 3, 2025 20:18
@azz

azz commented Jul 4, 2026

Copy link
Copy Markdown

Hey @ElMassimo — I just encountered this issue, and unfortunately it prevents our team from adopting Vite Ruby.

The issue is that for browsers which support ES modules, but not the "baseline widely available" features that Vite depends on, @vite/pluin-legacy will load the "legacy" bundle, and prevent the modern bundle from being loaded.

With vite_plugin_legacy, on older browsers (I tested with Chrome 95), the guard inserted in the chunk will prevent the modern bundle from loading:

https://github.com/vitejs/vite/blob/af21ab68adac3380dc9a854d2fe3f776654301cd/packages/plugin-legacy/src/snippets.ts#L29

... however the fallback behaviour of importing the legacy bundle via SystemJS is not present, resulting in a blank screen on these browsers.

Is there any chance you'd be able to take a look at what would be required to get this working in vite_ruby?

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.

3 participants