Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(engine-core): fix warnings for invalid keys #4097

Merged
merged 10 commits into from Mar 26, 2024

Conversation

nolanlawson
Copy link
Contributor

Details

Now that static blocks support keys (#4091), this dev-only error message became incorrect. If the invalid key is on a static fragment, then we weren't properly checking for that – we assumed it would only be on an element or custom element.

This fixes that, as well as adding more robust tests to capture more ways that this can log.

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.

@nolanlawson nolanlawson requested a review from a team as a code owner March 22, 2024 23:12
@@ -431,16 +432,25 @@ function i(

if (process.env.NODE_ENV !== 'production') {
const vnodes = isArray(vnode) ? vnode : [vnode];
forEach.call(vnodes, (childVnode: VNode | null) => {
if (!isNull(childVnode) && isObject(childVnode) && !isUndefined(childVnode.sel)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

childVnode.sel is just a sniff test for VElement or VCustomElement since those are the only types that can have a sel. I prefer to be explicit and just check for the childVnode.type instead.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we need the check on isObject since vnodes should always contain a vnode.

It doesn't break any karma tests when it's removed but I'm not sure if there's any edge cases I'm not thinking of.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're right. It's not necessary.

// TODO [#1283]: Improve this error message. The vm should not be exposed and the message is not helpful.
expect(() => document.body.appendChild(elm)).toLogErrorDev(
/Duplicated "key" attribute value for "<(li|x-custom)>" in \[object:vm \S+ \(\d+\)\] for item number 1\. A key with value "\d:xyz" appears more than once in the iteration\. Key values must be unique numbers or strings\./
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We previously didn't have any tests for this "Duplicated key" error message.

Ctor: XTestCustomElement,
tagName: 'x-test-custom-element',
},
];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing the three scenarios we care about: Elements, CustomElements, and VStatics.

@@ -64,7 +66,7 @@ it('should throw an error when the passing a non iterable', () => {

// TODO [#1283]: Improve this error message. The vm should not be exposed and the message is not helpful.
expect(() => document.body.appendChild(elm)).toThrowCallbackReactionError(
/Invalid template iteration for value `\[object (ProxyObject|Object)\]` in \[object:vm Test \(\d+\)\]. It must be an array-like object and not `null` nor `undefined`.|is not a function/
/Invalid template iteration for value `\[object (ProxyObject|Object)]` in \[object:vm Test \(\d+\)]\. It must be an array-like object and not `null` nor `undefined`\.|is not a function/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unnecessary escapes in regexes, and some missing escapes (like for the .).

Copy link
Member

@jmsjtu jmsjtu left a comment

Choose a reason for hiding this comment

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

Left a comment but otherwise LGTM, thank you!

@@ -431,16 +432,25 @@ function i(

if (process.env.NODE_ENV !== 'production') {
const vnodes = isArray(vnode) ? vnode : [vnode];
forEach.call(vnodes, (childVnode: VNode | null) => {
if (!isNull(childVnode) && isObject(childVnode) && !isUndefined(childVnode.sel)) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we need the check on isObject since vnodes should always contain a vnode.

It doesn't break any karma tests when it's removed but I'm not sure if there's any edge cases I'm not thinking of.

@nolanlawson nolanlawson merged commit 3665f31 into master Mar 26, 2024
9 checks passed
@nolanlawson nolanlawson deleted the nolan/test-static-keys branch March 26, 2024 16:53
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.

None yet

2 participants