Skip to content

fix(cjs): fix HMR issue with mongoose - #7938

Merged
pi0 merged 2 commits into
devfrom
mongoose-hmr
Aug 26, 2020
Merged

pi0 merged 2 commits into
devfrom
mongoose-hmr

Conversation

@farnabaz

@farnabaz farnabaz commented Aug 17, 2020 •

Copy link
Copy Markdown
Member

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Introduce isHMRCompatible function to detect clear incompatible modules cache.
As we know mongoose is incompatible and clearing mongoose/index.js and mongoose/lib/index.js makes it work.

close #7917

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: #)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.

@codecov-commenter

codecov-commenter commented Aug 17, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #7938 into dev will decrease coverage by 0.01%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev    #7938      +/-   ##
==========================================
- Coverage   68.92%   68.91%   -0.02%     
==========================================
  Files          91       91              
  Lines        3846     3847       +1     
  Branches     1041     1042       +1     
==========================================
  Hits         2651     2651              
  Misses        971      971              
- Partials      224      225       +1     
Flag Coverage Δ
#unittests 68.91% <33.33%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/utils/src/cjs.js 65.71% <33.33%> (-3.99%) ⬇️
packages/cli/src/utils/generate.js 0.00% <0.00%> (ø)
packages/webpack/src/plugins/vue/modern.js 3.70% <0.00%> (+0.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e9d759...cfb5ca3. Read the comment docs.

Comment thread packages/utils/src/cjs.js Outdated
import { join } from 'path'

export function isHMRCompatible (id) {
return !/[/\\]mongoose[/\\/](lib[/\\/])?index.js/.test(id)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not marking entire mongoose dep as incompatible? A regex matching node_modules/mongoose as a part of id

@farnabaz farnabaz Aug 17, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

mongoose has lots of files and it does not bundle them. clearing entire mongose deps causes Maximum call stack size exceeded. (Honestly, I don't understand why)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you have a repo to quickly check? Maybe it is a nuxt HMR bug

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll have one, let me push it to github

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we create a nuxt module for mongoouse and clear cache via watchers or modules:before hook ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@farnabaz Typescript recursion should be fixed by (#7966)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@clarkdo Seems nice idea. Also there is an alternative way i used once to use unload method.

Since it is really minor case (serverMiddleware + HMR + mongoose) but not uncommon setup, it may worth excluding mongoose by default. Nuxt 3 will isolate functions anyway so we won't have such issues for HMR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@pi0 I have updated the regex based on based on fix #7966

@pi0 pi0 changed the title fix(cjs): add regex to clear mongoose main file cache fix(cjs): fix HMR issue with mongoose Aug 26, 2020
@pi0
pi0 merged commit 9f05feb into dev Aug 26, 2020
@pi0
pi0 deleted the mongoose-hmr branch August 26, 2020 09:38
@pi0 pi0 mentioned this pull request Aug 26, 2020
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

5 participants