Skip to content

fix: use stable bundle name in dev mode to avoid CDN mismatch#221

Open
happy-edge wants to merge 4 commits into
jup-ag:mainfrom
happy-edge:fix/dev-bundle-loading
Open

fix: use stable bundle name in dev mode to avoid CDN mismatch#221
happy-edge wants to merge 4 commits into
jup-ag:mainfrom
happy-edge:fix/dev-bundle-loading

Conversation

@happy-edge

Copy link
Copy Markdown

Problem

When bumping package.json version during development, the homepage breaks because:

  1. bundleName becomes plugin-{new-version}
  2. Loader tries to fetch plugin-{new-version}-app.js from CDN
  3. File doesn't exist on CDN yet → 💥

This forced developers to either:

  • Not bump versions until ready to publish
  • Or deal with a broken homepage during development

Solution

When NEXT_PUBLIC_IS_PLUGIN_DEV=true:

  • Webpack outputs to plugin-dev.js (stable name)
  • Runtime loader uses plugin-dev.js
  • Version bumps no longer break local development

Usage

# In .env (already enabled by default after this PR)
NEXT_PUBLIC_IS_PLUGIN_DEV=true

# Build for local testing
pnpm build-widget
# → outputs plugin-dev.js, plugin-dev-app.js, etc.

# Build for production (when ready to publish)
NEXT_PUBLIC_IS_PLUGIN_DEV= pnpm build-widget  
# → outputs plugin-1.0.14.js, etc.

Changes

  • webpack.config.js: Use plugin-dev bundle name when dev flag is set
  • library.tsx: Same logic for runtime bundle resolution
  • .env: Enable dev mode by default
  • DEVELOPER_NOTES.md: Document the workflow

Backwards Compatible

Production builds (without the env var) work exactly as before.

Problem:
When bumping package.json version, the homepage would try to load
plugin-{new-version}-app.js from CDN, but it doesn't exist yet.
This broke local development when making version changes.

Solution:
When NEXT_PUBLIC_IS_PLUGIN_DEV=true:
- Webpack outputs to plugin-dev.js (stable name)
- library.tsx loads plugin-dev.js instead of versioned file
- Local builds work regardless of package.json version

Changes:
- webpack.config.js: Use 'plugin-dev' bundle name in dev mode
- library.tsx: Same logic for runtime bundle loading
- .env: Enable dev mode by default for local development
- DEVELOPER_NOTES.md: Document the dev build workflow
@vercel

vercel Bot commented Feb 6, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the wowcats Team on Vercel.

A member of the Team first needs to authorize it.

Edgy added 3 commits February 7, 2026 02:00
- Check VERCEL_ENV=preview in webpack and NEXT_PUBLIC_VERCEL_ENV in library.tsx
- Add vercel.json to run build-widget:dev before Next.js build
- Vercel previews now automatically load new code without manual env var setup
Instead of changing bundle names, we switch where we load from:
- Dev/Preview: load from local /public (relative path)
- Production: load from CDN

This way:
- Bundles are always versioned (plugin-1.0.14.js)
- Local dev loads /public/plugin-1.0.14.js
- Vercel preview loads /public/plugin-1.0.14.js
- Production loads https://plugin.jup.ag/plugin-1.0.14.js

@thejesh23 thejesh23 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The title and PR description say webpack will output plugin-dev.js as a stable bundle name, but the diff doesn't actually change webpack.config.jsbundleName is still plugin-${packageJson.version}. The real fix here is in library.tsx: switching scriptDomain to '' (relative path) when NEXT_PUBLIC_IS_PLUGIN_DEV === 'true' or on Vercel preview, so the loader picks up whatever versioned bundle is in /public/.

That's a cleaner solution than the description suggests — worth updating the title/description so reviewers and future git-blame readers aren't hunting for a plugin-dev.js rename that doesn't exist.

Minor: === 'true' is stricter than the previous truthy check (!process.env.X); harmless here, but anyone setting the var to 1 or yes will silently get production behavior.

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.

2 participants