Skip to content

Conversation

fry69
Copy link
Contributor

@fry69 fry69 commented Oct 5, 2025

fix #3521

Generated PR message below


Problem

Island files named after JavaScript global objects (e.g., Map.tsx, Set.tsx, Promise.tsx) cause runtime errors. When UniqueNamer generates identifiers from these filenames, the resulting variable names shadow global constructors, breaking instantiation:

import Map from "/islands/Map.tsx";
boot({Map}, props);  // Map resolves to global constructor, not the island

This results in TypeError: Map is not a constructor when the framework attempts to use new Map() internally.

Solution

Added JavaScript global objects to the JS_RESERVED set in UniqueNamer. Names matching reserved keywords or globals are now automatically prefixed with underscore:

import _Map_1 from "/islands/Map.tsx";
boot({_Map_1}, props);  // No shadowing

Changes

  • utils.ts: Extended JS_RESERVED with:

    • JavaScript built-ins (Map, Set, Array, Promise, Object, etc.)
    • Web APIs (fetch, console, URL, WebSocket, etc.)
    • Deno-specific globals (Deno namespace)
    • Node.js compatibility globals (process, Buffer, global)
  • Integration tests: Added test cases for both Builder and Vite build systems verifying islands named after globals work correctly

Impact

Single-location fix in UniqueNamer applies to all code generation (islands, routes, etc.). Island names are prefixed when needed, preserving debuggability while preventing shadowing bugs.

@fry69 fry69 changed the title fix: Prevent island names from shadowing JavaScript globals fix: prevent island names from shadowing JavaScript globals Oct 5, 2025
Copy link
Collaborator

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@marvinhagemeister marvinhagemeister merged commit 84576bd into denoland:main Oct 5, 2025
7 checks passed
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.

Island files named after global objects cause runtime failures

2 participants