Skip to content

cleanup: unify collectPublicProps duplicate implementations #621

Description

@SisyphusZheng

Problem

collectPublicProps is implemented twice with subtly different semantics:

Location Access method
packages/element/src/define-element.ts:11 host[key] (direct property access)
packages/app/src/authoring.ts:226 Reflect.get(host, key) (safer, respects getters)

Both filter __openElement-prefixed keys. The Reflect.get version is strictly more correct (handles inherited getters without throwing), but the divergence is a maintenance trap.

Fix

Unify to a single implementation exported from @openelement/element internal utils:

// packages/element/src/internal/core/props-utils.ts
export function collectPublicProps(host: object): Record<string, unknown> {
  const props: Record<string, unknown> = {};
  for (const key of Object.keys(host)) {
    if (key.startsWith('__openElement')) continue;
    props[key] = Reflect.get(host, key);
  }
  return props;
}

Both define-element.ts and app/authoring.ts import from this single source.

Acceptance

  • Single implementation exists
  • Both call sites import from the shared module
  • Existing tests pass unchanged

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions