Skip to content

Commit

Permalink
feat: add a feature flag to turn on trusted types policy creation, an…
Browse files Browse the repository at this point in the history
…d default to false
  • Loading branch information
haoqunjiang authored and yyx990803 committed May 30, 2024
1 parent cc5cd3c commit e9f8419
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ declare var __FEATURE_OPTIONS_API__: boolean
declare var __FEATURE_PROD_DEVTOOLS__: boolean
declare var __FEATURE_SUSPENSE__: boolean
declare var __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__: boolean
declare var __FEATURE_PROD_TRUSTED_TYPES__: boolean

// for tests
declare namespace jest {
Expand Down
6 changes: 5 additions & 1 deletion packages/runtime-dom/src/nodeOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ type VueTrustedTypePolicy =
let policy: VueTrustedTypePolicy = undefined
function getPolicy(): VueTrustedTypePolicy {
const ttWindow = window as unknown as TrustedTypesWindow
if (ttWindow.trustedTypes && !policy) {
if (
(__DEV__ || __FEATURE_PROD_TRUSTED_TYPES__) &&
ttWindow.trustedTypes &&
!policy
) {
try {
policy = ttWindow.trustedTypes.createPolicy('vue', {
createHTML: val => val,
Expand Down
3 changes: 3 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ function createConfig(format, output, plugins = []) {
__FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__: isBundlerESMBuild
? `__VUE_PROD_HYDRATION_MISMATCH_DETAILS__`
: `false`,
__FEATURE_PROD_TRUSTED_TYPES__: isBundlerESMBuild
? `__VUE_PROD_TRUSTED_TYPES__`
: `false`,
}

if (!isBundlerESMBuild) {
Expand Down
1 change: 1 addition & 0 deletions scripts/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ for (const target of targets) {
__FEATURE_OPTIONS_API__: `true`,
__FEATURE_PROD_DEVTOOLS__: `false`,
__FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__: `false`,
__FEATURE_PROD_TRUSTED_TYPES__: `false`,
},
})
.then(ctx => ctx.watch())
Expand Down
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default defineConfig({
__FEATURE_SUSPENSE__: true,
__FEATURE_PROD_DEVTOOLS__: false,
__FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__: false,
__FEATURE_PROD_TRUSTED_TYPES__: false,
__COMPAT__: true,
},
resolve: {
Expand Down

0 comments on commit e9f8419

Please sign in to comment.