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

feat: add flag to disable synthetic shadow #4408

Merged
merged 1 commit into from
Jul 29, 2024

Conversation

nolanlawson
Copy link
Collaborator

Details

Today, you can simply not import @lwc/synthetic-shadow and you'll run in pure-native-shadow mode. However, if @lwc/synthetic-shadow is loaded, then there's no way to switch back to a pure-native-shadow mode.

In some environments though (notably core), it would be convenient to have a runtime flag that can toggle this behavior on-demand, regardless of whether @lwc/synthetic-shadow was previously loaded or not. This PR accomplishes that via a new lwcRuntimeFlags prop.

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.

@nolanlawson nolanlawson requested a review from a team as a code owner July 26, 2024 20:55
// Note that lwcRuntimeFlags must be referenced as a pure global, or else string replacement in ESBuild
// will not work. But we also have to check to make sure that lwcRuntimeFlags is defined, so this
// `Object.defineProperty` code is copied from @lwc/features itself.
banner += `
if (!globalThis.lwcRuntimeFlags) {
Object.defineProperty(globalThis, 'lwcRuntimeFlags', { value: Object.create(null) });
}
if (!lwcRuntimeFlags.ENABLE_FORCE_SHADOW_MIGRATE_MODE) {
if (!lwcRuntimeFlags.ENABLE_FORCE_SHADOW_MIGRATE_MODE && !lwcRuntimeFlags.DISABLE_SYNTHETIC_SHADOW) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not every environment has the runtime flag set before @lwc/synthetic-shadow executes, but enough do that it makes sense to just disable synthetic shadow entirely in those cases.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I completely missed this part in the initial pass. The logic we're adding to computeShadowMode is unnecessary for applications that set feature flags before bootstrap, correct?

Feature flags being available before LWC bootstraps was assumed in the initial feature flag design. We really shouldn't be having to consider other cases...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately there are still apps that don't set flags before LWC bootstraps. Ideally yes we would not need this code, but this is the next-best thing.

Copy link
Member

@ekashida ekashida left a comment

Choose a reason for hiding this comment

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

We basically support two flavors of native shadow--the first is via polyfill exclusion (not using @lwc/synthetic-shadow) and the second is via mixed mode. This change feels more in line with the latter as we're still operating in the context of synthetic shadow polyfills. Should it instead be called FORCE_MIXED_MODE or something similar?

@nolanlawson
Copy link
Collaborator Author

How about FORCE_NATIVE_SHADOW? MIXED_MODE is a bit ambiguous to me.

@ekashida
Copy link
Member

ekashida commented Jul 26, 2024

FORCE_SHADOW_SUPPORT_MODE_NATIVE? If not, I'm good with FORCE_NATIVE_SHADOW.

I completely missed the part where we actually prevent @lwc/synthetic-shadow from running. I'm good with DISABLE_SYNTHETIC_SHADOW.

@nolanlawson
Copy link
Collaborator Author

/nucleus test

Copy link
Contributor

Well that's strange! A workflow could not be found for this PR. Please try running the /nucleus start command to start the workflow.

@nolanlawson
Copy link
Collaborator Author

/nucleus start

@nolanlawson nolanlawson merged commit c6c6803 into master Jul 29, 2024
11 checks passed
@nolanlawson nolanlawson deleted the nolan/disable-synthetic branch July 29, 2024 21:29
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

Successfully merging this pull request may close these issues.

2 participants