-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[feat] improve parent_component undefined error #6991
Conversation
Actually I just realized something, the error message would only apply to the user's project's own components only, and in most case they shouldn't hit this issue. The core issue is that other libraries precompile into JS, and the error arise in that precompiled code. So that makes this PR not very useful most of the time. though maybe useful for The real way to detect the error is by wrapping a try catch when initializing the precompiled JS component and re-transform the error, which is a bit hacky. |
Oh shit, yeah I guess you're right .. |
Looking at svelte-jester's source, looks like this PR would help it surface the better error message. But other than that, I don't see any other usecases. I could add the |
If it's possible to add this as a dev-only warning I'd say this would be a good addition. What did you have in mind to implement this? |
It'll most likely be some sort of wrapper function when instantiating a Svelte component in the compiled code. Something like: Update: Or maybe I can re extend the component class, and wrap the checks there. This sounds more robust. |
Tried implementing the try-catch solution today, but I can't find a solid heuristic to detect this edge case, especially when the code is minified. The only way I thought of is to have the |
Could you show what you had for the |
Basically whenever we generate code that instantiates the component, like: function create_fragment(ctx) {
let foo
foo = new Foo({})
} I was thinking we can have something like: function create_fragment(ctx) {
let foo
foo = validate_component(() => new Foo({}))
} Which wraps the function call in a try catch to detect the error. I also tried inline extending the The issue with try catch is that the error message varies between Chrome, Firefox, and Safari. Plus the error message won't always be |
In which cases this could be an error that is unrelated? Would it be feasible to always append additional text like "if the instantiated component is precompiled then .."? |
Any error could come up during the component initialization phase. Given this example, if we have
I'm not sure if it's fine to alter the error message. It might be confusing, but otherwise I don't see any other safe way. |
Fixes #6584
If
target
option is not defined, ensurecurrent_component
is defined too, which is used in componentinit()
phase.Before submitting the PR, please make sure you do the following
[feat]
,[fix]
,[chore]
, or[docs]
.Tests
npm test
and lint the project withnpm run lint