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

Replace amp_experimental_sandboxing_enabled filter with Sandboxing experiment toggle #6757

Merged
merged 6 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assets/src/settings-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { PluginsContextProvider } from '../components/plugins-context-provider';
import { ThemesContextProvider } from '../components/themes-context-provider';
import { SiteScanContextProvider } from '../components/site-scan-context-provider';
import { Welcome } from './welcome';
import { SandboxingLevel } from './sandboxing-level';
import { Sandboxing } from './sandboxing';
import { TemplateModes } from './template-modes';
import { SupportedTemplates } from './supported-templates';
import { SettingsFooter } from './settings-footer';
Expand Down Expand Up @@ -223,7 +223,6 @@ function Root( { appRoot } ) {
<h2 id="advanced-settings">
{ __( 'Advanced Settings', 'amp' ) }
</h2>
<SandboxingLevel focusedSection={ focusedSection } />
<AMPDrawer
heading={ (
<h3>
Expand Down Expand Up @@ -261,6 +260,7 @@ function Root( { appRoot } ) {
>
<Analytics />
</AMPDrawer>
<Sandboxing focusedSection={ focusedSection } />
<PairedUrlStructure focusedSection={ focusedSection } />
<AMPDrawer
className="amp-other-settings"
Expand Down
105 changes: 0 additions & 105 deletions assets/src/settings-page/sandboxing-level.js

This file was deleted.

120 changes: 120 additions & 0 deletions assets/src/settings-page/sandboxing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* External dependencies
*/
import PropTypes from 'prop-types';

/**
* WordPress dependencies
*/
import { useContext } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { CheckboxControl } from '@wordpress/components';

/**
* Internal dependencies
*/
import { Options } from '../components/options-context-provider';
import { AMPDrawer } from '../components/amp-drawer';
import { STANDARD } from '../common/constants';

/**
* Component rendering the Sandboxing experiment.
*
* @param {Object} props Component props.
* @param {string} props.focusedSection Focused section.
*/
export function Sandboxing( { focusedSection } ) {
const { updateOptions, editedOptions: {
sandboxing_enabled: sandboxingEnabled,
sandboxing_level: sandboxingLevel,
theme_support: themeSupport,
} } = useContext( Options );

if ( STANDARD !== themeSupport ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is an experimental feature, should it be available to technical users only?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good question. I think that it should be available to non-technical users too, as this feature is intended to be the most benefit to users who are not technical in the first place, since it avoids the need to fix validation errors.

return null;
}

return (
<AMPDrawer
heading={ (
<h3>
{ __( 'Sandboxing (Experimental)', 'amp' ) }
</h3>
) }
hiddenTitle={ __( 'Sandboxing (Experimental)', 'amp' ) }
id="sandboxing"
initialOpen={ 'sandboxing' === focusedSection }
>
<p>
{ __( 'Try out a more flexible AMP by generating pages that use AMP components without requiring AMP validity! By selecting a sandboxing level, you are indicating the minimum degree of sanitization. For example, if you selected the loose leve but have a page without any POST form and no custom scripts, it will still be served as valid AMP—the same as if you had selected the strict level.', 'amp' ) }
</p>

<CheckboxControl
className="sandboxing-enabled"
checked={ sandboxingEnabled }
label={ __( 'Enable sandboxing experiment', 'amp' ) }
onChange={
( newChecked ) => {
updateOptions( { sandboxing_enabled: newChecked } );
}
}
/>

{ sandboxingEnabled && (
<ol>
<li>
<input
type="radio"
id="sandboxing-level-1"
checked={ 1 === sandboxingLevel }
onChange={ () => {
updateOptions( { sandboxing_level: 1 } );
} }
/>
<label htmlFor="sandboxing-level-1">
<strong>
{ __( 'Loose:', 'amp' ) }
</strong>
{ ' ' + __( 'Do not remove any AMP-invalid markup by default, including custom scripts. CSS processing is disabled.', 'amp' ) }
</label>
</li>
<li>
<input
type="radio"
id="sandboxing-level-2"
checked={ 2 === sandboxingLevel }
onChange={ () => {
updateOptions( { sandboxing_level: 2 } );
} }
/>
<label htmlFor="sandboxing-level-2">
<strong>
{ __( 'Moderate:', 'amp' ) }
</strong>
{ ' ' + __( 'Remove anything invalid AMP except for POST forms, excessive CSS, and other PX-verified markup.', 'amp' ) }
</label>
</li>
<li>
<input
type="radio"
id="sandboxing-level-3"
checked={ 3 === sandboxingLevel }
onChange={ () => {
updateOptions( { sandboxing_level: 3 } );
} }
/>
<label htmlFor="sandboxing-level-3">
<strong>
{ __( 'Strict:', 'amp' ) }
</strong>
{ ' ' + __( 'Require valid AMP, removing all markup that causes validation errors (except for excessive CSS).', 'amp' ) }
</label>
</li>
</ol>
) }
</AMPDrawer>
);
}
Sandboxing.propTypes = {
focusedSection: PropTypes.string,
};
22 changes: 13 additions & 9 deletions assets/src/settings-page/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ li.error-kept {
}
}

#sandboxing-level .amp-drawer__panel-body-inner,
#sandboxing .amp-drawer__panel-body-inner,
#site-scan .amp-drawer__panel-body-inner,
#site-review .amp-drawer__panel-body-inner,
#plugin-suppression .amp-drawer__panel-body-inner,
Expand Down Expand Up @@ -660,30 +660,34 @@ li.error-kept {
font-size: 0.875rem;
}

/* Sandboxing Level */
#sandboxing-level .amp-drawer__panel-body-inner p {
/* Sandboxing */
#sandboxing .amp-drawer__panel-body-inner p {
font-size: 14px;
margin-top: 0;
}

#sandboxing-level .amp-drawer__panel-body-inner ol {
#sandboxing .sandboxing-enabled {
font-weight: bold;
}

#sandboxing .amp-drawer__panel-body-inner ol {
margin-top: 1.5rem;
margin-left: 0;
}

