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

[Vue-3] Cannot read property 'contains' of null at Proxy.focusIn #86

Closed
1 task done
alinkedd opened this issue Jun 21, 2021 · 4 comments
Closed
1 task done

[Vue-3] Cannot read property 'contains' of null at Proxy.focusIn #86

alinkedd opened this issue Jun 21, 2021 · 4 comments

Comments

@alinkedd
Copy link

alinkedd commented Jun 21, 2021

I've got multiple Cannot read property 'contains' of null at Proxy.focusIn errors at this line regarding this.$refs.root.

  • Bug report

Tell about your platform

  • Vue.js version : 3.0.11
  • Browser name and version : Chrome 91.0.4472.106 (Dev), Firefox 89.0.1
  • This package version : 4.0.2

Current behavior
Cannot read property 'contains' of null at Proxy.focusIn errors in browser developer console.

Expected behavior
No errors regarding nullish elements in browser developer console.

Minimal reproduction of the problem with instructions
I have vue-cli project and was getting this error only after building it and serving it at some domain.

I might have got this problem because of possibly wrong component usage such as following:

  <div v-show="loading" class="loading-container">
    <div>
      <Loading
        active
        loader="dots"
        :is-full-page="false"
      />
    </div>
  </div>

I thought I did not need v-model, cause custom component appearance was controlled by loading prop and Loading component was always active. After adding additional ref variable drived by loading prop, error is gone:

  <div v-show="active" class="loading-container">
    <div>
      <Loading
        v-model:active="active"
        loader="dots"
        :is-full-page="false"
      />
    </div>
  </div>
  
  
  setup(props) {
    const { loading } = toRefs(props);

    const active = ref<boolean>(loading.value);

    watch(loading, (value) => {
      active.value = value;
    });

    return {
      active,
    };
  },

Aftewards, I just wanted to know if v-model is required (even if only UI is needed in some cases) and propose to add some check to this.$refs.root.

@ankurk91
Copy link
Owner

I am not sure if you are reporting a bug or asking the right way to use the component.

But if you can make a minimal re-pro on js-fiddle or codesandbox, and write steps to re-produce the issue, would be helpful.

Tip: Please use the component as described in docs.

@alinkedd
Copy link
Author

I am not sure if you are reporting a bug or asking the right way to use the component.

@ankurk91 kinda both, 'cause even if it's not supposed to happen due to inaccurate usage, imho it's better to check if element is not null.

Check example.

Steps to reproduce:

  1. Open container
  2. Click on green box
  3. Close and open container
  4. Click on green box again

@ankurk91
Copy link
Owner

-<div v-show="active" class="loading-container">
+<div class="loading-container">
    <div>
      <Loading
        v-model:active="active"
        loader="dots"
        :is-full-page="false"
      />
    </div>
  </div>

Actually you no need to add v-if to parent container.
If you are adding a v-if on parent, you are forcing vue to remove the element from DOM and re-create it.
This is overhead on browser.
The v-model on component will cause it to hide/show, this way component no need bind all events again.

Regarding, checking if this.$refs.root is null, i believe when the component is mounted the this.$refs.root must be always available. I need to investigate why it is null.

@ankurk91 ankurk91 changed the title Cannot read property 'contains' of null at Proxy.focusIn [Vue-3] Cannot read property 'contains' of null at Proxy.focusIn Dec 20, 2021
@ankurk91
Copy link
Owner

It has been one year and no one has reported similar issue

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

No branches or pull requests

2 participants