playroom 0.44.1 → 0.44.2-fix-code-loading-ff-20250813004811

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # playroom
2
2
 
3
+ ## 0.44.2-fix-code-loading-ff-20250813004811
4
+
5
+ ### Patch Changes
6
+
7
+ - [#442](https://github.com/seek-oss/playroom/pull/442) [`a8f17d8`](https://github.com/seek-oss/playroom/commit/a8f17d88a33ad4e439aa403be261743133e77b6f) Thanks [@michaeltaranto](https://github.com/michaeltaranto)! - Fix code loading on page load in Firefox
8
+
9
+ Resolves a timing issue where code would not be hydrated into the editor correctly on page load in Firefox.
10
+
3
11
  ## 0.44.1
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playroom",
3
- "version": "0.44.1",
3
+ "version": "0.44.2-fix-code-loading-ff-20250813004811",
4
4
  "description": "Design with code, powered by your own component library",
5
5
  "bin": {
6
6
  "playroom": "bin/cli.cjs"
@@ -73,7 +73,7 @@ export const CodeEditor = ({
73
73
  onChange,
74
74
  previewCode,
75
75
  }: Props) => {
76
- const mounted = useRef(false);
76
+ const previewSnippetsCode = useRef(false);
77
77
  const editorInstanceRef = useRef<Editor | null>(null);
78
78
  const insertionPointRef = useRef<ReturnType<Editor['addLineClass']> | null>(
79
79
  null
@@ -147,7 +147,10 @@ export const CodeEditor = ({
147
147
  if (editorInstanceRef.current) {
148
148
  if (previewCode) {
149
149
  editorInstanceRef.current.setValue(previewCode);
150
- } else {
150
+ previewSnippetsCode.current = true;
151
+ } else if (previewSnippetsCode.current) {
152
+ // If existing snippets preview, remove the preview code
153
+ // from the undo history.
151
154
  editorInstanceRef.current.getDoc().undo();
152
155
 
153
156
  // prevent redo after undo'ing preview code.
@@ -155,6 +158,8 @@ export const CodeEditor = ({
155
158
  editorInstanceRef.current
156
159
  .getDoc()
157
160
  .setHistory({ ...history, undone: [] });
161
+
162
+ previewSnippetsCode.current = false;
158
163
  }
159
164
  }
160
165
  }, [previewCode]);
@@ -162,10 +167,9 @@ export const CodeEditor = ({
162
167
  useEffect(() => {
163
168
  if (editorInstanceRef.current) {
164
169
  if (
165
- mounted.current &&
166
- (editorInstanceRef.current.hasFocus() ||
167
- code === editorInstanceRef.current.getValue() ||
168
- previewCode)
170
+ editorInstanceRef.current.hasFocus() ||
171
+ code === editorInstanceRef.current.getValue() ||
172
+ previewCode
169
173
  ) {
170
174
  return;
171
175
  }
@@ -211,18 +215,11 @@ export const CodeEditor = ({
211
215
  <ReactCodeMirror
212
216
  editorDidMount={(editorInstance) => {
213
217
  editorInstanceRef.current = editorInstance;
218
+ editorInstanceRef.current.setValue(code);
214
219
  validateCodeInEditor(editorInstance, code);
215
220
  if (!editorHidden) {
216
221
  setCursorPosition(cursorPosition);
217
222
  }
218
- /**
219
- * This workaround delays the setting of the mounted flag. It allows
220
- * the behaviours wired up via `useEffect` to complete without being
221
- * interrupted by change or focus events.
222
- */
223
- setTimeout(() => {
224
- mounted.current = true;
225
- }, 1);
226
223
  }}
227
224
  onChange={(editorInstance, data, newCode) => {
228
225
  if (editorInstance.hasFocus() && !previewCode) {