fix: Non-editable link clicks opening duplicate tabs#2667
fix: Non-editable link clicks opening duplicate tabs#2667matthewlipski merged 2 commits intofeat/inline-tiptap-linkfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The link refactor changed the HTML representation of <a> tags by adding
classname="bn-inline-content-section" data-inline-content-type="link"
attributes. This changed the request bodies sent to LLM providers in tests,
which broke the MD5 hash-based MSW snapshot filenames. Additionally, the
test runtime now captures actual request headers (authorization,
content-type, etc.) instead of empty arrays, further changing the hashes.
57 snapshot files were migrated (56 via script + 1 manual fix):
- Old-hash files deleted, new-hash files created with the same valid
200 response bodies transplanted from the originals.
## How MSW Snapshot Hashing Works
Each test records HTTP requests via msw-snapshot. The snapshot filename
includes an MD5 hash computed from:
[method, url.origin, url.pathname, sorted(searchParams), sorted(headers), body]
See createRequestHash() in each test file (e.g. htmlBlocks.test.ts:22).
The hash function is toHashString() from msw-snapshot, which does:
crypto.createHash('md5').update(JSON.stringify(array), 'binary').digest('hex')
## How to Migrate Snapshots When Schema Changes
When a code change alters the HTML/content sent to LLM providers, the
request body changes, which changes the hash, which means snapshot files
won't be found by filename.
### Step 1: Run the tests to create duplicate snapshots
cd packages/xl-ai && npm run test
Tests with hash mismatches will try to fetch from real servers (which
will fail without API keys), creating NEW snapshot files with correct
hashes but 401 error responses alongside the OLD files with valid 200
responses. The validateTestEnvironment test will report duplicates.
### Step 2: Identify duplicate pairs
For each test directory under __msw_snapshots__/{provider}/{model}/,
look for snapshot pairs with the same test name prefix but different
hashes. The OLD file (valid 200 response, older mtime) needs its
response transplanted into the NEW file (401 error, newer mtime).
### Step 3: Transplant responses
For each duplicate pair:
1. Read the response body from the OLD file (status 200)
2. Write that response into the NEW file (replacing the 401 error)
3. Delete the OLD file
This can be scripted in Python:
import json, os, glob
from collections import defaultdict
base = 'packages/xl-ai/src/api/formats/html-blocks/__snapshots__'
files = glob.glob(f'{base}/**/*.json', recursive=True)
# Group by test name prefix (everything before the hash)
groups = defaultdict(list)
for f in files:
name = os.path.basename(f)
# Pattern: testname_N_hash.json
prefix = '_'.join(name.rsplit('_', 1)[:-1])
groups[prefix].append(f)
for prefix, paths in groups.items():
if len(paths) == 2:
# Identify old (200) vs new (401) by checking response status
for p in paths:
data = json.load(open(p))
if data['response']['status'] == 200:
old_file, old_data = p, data
else:
new_file = p
# Transplant response
new_data = json.load(open(new_file))
new_data['response'] = old_data['response']
json.dump(new_data, open(new_file, 'w'), indent=2)
os.remove(old_file)
### Step 4: Handle edge cases
Some tests may fail with 'TypeError: unusable' at Request.clone in
msw-snapshot. This happens when a snapshot hash changed but the test
crashes before creating a new file (no duplicate pair to migrate).
To fix these:
1. Add debug logging in createSnapshotPath to print the computed hash
2. Run the failing test to get the new hash
3. Rename the old snapshot file to use the new hash
4. Remove the debug logging
### Step 5: Verify
cd packages/xl-ai && npm run test
All tests should pass and the duplicate validation test should be green.
nperez0111
left a comment
There was a problem hiding this comment.
Looks good, I added the commit to fix up the snapshots
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/mantine
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-ai
@blocknote/xl-docx-exporter
@blocknote/xl-email-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
commit: |
Summary
This PR fixes a bug causing the
Linkextension's click handler to also fire on links that were non-editable, causing duplicate tabs to open.Closes #1040
Rationale
This is a bug.
Changes
data-inline-content-typeattribute to inline/rich-text links to differentiate them from links that may be rendered by e.g. custom blocks.Linkextension ignore links without those.Impact
N/A
Testing
N/A, Needed?
Screenshots/Video
N/A
Checklist
Additional Notes
N/A