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

SSR watchEffect onInvalidate issue (Cannot access 'runner' before initialization) #3322

Closed
tjk opened this issue Feb 27, 2021 · 3 comments · Fixed by #3323
Closed

SSR watchEffect onInvalidate issue (Cannot access 'runner' before initialization) #3322

tjk opened this issue Feb 27, 2021 · 3 comments · Fixed by #3323
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. 🐞 bug Something isn't working scope: ssr

Comments

@tjk
Copy link
Contributor

tjk commented Feb 27, 2021

See README in https://github.com/tjk/watcheffect-runner-bug

Version

3.0.6

Reproduction link

https://github.com/tjk/watcheffect-runner-bug

Steps to reproduce

git clone https://github.com/tjk/watcheffect-runner-bug
cd watcheffect-runner-bug
yarn
yarn dev

Then hit http://localhost:3000

What is expected?

No error

What is actually happening?

Error

@LinusBorg LinusBorg added 🐞 bug Something isn't working ❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. scope: ssr labels Feb 27, 2021
@LinusBorg
Copy link
Member

LinusBorg commented Feb 27, 2021

During SSR, we return from doWatch before runner is initalized, but onInvalidate still references it, which throws this error.

Think we need to initialize it eagerly with let runner and also check for it to be set during onInvalidate execution before accessing runner.options.

But i have no idea how to write a test for this ...

@tjk
Copy link
Contributor Author

tjk commented Feb 27, 2021

I have no idea what I'm doing but I think this test is working --

// XXX find a way to not double setup and just generally not do this so hackily
it('effect onInvalidate succeeds in ssr context', (done) => {
  let instance: ComponentInternalInstance | null
  const noop = () => {}
  const Comp = defineComponent({
    setup() {
      if (!instance) {
        instance = getCurrentInstance()
      } else {
        watchEffect((onInvalidate) => {
          expect(() => onInvalidate(noop)).toThrow(ReferenceError)
          done()
        })
      }
    },
    render: noop,
  })
  createApp(Comp).mount(nodeOps.createElement('div'))
  setupComponent(instance!, true /* isSSR */)
})

@tjk
Copy link
Contributor Author

tjk commented Feb 27, 2021

Started a PR #3323 for someone who understands better to fix up. Thanks for the guidance @LinusBorg.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. 🐞 bug Something isn't working scope: ssr
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants