Skip to content

Conversation

@packagethief
Copy link
Contributor

When Rollup's output format changed to "esm" in #1016, it stopped automatically renaming variables that shadow globals. This caused the bundled turbo.js to overwrite window.navigator with Turbo's internal Navigator instance, breaking libraries that depend on the browser's window.navigator.

Fix by renaming navigator to sessionNavigator during destructuring, then re-exporting it under the original name.

Fixes hotwired/turbo-rails#776

…dow.navigator

When Rollup's output format changed to "esm"[1], it stopped automatically
renaming variables that shadow globals. This caused the bundled turbo.js
to overwrite `window.navigator` with Turbo's internal `Navigator` instance,
breaking libraries that depend on the browser's `navigator`.

Fix by explicitly renaming `navigator` to `sessionNavigator` during
destructuring, then re-exporting it under the original name.

Fixes hotwired/turbo-rails#776

[1]: cbf3d86
Comment on lines +15 to +17
// Rename `navigator` to avoid shadowing `window.navigator`
const { cache, navigator: sessionNavigator } = session
export { session, cache, sessionNavigator as navigator }
Copy link
Contributor

Choose a reason for hiding this comment

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

Depending on how we've been supporting this particular property, this could be considered a breaking change. For example, there is existing test coverage that ensures that Turbo.navigator is available when imported with a *.

assert.equal(typeof Turbo.navigator, "object")

I think a more backwards-compatible resolution could involve rolling back the Rollup config to its previous value, followed up by a more deliberate deprecation and rename of this export.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, I see that the final export is still consistently navigator, so that's good. Maybe this could work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly. It was just the destructured navigator constant that was clobbering the global window object of the same name. We still export as Turbo.navigator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

v2.0.21 clobbers global window.navigator object

3 participants