Skip to content

fix: correct prose macro packaging - #10976

Open
BDesta wants to merge 1 commit into
adobe:mainfrom
BDesta:fix/prose-macro-packaging
Open

BDesta wants to merge 1 commit into
adobe:mainfrom
BDesta:fix/prose-macro-packaging

Conversation

@BDesta

@BDesta BDesta commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #10975

Summary

Intent

Make the published prose() macro usable without changing its public API or requiring consumers to maintain their own typography styles. Currently, evaluating it fails with ReferenceError: fontSize is not defined because values imported with with {type: 'macro'} are referenced as ordinary data by the local font() helper.

Implementation and why the separate font file matters

  • Move the existing font() helper and its color lookup into prose-font.ts. This module imports the font tables and related values normally; prose.ts imports the helper function as a macro.

  • The separate file is a compilation boundary, not just code organization. Parcel evaluates the literal font('body'), font('heading-xl'), etc. calls while packaging prose.ts, and inlines their resolved declaration objects. The helper can read the original Spectrum font tables without retaining those tables and their dependencies in the published macro. It also avoids duplicating token values or inventing a separate typography scale.

  • Simply changing the existing theme imports to regular imports avoids the missing binding, but pulls substantially more theme code into the emitted macro. In a local comparison using the same Node ESM library entry, production mode, and shouldOptimize: false:

    Approach Emitted JavaScript
    Regular theme imports, helper kept in prose.ts 211,734 bytes
    Separate helper imported as a macro (this PR) 37,610 bytes

    That is 174,124 fewer bytes (about 82% smaller) than the imports-only alternative. These are unoptimized build-time macro module sizes, not compressed browser-bundle measurements. The broken upstream module is smaller still, but cannot be evaluated.

  • Recursively serialize nested conditional declarations. Resolving the actual font-weight tables exposes nested CJK language conditions; stringifying these objects directly produces [object Object] instead of CSS. Preserve the nested selectors and their default weights.

  • Add source-level coverage for the nested font weights and packaging coverage that builds both CommonJS and ESM output, evaluates the packaged macro in Node, and checks its emitted CSS. The packaging test runs Parcel outside Jest's module environment to avoid sharing cached loaders with other suites.

This PR was prepared with AI assistance; the implementation and validation remain the author's responsibility.

📝 Test Instructions

  • The pre-fix failure was reproduced against upstream main (360e35170) in a separate Parcel ESM packaging probe: evaluating the output throws ReferenceError: fontSize is not defined. The same probe succeeds on this branch and emits CSS without undefined or [object Object].
  • yarn test --maxWorkers=2: 383 suites / 8,285 tests passed; 2 tests failed; 16 skipped. Failures are in unchanged date/era tests: DatePicker > editing > text input > should support typing into the era segment and DateField > does not crash when a calendar has an era with no localized name (expected AM, received ERA1). These failures have not been independently reproduced on a clean baseline.
  • yarn test:ssr: 60 suites / 74 tests passed.
  • yarn test:parcel --runInBand: 2 suites / 15 tests passed, including both packaged prose formats and the existing docs-transformer suite.
  • yarn lint: failed. Package lint, package metadata checks, and Yarn constraints passed. The formatting check reports two untouched local configuration files (.claude/settings.local.json, .github/hooks/hooks.json); type checking reports duplicate JSX imports on lines 1 and 2 of the installed node_modules/@mdx-js/react/lib/index.d.ts. No unrelated configuration or dependency files were changed to suppress these failures.
  • yarn format:check and yarn exec oxlint on all four changed files: passed. git diff --cached --check: passed.
  • Local environment: Node.js 24.11.1 selected by .nvmrc (24), Yarn 4.18.0, macOS. Dependencies were refreshed with yarn install --immutable after fast-forwarding to upstream main.
  • Manual reproduction: open https://stackblitz.com/edit/frhxnxlb?file=main.js and run npm run build to observe the published 0.5.2 failure. The StackBlitz still uses the published package, not this unpublished fix.
  • No browser/visual verification or Chromatic runs. This is a build-time macro fix; no component interaction or API changes are intended. Full package release builds and downstream Vite verification against a newly packed package have not been run.

Release impact

  • Only changes docs, tests, CI, or development tools. Nothing shipped to users changes.
  • Fixes a bug or improves existing code without changing how apps use it.
  • Adds a feature or API while keeping existing usage working.
  • May break existing usage or require changes in apps that use this code.

✅ PR Checklist

  • I followed the contributing guide. Validation limitations and the local Node version are disclosed above.
  • I tested this change locally and included the results in Test Instructions, or explained why testing does not apply.
  • I understand and can explain every change in this PR. If I used AI assistance, I followed the AI contribution guidance.

🧢 Your Project

Downstream Markdown rendering using shared Spectrum prose styles.

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.

@react-spectrum/ai prose() fails with fontSize is not defined

1 participant