Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

add alert & don't put code into a string

Roman Pominov903855045a2d
diff --git a/packages/react-sdk/src/tree/session-storage-polyfill.tsx b/packages/react-sdk/src/tree/session-storage-polyfill.tsx
index da39d97d44..b3dbe08026 100644
--- a/packages/react-sdk/src/tree/session-storage-polyfill.tsx
+++ b/packages/react-sdk/src/tree/session-storage-polyfill.tsx
@@ -1,25 +1,31 @@
// This is a temporary work around for https://github.com/remix-run/remix/issues/3659
// The code is based on this discussion https://bugs.chromium.org/p/chromium/issues/detail?id=357625
-const polyfill = `(function () {
+const polyfill = function () {
try {
const key = "__session_storage_availability_test__";
- sessionStorage.setItem(key, "test");
- sessionStorage.removeItem(key);
- } catch (e) {
+ sessionStorage.setItem(key, "test"); // test
+ sessionStorage.removeItem(key); // cleanup
+ } catch (error) {
+ alert(
+ 'It looks like you have disabled cookies in your browser. Webstudio designer may not work properly.\n\nTo enable cookies, go to "Setting" > "Privacy and security" > "Cookies and other site data", and make sure neither "Block all cookies" nor "Block third-party cookies" are selected.\n\nRead more at https://support.google.com/chrome/answer/95647'
+ );
const data = new Map();
Object.defineProperty(window, "sessionStorage", {
value: {
- setItem: (key, val) => {
+ setItem: (key: string, val: unknown) => {
+ // eslint-disable-next-line no-console
console.warn(
- \`Session storage is unavailable due to Error "\${e.message}". A polyfill is used to set value of "\${key}". The value will be lost when the page is reloaded.\`
+ `Session storage is unavailable due to Error "${
+ (error as Error).message
+ }". A polyfill is used to set value of "${key}". The value will be lost when the page is reloaded.`
);
data.set(key, String(val));
},
- getItem: (key) => {
+ getItem: (key: string) => {
return data.get(key);
},
- removeItem: (key) => {
+ removeItem: (key: string) => {
data.delete(key);
},
clear: () => {
@@ -28,8 +34,8 @@ const polyfill = `(function () {
},
});
}
-})();`;
+}.toString();
export const SessionStoragePolyfill = () => (
- <script dangerouslySetInnerHTML={{ __html: polyfill }} />
+ <script dangerouslySetInnerHTML={{ __html: `(${polyfill})()` }} />
);