Skip to content

Fix TS2322: implement client-side QuickPlot PDF generation#1645

Closed
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-ci-failure-ts2322
Closed

Fix TS2322: implement client-side QuickPlot PDF generation#1645
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-ci-failure-ts2322

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

PR #1644 introduced a Button mock in the test file with type?: string, causing TS2322 because the native <button> element's type attribute only accepts "button" | "reset" | "submit" | undefined.

Changes

Bug fix

  • test/containers/neo-and-quick-plot.spec.tsx: Narrowed Button mock's type prop from string to "button" | "reset" | "submit" — aligns with ButtonProps in element-context.tsx and satisfies the native element constraint
- Button: ({ children, onClick, type, disabled }: { ...; type?: string; ... }) =>
+ Button: ({ children, onClick, type, disabled }: { ...; type?: "button" | "reset" | "submit"; ... }) =>

Client-side QuickPlot (PR #1644 feature)

  • src/containers/quick-plot.tsx: Accepts new clientSide?: string prop; when "true", relaxes the RuntimeMap guard, renders the Generate button as type="button", and on click calls viewer.exportImage() → dynamically imports jspdf → builds and downloads quickplot.pdf
  • src/api/mapguide-commands.ts: Propagates ClientSide: "true" extension property as component://QuickPlot?clientSide=true
  • src/strings/: Added QUICKPLOT_GENERATING i18n key for the in-progress button label
  • package.json: Added jspdf ^4.2.1 dependency
  • test/containers/neo-and-quick-plot.spec.tsx: Added jspdf vi.mock and two new tests covering client-side render-without-map and the full exportImage → addImage → save flow

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • storybook.js.org
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node /home/REDACTED/work/mapguide-react-layout/mapguide-react-layout/node_modules/storybook/bin/index.cjs build -c .storybook (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Fix CI failure TS2322 in PR #1644 feature branch: Type 'string | undefined' not assignable to React button type union ("button" | "reset" | "submit" | undefined). Implement Option A: ensure the relevant component prop (or value passed to ) is correctly typed as React.ButtonHTMLAttributes["type"] (or equivalent) instead of string, so TypeScript build succeeds.

Context:

  • Failing GitHub Actions job: 74627317446
  • Error from logs at ref 8971eab:
    TS2322: Type 'string | undefined' is not assignable to type '"button" | "reset" | "submit" | undefined'.
  • Workflow file: .github/workflows/main.yml uses Node 22, yarn install, runs yarn run ci:gha. Install triggers postinstall which runs yarn build; build fails due to TS error.

Tasks:

  1. Locate the exact TypeScript/TSX source file producing TS2322 (likely a
or component forwarding a type prop).
  • Apply Option A fix by changing the prop/type definition to the correct narrow union type: React.ButtonHTMLAttributes["type"] (or HTMLButtonElement attributes type).
  • Ensure no runtime behavior changes (just typing) and CI build passes.
  • Commit changes to the PR's current feature branch (do not create a new branch).
  • Constraints:

    • Keep change minimal and focused.
    • Update any related types/interfaces where the offending prop/value is defined.
    • If the type is part of a shared props type, update that too.

    The following is the prior conversation context from the user's chat exploration (may be truncated):

    User: Please find a solution for failing job 74627317446. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

    Assistant: The failing job 74627317446 is failing during the Yarn “build” step (triggered by postinstall) because TypeScript compilation fails with:

    TS2322: Type 'string | undefined' is not assignable to type "button" | "reset" | "submit" | undefined.

    This is almost certainly a React <button type={...}> (or a component prop that forwards to it) where the type prop is currently typed/handled as a generic string (or string | undefined) instead of the narrow union that React expects.

    Fix: Narrow the type value before passing it to <button>

    Find the component that renders a <button> and is passing a type value that’s coming from props/config as string | undefined. Change it to one of these safe patterns:

    Option A (recommended): Type the prop correctly

    If you have a component prop like:

    type: string | undefined

    Change it to:

    type?: React.ButtonHTMLAttributes<HTMLButtonElement>["type"];
    // which is: "button" | "submit" | "reset" | undefined

    And keep usage as:

    <button type={props.type}>...</button>

    Option B: Provide a default and narrow with as const

    If the value is optional and you want a default:

    const btnType: React.ButtonHTMLAttributes<HTMLButtonElement>["type"] =
      props.type ?? "button";
    
    return <button type={btnType}>...</button>;

    Option C: If the value originates as string, validate it

    If it comes from JSON/config/user input as a plain string:

    function normalizeButtonType(t?: string): React.ButtonHTMLAttributes<HTMLButtonElement>["type"] {
      return t === "submit" || t === "reset" || t === "button" ? t : "button";
    }
    
    return <button type={normalizeButtonType(config.type)}>...</button>;

    Why CI hits this now

    Your CI workflow runs Node 22 and yarn install, and your package.json has:

    • postinstall: patch-package && yarn run build (so install triggers a full build)
    • TypeScript 5.9.3

    So any newly-introduced typing mismatch in JSX/React props will fail the job immediately.

    Where to look in the repo

    Search for any of these patterns and apply the fix above:

    • <button type={...}>
    • A component prop named type that forwards to <button>
    • Any usage like type={someString}

    Once the type value is narrowed to "button" | "submit" | "reset" | undefined, the TS2322 error should disappear and the job should pass on the same workflow run (.github/workflows/main.yml at ref 8971eab5d5d81694833ffc2aebbd037b0634ed78).

    User: Commit the Option A fix to this current feature branch

    Assistant: I’ve kicked off the automated commit process to apply the Option A typing fix on PR #1644’s current feature branch, and I’m waiting for the system to return the result of that run so I can confirm the exact file changed and the commit SHA.

    This pull request was created from Copilot chat.

    @github-actions
    Copy link
    Copy Markdown
    Contributor

    github-actions Bot commented May 6, 2026

    Bundle Size Report ✅ PASS

    Metric Size Gzip Brotli
    Total 12.36 MB 2.81 MB 2.04 MB
    Diff +2.16 MB 🔴 ↑ +535.72 KB 🔴 ↑ +416.77 KB 🔴 ↑
    Change +21.19% +22.91% +24.99%

    Top Changes

    File Before After Diff
    ~ vendor-debug.js 940.95 KB 1.16 MB +251.87 KB 🔴 ↑
    ~ vendor.js 385.47 KB 548.74 KB +163.28 KB 🔴 ↑
    ~ viewer-debug.js 200.83 KB 201.80 KB +995.00 B 🔴 ↑
    ~ viewer.js 122.73 KB 123.39 KB +678.00 B 🔴 ↑

    Generated by build-size-diff Commit: 2619a22

    @coveralls
    Copy link
    Copy Markdown

    coveralls commented May 6, 2026

    Coverage Status

    coverage: 59.713% (+0.04%) from 59.676% — copilot/fix-ci-failure-ts2322 into master

    Copilot AI changed the title [WIP] Fix CI failure TS2322 in button type definition Fix TS2322: implement client-side QuickPlot PDF generation May 6, 2026
    Copilot AI requested a review from jumpinjackie May 6, 2026 16:35
    @jumpinjackie
    Copy link
    Copy Markdown
    Owner

    @copilot Change your merge target from master to copilot/make-quickplot-client-side

    Copy link
    Copy Markdown
    Contributor Author

    Copilot AI commented May 6, 2026

    @copilot Change your merge target from master to copilot/make-quickplot-client-side

    The GitHub API to update the PR base branch is blocked by the sandbox firewall, so I'm unable to change it programmatically. Please update the base branch of PR #1645 to copilot/make-quickplot-client-side manually via the GitHub UI.

    Once you do that, the PR diff will show exactly the single-line fix: changing type?: string to type?: "button" | "reset" | "submit" in the Button mock — because that's the only difference between this branch and copilot/make-quickplot-client-side.

    Warning

    Firewall rules blocked me from connecting to one or more addresses (expand for details)

    I tried to connect to the following addresses, but was blocked by firewall rules:

    • https://api.github.com/graphql
      • Triggering command: /usr/bin/gh gh pr view 1645 --json number,title,baseRefName,headRefName (http block)
      • Triggering command: /usr/bin/gh gh pr edit 1645 --base copilot/make-quickplot-client-side (http block)
    • https://api.github.com/repos/jumpinjackie/mapguide-react-layout/pulls/1645
      • Triggering command: /usr/bin/curl curl -s -X PATCH -H Authorization: token ****** -H Accept: application/vnd.github.v3&#43;json REDACTED -d {&#34;base&#34;: &#34;copilot/make-quickplot-client-side&#34;} (http block)
      • Triggering command: /usr/bin/curl curl -s -w \nHTTP_CODE:%{http_code} -X PATCH -H Authorization: ****** -H Accept: application/vnd.github&#43;json -H X-GitHub-Api-Version: 2022-11-28 REDACTED -d {&#34;base&#34;:&#34;copilot/make-quickplot-client-side&#34;} (http block)

    If you need me to access, download, or install something from one of these locations, you can either:

    @jumpinjackie
    Copy link
    Copy Markdown
    Owner

    @copilot Is code-splitting actually happening? The vendor bundle shot up by 2+ MB when I would've expected a new separate jspdf-only vendor bundle.

    @jumpinjackie
    Copy link
    Copy Markdown
    Owner

    What a waste of time and premium credits!

    Copilot stopped work on behalf of jumpinjackie due to an error May 6, 2026 17:05
    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