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

Remove errors that only occur in dev mode #3245

Closed
nolanlawson opened this issue Dec 21, 2022 · 6 comments · Fixed by #3413
Closed

Remove errors that only occur in dev mode #3245

nolanlawson opened this issue Dec 21, 2022 · 6 comments · Fixed by #3413
Labels

Comments

@nolanlawson
Copy link
Collaborator

#3244 revealed a lot of cases where our functionality differs between dev mode and prod mode. Sometimes this makes sense (e.g. calling console.warn only in dev mode), but in other cases it can introduce surprising behavior, when you test in dev mode and then get a different result in prod mode.

We should audit each of these cases and (probably) defer to doing the same thing in dev mode as prod mode. (In practice, prod mode is reality – many people never test in dev mode.)

Cases to check (in Karma test code):

  • if (process.env.NODE_ENV === ...)
  • expect(...).toThrowErrorDev()
  • expect(...).toThrowConnectedErrorDev()
@git2gus
Copy link

git2gus bot commented Dec 21, 2022

This issue has been linked to a new work item: W-12257612

@nolanlawson
Copy link
Collaborator Author

This is a really sneaky one that I haven't gotten around to fixing yet:

get(this: LightningElement): any {
if (process.env.NODE_ENV !== 'production') {
// Assert that the this value is an actual Component with an associated VM.
getAssociatedVM(this);
}
return get.call(this);
},

@nolanlawson
Copy link
Collaborator Author

Might have to save this one ^ for when we have API versioning. Turns out it throws an error in dev mode, but not prod mode, and only when the accessor is accessed internally: 893d693

Feels like it should just consistently throw in both prod and dev mode when the this is wrong.

@nolanlawson
Copy link
Collaborator Author

A big problem is this function. It throws an error in dev mode, but not in prod mode:

export function getAssociatedVM(obj: VMAssociable): VM {
const vm = ViewModelReflection.get(obj);
if (process.env.NODE_ENV !== 'production') {
assertIsVM(vm);
}
return vm!;
}

This function is called in many places.

nolanlawson added a commit that referenced this issue Apr 13, 2023
@nolanlawson nolanlawson changed the title Audit functional differences between dev mode and prod mode Remove errors that only occur in dev mode Apr 14, 2023
@nolanlawson
Copy link
Collaborator Author

Synthetic shadow has a few of these, like this one:

if (process.env.NODE_ENV !== 'production') {
assert.invariant(
owner instanceof HTMLElement,
`isNodeOwnedBy() should be called with an element as the first argument instead of ${owner}`
);
assert.invariant(
node instanceof Node,
`isNodeOwnedBy() should be called with a node as the second argument instead of ${node}`
);
assert.invariant(
compareDocumentPosition.call(node, owner) & DOCUMENT_POSITION_CONTAINS,
`isNodeOwnedBy() should never be called with a node that is not a child node of ${owner}`
);
}

@nolanlawson
Copy link
Collaborator Author

This is largely fixed, I'm going to call this one done for now. If something else comes up, we can open another issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant