Skip to content

NODE_ENV affects root context message availability for linked messages in SFCs #1444

@maschill92

Description

@maschill92

Reporting a bug?

Messages defined in an SFC that link to messages defined in the root context are displayed when NODE_ENV is "development" but are not displayed when NODE_ENV is "production".

I believe the difference in behavior is caused by the setting of fallbackContext when NODE_ENV is "development".
Code as of writing in wrapWithDeps

if (__DEV__ || __FEATURE_PROD_INTLIFY_DEVTOOLS__) {
  try {
    setAdditionalMeta(getMetaInfo())
    if (!_isGlobal) {
      _context.fallbackContext = __root
        ? (getFallbackContext() as any)
        : undefined
    }
    ret = fn(_context)
  } finally {
    setAdditionalMeta(null)
    if (!_isGlobal) {
      _context.fallbackContext = undefined
    }
  }
} else {
  ret = fn(_context)
}

See: https://github.com/intlify/vue-i18n-next/blob/v9.3.0-beta.19/packages/vue-i18n-core/src/composer.ts#L2089

Expected behavior

Messages created at createI18n time should be available for use to all SFCs.

Common and shared messages should not need to be defined multiple times. Examples of those messages include:

  • name
  • description
  • submit
  • cancel

Reproduction

Step 1 - Code Changes

In vue-i18n-next's examples/web-components project make the following changes:

main.ts

Alter the createI18n argument to include the following messages:

messages: {
  en: {
    test: 'Test Message...'
  }
}

HelloBlock.ce.vue

Alter the <i18n> block to be the following:

<i18n>
{
  "en": {
    "world": "@:test The world!"
  },
  "ja": {
    "world": "ザ・ワールド"
  }
}
</i18n>

Step 2 - Expected behavior when NODE_ENV is "development"

  1. Ensure NODE_ENV environment variable is development.
  2. From examples/web-components run pnpm dev and navigate to the application
  3. Validate that "Test Message... The world!" is rendered (see screenshot)
image

Step 3 - Buggy behavior when NODE_ENV is "production"

  1. Ensure NODE_ENV environment variable is production.
  2. From examples/web-components run pnpm dev and navigate to the application
  3. Expect that "Test Message... The world!" is rendered, but it is just "The world!" (see screenshot)
image

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (8) x64 Intel(R) Xeon(R) E-2134 CPU @ 3.50GHz
    Memory: 11.41 GB / 31.88 GB
  Binaries:
    Node: 20.0.0 - ~\scoop\apps\nvm\current\nodejs\nodejs\node.EXE
    Yarn: 1.22.19 - ~\scoop\apps\nvm\current\nodejs\nodejs\yarn.CMD
    npm: 9.6.4 - ~\scoop\apps\nvm\current\nodejs\nodejs\npm.CMD
    pnpm: 8.6.5 - ~\scoop\shims\pnpm.EXE
  Browsers:
    Edge: Spartan (44.22621.1848.0), Chromium (114.0.1823.58)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @intlify/vite-plugin-vue-i18n: ^2.4.0 => 2.4.0 
    @vitejs/plugin-vue: ^4.2.0 => 4.2.3 
    @vue/compiler-sfc: ^3.3.4 => 3.3.4 
    vite: ^4.3.0 => 4.3.9 
    vue: ^3.3.4 => 3.3.4
    vue-i18n: workspace:* => 9.3.0-beta.19
    vue-tsc: ^1.6.5 => 1.6.5

Screenshot

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: ImprovementIncludes backwards-compatible fixes🍰 p2-nice-to-havePriority 2: nothing is broken but it's worth addressing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions