Skip to content

Harden PreviewIframe Prop Typing to Eliminate Untyped Customization Payloads #1007

Description

@temma02

Description

src/components/app/preview/PreviewIframe.tsx declares customization?: any in PreviewIframeProps (line 8), even though every caller — PreviewWorkspace.tsx passes a CustomizationConfig — already has a properly typed value available. Using any here means JSON.stringify(customization) inside the generatePreviewUrl effect (line 32) and any future consumer of the prop get zero compile-time safety; a caller could pass an unrelated object shape and TypeScript would not catch it, and IDE autocomplete/refactor tooling can't help maintainers working in this file.

Requirements and Context

  • PreviewIframeProps.customization must be typed as CustomizationConfig | undefined instead of any, matching the type already used by PreviewWorkspaceProps.customization in the same directory.
  • No behavior change is expected; this is a type-safety improvement only.
  • pnpm typecheck must pass with the tightened type, confirming all current call sites already satisfy it.
  • Add a type-level or unit test (e.g. a PreviewIframe.test.tsx render passing a full CustomizationConfig) if no test file currently exists for this component.

Suggested Execution

Branch: refactor/preview-iframe-prop-typing

Implement Changes

  • In src/components/app/preview/PreviewIframe.tsx, import CustomizationConfig from @craft/types and change customization?: any to customization?: CustomizationConfig.
  • Re-check the generatePreviewUrl effect's dependency array and JSON.stringify(customization) call for any implicit any-driven behavior that needs adjusting once the type is narrowed.
  • If src/components/app/preview/PreviewIframe.tsx has no dedicated test file, add a minimal one rendering the component with a typed CustomizationConfig and asserting the generated src URL includes the serialized customization.
  • Run pnpm typecheck to surface and fix any now-visible type errors at call sites.

Test and Commit

Run pnpm typecheck --filter=frontend and pnpm test --filter=frontend -- PreviewIframe to confirm the tightened prop type compiles cleanly and existing preview rendering still works.

Example Commit Message

refactor(frontend): replace any with CustomizationConfig in PreviewIframeProps

Co-authored-by: <your-name>

Guidelines

  • Branch off main, keep PRs focused on one issue
  • All new code must include unit or integration tests
  • Ensure pnpm lint and pnpm typecheck pass before review
  • Link this issue in your PR description
  • Request review from at least one maintainer before merging

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programenhancementNew feature or requestfrontendFrontend related issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions