Skip to content

Add JSON parsing support for custom prop types (Unknown/Any) to provide consistent behavior between SSR and non-SSR environments.#6352

Merged
johnjenkins merged 2 commits intostenciljs:mainfrom
Jagget:patch-1
Jul 24, 2025
Merged

Conversation

@Jagget
Copy link
Copy Markdown
Contributor

@Jagget Jagget commented Jul 24, 2025

What is the current behavior?

  • Props typed as custom interfaces (e.g., Action) get classified as MEMBER_FLAGS.Unknown and receive no JSON parsing
  • JSON-like string attributes for custom types remain as strings, making the prop undefined when accessed as an object
  • Inconsistent behavior: string props sometimes get JSON parsing during hydration, but custom types never do
  • Example: <my-cmp data='{"param":"value"}'></my-cmp> with @Prop() data: Action results in this.data being undefined

What is the new behavior?

  • Custom interface props (MEMBER_FLAGS.Unknown) and any props (MEMBER_FLAGS.Any) now attempt JSON parsing when the string value looks like JSON (starts with {/[ and ends with }/])
  • Primitive types (string, number, boolean) maintain their existing behavior - no JSON parsing
  • Consistent behavior between SSR and non-SSR environments for custom types
  • Graceful fallback: if JSON parsing fails, the original string value is preserved
  • Example: <my-cmp data='{"param":"value"}'></my-cmp> with @Prop() data: Action now results in this.data being { param: "value" }

Does this introduce a breaking change?

  • Yes
  • No

Testing

Added

Jagget added 2 commits July 24, 2025 10:43
- String props: Always remain strings, even if they look like JSON
- Number props: Always get parsed as numbers
- Boolean props: Always get parsed as Booleans
- Custom interface props: Get JSON parsing attempted
- Any props: Get JSON parsing attempted
@Jagget Jagget requested a review from a team as a code owner July 24, 2025 14:57
Copy link
Copy Markdown
Contributor

@johnjenkins johnjenkins left a comment

Choose a reason for hiding this comment

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

LGTM!

@johnjenkins johnjenkins added this pull request to the merge queue Jul 24, 2025
Merged via the queue into stenciljs:main with commit a3fe474 Jul 24, 2025
69 checks passed
@Jagget Jagget deleted the patch-1 branch July 24, 2025 15:32
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