#sandboxing-level .amp-drawer__panel-body-inner li {
#sandboxing .amp-drawer__panel-body-inner li {
list-style-type: none;
}

#sandboxing-level .amp-drawer__panel-body-inner li:not(:last-child) {
#sandboxing .amp-drawer__panel-body-inner li:not(:last-child) {
margin-bottom: 12px;
}

#sandboxing-level .amp-drawer__panel-body-inner input[type="radio"] {
#sandboxing .amp-drawer__panel-body-inner input[type="radio"] {
margin-right: 12px;
}

#sandboxing-level .amp-drawer__panel-body-inner input[type="radio"],
#sandboxing-level .amp-drawer__panel-body-inner label {
#sandboxing .amp-drawer__panel-body-inner input[type="radio"],
#sandboxing .amp-drawer__panel-body-inner label {
vertical-align: middle;
}
9 changes: 1 addition & 8 deletions includes/validation/class-amp-validation-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use AmpProject\AmpWP\Icon;
use AmpProject\AmpWP\Option;
use AmpProject\AmpWP\QueryVar;
use AmpProject\AmpWP\Sandboxing;
use AmpProject\AmpWP\Services;
use AmpProject\Dom\Document;
use AmpProject\Exception\MaxCssByteCountExceeded;
Expand Down Expand Up @@ -331,13 +330,7 @@ public static function post_supports_validation( $post ) {
*/
public static function is_sanitization_auto_accepted( $error = null ) {

if (
$error
&&
amp_is_canonical()
&&
! Sandboxing::is_needed() // @todo Remove this once Sandboxing no longer experimental.
) {
if ( $error && amp_is_canonical() ) {
// Excessive CSS on AMP-first sites must not be removed by default since removing CSS can severely break a site.
$accepted = AMP_Style_Sanitizer::STYLESHEET_TOO_LONG !== $error['code'];
} else {
Expand Down
Loading